From 86308c9780e4284f512130f277371347b94d9e81 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 26 Jan 2023 19:14:08 +0100 Subject: [PATCH] Fix ACME DNS challenge for top-level domains in a zone e.g. "*.emersion.fr" when the zone is "emersion.fr". Fixes: 662136ea745b ("Add support for ACME DNS hooks") --- dns.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/dns.go b/dns.go index 077f7c7..b1156e8 100644 --- a/dns.go +++ b/dns.go @@ -62,10 +62,20 @@ func (provider *commandDNSProvider) DeleteRecords(ctx context.Context, zone stri } func domainFromACMEChallengeRecord(zone string, rec *libdns.Record) (string, error) { - if rec.Type != "TXT" || !strings.HasPrefix(rec.Name, "_acme-challenge.") { + relZone := strings.TrimSuffix(zone, ".") + + var domain string + if rec.Name == "_acme-challenge" { + // Root domain + domain = relZone + } else if strings.HasPrefix(rec.Name, "_acme-challenge.") { + // Subdomain + relName := strings.TrimPrefix(rec.Name, "_acme-challenge.") + domain = relName + "." + relZone + } + if rec.Type != "TXT" || domain == "" { return "", fmt.Errorf("DNS record doesn't look like an ACME challenge: %v %v", rec.Type, rec.Name) } - relName := strings.TrimPrefix(rec.Name, "_acme-challenge.") - relZone := strings.TrimSuffix(zone, ".") - return relName + "." + relZone, nil + + return domain, nil }