Skip to content

Commit 0badb07

Browse files
committed
httpcaddyfile: Fix generated config related to ACME global options
If global DNS provider is configured, it does not need to be repeated in the JSON. If acme_* options are used, base automation policies should populate their issuers accordingly. Global issuer settings like acme_* options don't need to specify subjects in the automation policy since they should apply as a global default.
1 parent e4447c4 commit 0badb07

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

caddyconfig/httpcaddyfile/tlsapp.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,10 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
571571
return fmt.Errorf("acme_dns specified without DNS provider config, but no provider specified with 'dns' global option")
572572
}
573573
}
574+
acmeIssuer.Challenges = &caddytls.ChallengesConfig{
575+
DNS: new(caddytls.DNSChallengeConfig),
576+
}
577+
} else if globalACMEDNS != nil {
574578
acmeIssuer.Challenges = &caddytls.ChallengesConfig{
575579
DNS: &caddytls.DNSChallengeConfig{
576580
ProviderRaw: caddyconfig.JSONModuleObject(globalACMEDNS, "name", globalACMEDNS.(caddy.Module).CaddyModule().ID.Name(), nil),
@@ -622,12 +626,18 @@ func newBaseAutomationPolicy(
622626
_, hasLocalCerts := options["local_certs"]
623627
keyType, hasKeyType := options["key_type"]
624628
ocspStapling, hasOCSPStapling := options["ocsp_stapling"]
625-
626629
hasGlobalAutomationOpts := hasIssuers || hasLocalCerts || hasKeyType || hasOCSPStapling
627630

631+
globalACMECA := options["acme_ca"]
632+
globalACMECARoot := options["acme_ca_root"]
633+
_, globalACMEDNS := options["acme_dns"] // can be set to nil (to use globally-defined "dns" value instead), but it is still set
634+
globalACMEEAB := options["acme_eab"]
635+
globalPreferredChains := options["preferred_chains"]
636+
hasGlobalACMEDefaults := globalACMECA != nil || globalACMECARoot != nil || globalACMEDNS || globalACMEEAB != nil || globalPreferredChains != nil
637+
628638
// if there are no global options related to automation policies
629639
// set, then we can just return right away
630-
if !hasGlobalAutomationOpts {
640+
if !hasGlobalAutomationOpts && !hasGlobalACMEDefaults {
631641
if always {
632642
return new(caddytls.AutomationPolicy), nil
633643
}
@@ -649,6 +659,14 @@ func newBaseAutomationPolicy(
649659
ap.Issuers = []certmagic.Issuer{new(caddytls.InternalIssuer)}
650660
}
651661

662+
if hasGlobalACMEDefaults {
663+
for i := range ap.Issuers {
664+
if err := fillInGlobalACMEDefaults(ap.Issuers[i], options); err != nil {
665+
return nil, fmt.Errorf("filling in global issuer defaults for issuer %d: %v", i, err)
666+
}
667+
}
668+
}
669+
652670
if hasOCSPStapling {
653671
ocspConfig := ocspStapling.(certmagic.OCSPConfig)
654672
ap.DisableOCSPStapling = ocspConfig.DisableStapling

caddytest/integration/caddyfile_adapt/acme_dns_naked_use_dns_defaults.caddyfiletest

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,10 @@ example.com {
3434
"automation": {
3535
"policies": [
3636
{
37-
"subjects": [
38-
"example.com"
39-
],
4037
"issuers": [
4138
{
4239
"challenges": {
43-
"dns": {
44-
"provider": {
45-
"name": "mock"
46-
}
47-
}
40+
"dns": {}
4841
},
4942
"module": "acme"
5043
}

caddytest/integration/caddyfile_adapt/global_options_preferred_chains.caddyfiletest

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ example.com
3131
"automation": {
3232
"policies": [
3333
{
34-
"subjects": [
35-
"example.com"
36-
],
3734
"issuers": [
3835
{
3936
"module": "acme",

0 commit comments

Comments
 (0)