Skip to content

Commit 4564261

Browse files
httpcaddyfile: Fix acme_dns regression (#7199)
1 parent 16fe83c commit 4564261

File tree

3 files changed

+93
-15
lines changed

3 files changed

+93
-15
lines changed

caddyconfig/httpcaddyfile/tlsapp.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -564,21 +564,22 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
564564
if globalACMECARoot != nil && !slices.Contains(acmeIssuer.TrustedRootsPEMFiles, globalACMECARoot.(string)) {
565565
acmeIssuer.TrustedRootsPEMFiles = append(acmeIssuer.TrustedRootsPEMFiles, globalACMECARoot.(string))
566566
}
567-
if globalACMEDNSok && (acmeIssuer.Challenges == nil || acmeIssuer.Challenges.DNS == nil) {
568-
if globalACMEDNS == nil {
569-
globalACMEDNS = options["dns"]
570-
if globalACMEDNS == nil {
571-
return fmt.Errorf("acme_dns specified without DNS provider config, but no provider specified with 'dns' global option")
572-
}
573-
}
574-
acmeIssuer.Challenges = &caddytls.ChallengesConfig{
575-
DNS: new(caddytls.DNSChallengeConfig),
576-
}
577-
} else if globalACMEDNS != nil {
578-
acmeIssuer.Challenges = &caddytls.ChallengesConfig{
579-
DNS: &caddytls.DNSChallengeConfig{
580-
ProviderRaw: caddyconfig.JSONModuleObject(globalACMEDNS, "name", globalACMEDNS.(caddy.Module).CaddyModule().ID.Name(), nil),
581-
},
567+
if globalACMEDNSok {
568+
globalDNS := options["dns"]
569+
if globalDNS != nil {
570+
// If global `dns` is set, do NOT set provider in issuer, just set empty dns config
571+
acmeIssuer.Challenges = &caddytls.ChallengesConfig{
572+
DNS: &caddytls.DNSChallengeConfig{},
573+
}
574+
} else if globalACMEDNS != nil {
575+
// Set a global DNS provider if `acme_dns` is set and `dns` is NOT set
576+
acmeIssuer.Challenges = &caddytls.ChallengesConfig{
577+
DNS: &caddytls.DNSChallengeConfig{
578+
ProviderRaw: caddyconfig.JSONModuleObject(globalACMEDNS, "name", globalACMEDNS.(caddy.Module).CaddyModule().ID.Name(), nil),
579+
},
580+
}
581+
} else {
582+
return fmt.Errorf("acme_dns specified without DNS provider config, but no provider specified with 'dns' global option")
582583
}
583584
}
584585
if globalACMEEAB != nil && acmeIssuer.ExternalAccount == nil {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
acme_dns mock foo
3+
}
4+
5+
example.com {
6+
respond "Hello World"
7+
}
8+
----------
9+
{
10+
"apps": {
11+
"http": {
12+
"servers": {
13+
"srv0": {
14+
"listen": [
15+
":443"
16+
],
17+
"routes": [
18+
{
19+
"match": [
20+
{
21+
"host": [
22+
"example.com"
23+
]
24+
}
25+
],
26+
"handle": [
27+
{
28+
"handler": "subroute",
29+
"routes": [
30+
{
31+
"handle": [
32+
{
33+
"body": "Hello World",
34+
"handler": "static_response"
35+
}
36+
]
37+
}
38+
]
39+
}
40+
],
41+
"terminal": true
42+
}
43+
]
44+
}
45+
}
46+
},
47+
"tls": {
48+
"automation": {
49+
"policies": [
50+
{
51+
"issuers": [
52+
{
53+
"challenges": {
54+
"dns": {
55+
"provider": {
56+
"name": "mock"
57+
}
58+
}
59+
},
60+
"module": "acme"
61+
}
62+
]
63+
}
64+
]
65+
}
66+
}
67+
}
68+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
acme_dns
3+
}
4+
5+
example.com {
6+
respond "Hello World"
7+
}
8+
----------
9+
acme_dns specified without DNS provider config, but no provider specified with 'dns' global option

0 commit comments

Comments
 (0)