Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selectelv2: fix non-ASCII domain #2322

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 you@example.com --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 you@example.com --dns selectelv2 --domains my.example.org run
'''

Expand Down