Skip to content

Commit 5b727bd

Browse files
committed
httpcaddyfile: Allow naked acme_dns if dns is set (fix #7091)
1 parent fe41ff3 commit 5b727bd

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

caddyconfig/httpcaddyfile/options.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,14 @@ func parseOptPreferredChains(d *caddyfile.Dispenser, _ any) (any, error) {
557557

558558
func parseOptDNS(d *caddyfile.Dispenser, _ any) (any, error) {
559559
d.Next() // consume option name
560+
optName := d.Val()
560561

561-
if !d.Next() { // get DNS module name
562+
// get DNS module name
563+
if !d.Next() {
564+
// this is allowed if this is the "acme_dns" option since it may refer to the globally-configured "dns" option's value
565+
if optName == "acme_dns" {
566+
return nil, nil
567+
}
562568
return nil, d.ArgErr()
563569
}
564570
modID := "dns.providers." + d.Val()

caddyconfig/httpcaddyfile/tlsapp.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,10 @@ func (st ServerType) buildTLSApp(
464464
globalEmail := options["email"]
465465
globalACMECA := options["acme_ca"]
466466
globalACMECARoot := options["acme_ca_root"]
467-
globalACMEDNS := options["acme_dns"]
467+
_, globalACMEDNS := options["acme_dns"] // can be set to nil (to use globally-defined "dns" value instead), but it is still set
468468
globalACMEEAB := options["acme_eab"]
469469
globalPreferredChains := options["preferred_chains"]
470-
hasGlobalACMEDefaults := globalEmail != nil || globalACMECA != nil || globalACMECARoot != nil || globalACMEDNS != nil || globalACMEEAB != nil || globalPreferredChains != nil
470+
hasGlobalACMEDefaults := globalEmail != nil || globalACMECA != nil || globalACMECARoot != nil || globalACMEDNS || globalACMEEAB != nil || globalPreferredChains != nil
471471
if hasGlobalACMEDefaults {
472472
for i := range tlsApp.Automation.Policies {
473473
ap := tlsApp.Automation.Policies[i]
@@ -549,7 +549,7 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
549549
globalEmail := options["email"]
550550
globalACMECA := options["acme_ca"]
551551
globalACMECARoot := options["acme_ca_root"]
552-
globalACMEDNS := options["acme_dns"]
552+
globalACMEDNS, globalACMEDNSok := options["acme_dns"] // can be set to nil (to use globally-defined "dns" value instead), but it is still set
553553
globalACMEEAB := options["acme_eab"]
554554
globalPreferredChains := options["preferred_chains"]
555555
globalCertLifetime := options["cert_lifetime"]
@@ -564,7 +564,13 @@ 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 globalACMEDNS != nil && (acmeIssuer.Challenges == nil || acmeIssuer.Challenges.DNS == nil) {
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+
}
568574
acmeIssuer.Challenges = &caddytls.ChallengesConfig{
569575
DNS: &caddytls.DNSChallengeConfig{
570576
ProviderRaw: caddyconfig.JSONModuleObject(globalACMEDNS, "name", globalACMEDNS.(caddy.Module).CaddyModule().ID.Name(), nil),

0 commit comments

Comments
 (0)