Skip to content

Commit

Permalink
selectelv2: fix non-ASCII domain (#2322)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernandez Ludovic <[email protected]>
  • Loading branch information
Archirk and ldez authored Nov 6, 2024
1 parent b41079b commit 40bf2b0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
8 changes: 4 additions & 4 deletions docs/content/dns/zz_gen_selectelv2.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ Configuration for [Selectel v2](https://selectel.ru).
Here is an example bash command using the Selectel v2 provider:

```bash
SELECTEL_USERNAME=trex \
SELECTEL_PASSWORD=xxxxx \
SELECTEL_ACCOUNT_ID=1234567 \
SELECTEL_PROJECT_ID=111a11111aaa11aa1a11aaa11111aa1a \
SELECTELV2_USERNAME=trex \
SELECTELV2_PASSWORD=xxxxx \
SELECTELV2_ACCOUNT_ID=1234567 \
SELECTELV2_PROJECT_ID=111a11111aaa11aa1a11aaa11111aa1a \
lego --email [email protected] --dns selectelv2 --domains my.example.org run
```

Expand Down
21 changes: 16 additions & 5 deletions providers/dns/selectelv2/selectelv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/go-acme/lego/v4/providers/dns/internal/useragent"
selectelapi "github.com/selectel/domains-go/pkg/v2"
"github.com/selectel/go-selvpcclient/v3/selvpcclient"
"golang.org/x/net/idna"
)

const tokenHeader = "X-Auth-Token"
Expand Down Expand Up @@ -252,21 +253,26 @@ type clientWrapper struct {
}

func (w *clientWrapper) getZone(ctx context.Context, name string) (*selectelapi.Zone, error) {
params := &map[string]string{"filter": name}
unicodeName, err := idna.ToUnicode(name)
if err != nil {
return nil, fmt.Errorf("to unicode: %w", err)
}

params := &map[string]string{"filter": unicodeName}

zones, err := w.ListZones(ctx, params)
if err != nil {
return nil, fmt.Errorf("list zone: %w", err)
}

for _, zone := range zones.GetItems() {
if zone.Name == dns01.ToFqdn(name) {
if zone.Name == dns01.ToFqdn(unicodeName) {
return zone, nil
}
}

if len(strings.Split(dns01.UnFqdn(name), ".")) == 1 {
return nil, errors.New("zone for challenge has not been found")
return nil, fmt.Errorf("zone '%s' for challenge has not been found", name)
}

// -1 can not be returned since if no dots present we exit above
Expand All @@ -276,15 +282,20 @@ func (w *clientWrapper) getZone(ctx context.Context, name string) (*selectelapi.
}

func (w *clientWrapper) getRRset(ctx context.Context, name, zoneID string) (*selectelapi.RRSet, error) {
params := &map[string]string{"name": name, "rrset_types": string(selectelapi.TXT)}
unicodeName, err := idna.ToUnicode(name)
if err != nil {
return nil, fmt.Errorf("to unicode: %w", err)
}

params := &map[string]string{"name": unicodeName, "rrset_types": string(selectelapi.TXT)}

resp, err := w.ListRRSets(ctx, zoneID, params)
if err != nil {
return nil, fmt.Errorf("list rrset: %w", err)
}

for _, rrset := range resp.GetItems() {
if rrset.Name == dns01.ToFqdn(name) {
if rrset.Name == dns01.ToFqdn(unicodeName) {
return rrset, nil
}
}
Expand Down
8 changes: 4 additions & 4 deletions providers/dns/selectelv2/selectelv2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Code = "selectelv2"
Since = "v4.17.0"

Example = '''
SELECTEL_USERNAME=trex \
SELECTEL_PASSWORD=xxxxx \
SELECTEL_ACCOUNT_ID=1234567 \
SELECTEL_PROJECT_ID=111a11111aaa11aa1a11aaa11111aa1a \
SELECTELV2_USERNAME=trex \
SELECTELV2_PASSWORD=xxxxx \
SELECTELV2_ACCOUNT_ID=1234567 \
SELECTELV2_PROJECT_ID=111a11111aaa11aa1a11aaa11111aa1a \
lego --email [email protected] --dns selectelv2 --domains my.example.org run
'''

Expand Down

0 comments on commit 40bf2b0

Please sign in to comment.