Skip to content

Commit c80b4cd

Browse files
committed
BUG/MEDIUM: Fix ACME dns-01 propagation checks
- check the right TXT record name - allow DNS record overwrites - add more debug messages
1 parent 8cb6cc6 commit c80b4cd

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

.aspell.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ allowed:
199199
- tls
200200
- tooltip
201201
- tsconfig
202+
- txt
202203
- typings
203204
- ubuntu
204205
- uniq

acme/dns01.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strings"
2424
"time"
2525

26+
"github.com/haproxytech/dataplaneapi/log"
2627
"github.com/libdns/libdns"
2728
"github.com/miekg/dns"
2829
)
@@ -36,7 +37,7 @@ const (
3637

3738
// DNSProvider defines the operations required for dns-01 challenges.
3839
type DNSProvider interface {
39-
libdns.RecordAppender
40+
libdns.RecordSetter
4041
libdns.RecordDeleter
4142
}
4243

@@ -82,7 +83,7 @@ func (s *DNS01Solver) Present(ctx context.Context, domain, zone, keyAuth string)
8283
zone = rooted(zone)
8384
}
8485

85-
results, err := s.provider.AppendRecords(ctx, zone, []libdns.Record{rec})
86+
results, err := s.provider.SetRecords(ctx, zone, []libdns.Record{rec})
8687
if err != nil {
8788
return fmt.Errorf("adding temporary record for zone %q: %w", zone, err)
8889
}
@@ -123,7 +124,10 @@ func (s *DNS01Solver) Wait(ctx context.Context, domain, zone, keyAuth string) er
123124
checkAuthoritativeServers := len(s.Resolvers) == 0
124125
resolvers := RecursiveNameservers(s.Resolvers)
125126

126-
absName := strings.Trim(domain, ".")
127+
log.Debugf("events: acme deploy: %s: using DNS resolvers %v, check authoritative servers=%v",
128+
domain, resolvers, checkAuthoritativeServers)
129+
130+
absName := "_acme-challenge." + strings.Trim(domain, ".")
127131

128132
var err error
129133
start := time.Now()

acme/propagation.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"strings"
2929
"time"
3030

31+
"github.com/haproxytech/dataplaneapi/log"
3132
"github.com/miekg/dns"
3233
)
3334

@@ -142,6 +143,8 @@ func checkDNSPropagation(ctx context.Context, fqdn string, recType uint16, expec
142143
}
143144
populateNameserverPorts(authoritativeServers)
144145
resolvers = authoritativeServers
146+
log.Debugf("events: acme deploy: %s: using DNS resolvers %v, check authoritative servers=%v",
147+
fqdn, resolvers, checkAuthoritativeServers)
145148
}
146149

147150
return checkAuthoritativeNss(ctx, fqdn, recType, expectedValue, resolvers)
@@ -172,6 +175,9 @@ func checkAuthoritativeNss(ctx context.Context, fqdn string, recType uint16, exp
172175
record := strings.Join(txt.Txt, "")
173176
if record == expectedValue {
174177
return true, nil
178+
} else {
179+
log.Debugf("events: acme deploy: %s: TXT record mismatch! Expected %q, Got %q",
180+
fqdn, expectedValue, record)
175181
}
176182
}
177183
case dns.TypeCNAME:
@@ -221,6 +227,7 @@ func updateDomainWithCName(r *dns.Msg, fqdn string) string {
221227
for _, rr := range r.Answer {
222228
if cn, ok := rr.(*dns.CNAME); ok {
223229
if cn.Hdr.Name == fqdn {
230+
log.Debugf("events: acme deploy: %s: updated FQDN with CNAME value: %q", fqdn, cn.Target)
224231
return cn.Target
225232
}
226233
}

client-native/events_acme.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@ func (h *HAProxyEventListener) handleAcmeDeployEvent(ctx context.Context, args s
250250
solver.PropagationDelay = getEnvDuration("DPAPI_ACME_PROPAGDELAY_SEC", 0)
251251
solver.PropagationTimeout = getEnvDuration("DPAPI_ACME_PROPAGTIMEOUT_SEC", time.Hour)
252252

253+
log.Debugf("events: acme deploy: %s: using DNS provider %s", domainName, provider)
254+
253255
var zone string
254-
if solver.PropagationTimeout != -1 {
256+
if solver.PropagationTimeout == -1 {
255257
zone = acme.GuessZone(domainName)
256258
} else {
257259
zone, err = acme.FindZoneByFQDN(ctx, domainName, acme.RecursiveNameservers(nil))
@@ -260,11 +262,18 @@ func (h *HAProxyEventListener) handleAcmeDeployEvent(ctx context.Context, args s
260262
log.Errorf("events: acme deploy: failed to find root zone for '%s': %s", domainName, err.Error())
261263
return
262264
}
265+
266+
log.Debugf("events: acme deploy: %s: found DNS zone: %q", domainName, zone)
267+
263268
err = solver.Present(ctx, domainName, zone, keyAuth)
264269
if err != nil {
265270
log.Errorf("events: acme deploy: DNS solver: %s", err.Error())
266271
return
267272
}
273+
274+
log.Debugf("events: acme deploy: %s: record created, waiting for propagation. Timeout: %s",
275+
domainName, solver.PropagationTimeout.String())
276+
268277
// Wait for DNS propagation and cleanup.
269278
err = solver.Wait(ctx, domainName, zone, keyAuth)
270279
// Remove the challenge in 10m if Wait() was successful. This should be

0 commit comments

Comments
 (0)