Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 23:30 UTC
httpcaddyfile: Allow naked acme_dns if dns is set (fix #7091)
Matthew Holt committed
Jul 29, 2025 at 11:55 UTC
5b727bde2992e7cb9987208453db42ae6e1c6e1e
2 files changed
+17
-5
caddyconfig/httpcaddyfile/options.go
+7
-1
@@ -557,8 +557,14 @@ func parseOptPreferredChains(d *caddyfile.Dispenser, _ any) (any, error) {
557
558
func parseOptDNS(d *caddyfile.Dispenser, _ any) (any, error) {
559
d.Next() // consume option name
560
+ optName := d.Val()
561
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
+ }
568
return nil, d.ArgErr()
569
}
570
modID := "dns.providers." + d.Val()
caddyconfig/httpcaddyfile/tlsapp.go
+10
-4
@@ -464,10 +464,10 @@ func (st ServerType) buildTLSApp(
464
globalEmail := options["email"]
465
globalACMECA := options["acme_ca"]
466
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
468
globalACMEEAB := options["acme_eab"]
469
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
471
if hasGlobalACMEDefaults {
472
for i := range tlsApp.Automation.Policies {
473
ap := tlsApp.Automation.Policies[i]
@@ -549,7 +549,7 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
549
globalEmail := options["email"]
550
globalACMECA := options["acme_ca"]
551
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
553
globalACMEEAB := options["acme_eab"]
554
globalPreferredChains := options["preferred_chains"]
555
globalCertLifetime := options["cert_lifetime"]
@@ -564,7 +564,13 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
564
if globalACMECARoot != nil && !slices.Contains(acmeIssuer.TrustedRootsPEMFiles, globalACMECARoot.(string)) {
565
acmeIssuer.TrustedRootsPEMFiles = append(acmeIssuer.TrustedRootsPEMFiles, globalACMECARoot.(string))
566
}
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
+ }
574
acmeIssuer.Challenges = &caddytls.ChallengesConfig{
575
DNS: &caddytls.DNSChallengeConfig{
576
ProviderRaw: caddyconfig.JSONModuleObject(globalACMEDNS, "name", globalACMEDNS.(caddy.Module).CaddyModule().ID.Name(), nil),