Skip to content

Commit 583c585

Browse files
committed
httpcaddyfile: Set challenge ports when http_port or https_port are used
1 parent 4356635 commit 583c585

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

caddyconfig/httpcaddyfile/tlsapp.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
457457
globalACMEEAB := options["acme_eab"]
458458
globalPreferredChains := options["preferred_chains"]
459459
globalCertLifetime := options["cert_lifetime"]
460+
globalHTTPPort, globalHTTPSPort := options["http_port"], options["https_port"]
460461

461462
if globalEmail != nil && acmeIssuer.Email == "" {
462463
acmeIssuer.Email = globalEmail.(string)
@@ -480,7 +481,24 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
480481
if globalPreferredChains != nil && acmeIssuer.PreferredChains == nil {
481482
acmeIssuer.PreferredChains = globalPreferredChains.(*caddytls.ChainPreference)
482483
}
483-
484+
if globalHTTPPort != nil && (acmeIssuer.Challenges == nil || acmeIssuer.Challenges.HTTP == nil || acmeIssuer.Challenges.HTTP.AlternatePort == 0) {
485+
if acmeIssuer.Challenges == nil {
486+
acmeIssuer.Challenges = new(caddytls.ChallengesConfig)
487+
}
488+
if acmeIssuer.Challenges.HTTP == nil {
489+
acmeIssuer.Challenges.HTTP = new(caddytls.HTTPChallengeConfig)
490+
}
491+
acmeIssuer.Challenges.HTTP.AlternatePort = globalHTTPPort.(int)
492+
}
493+
if globalHTTPSPort != nil && (acmeIssuer.Challenges == nil || acmeIssuer.Challenges.TLSALPN == nil || acmeIssuer.Challenges.TLSALPN.AlternatePort == 0) {
494+
if acmeIssuer.Challenges == nil {
495+
acmeIssuer.Challenges = new(caddytls.ChallengesConfig)
496+
}
497+
if acmeIssuer.Challenges.TLSALPN == nil {
498+
acmeIssuer.Challenges.TLSALPN = new(caddytls.TLSALPNChallengeConfig)
499+
}
500+
acmeIssuer.Challenges.TLSALPN.AlternatePort = globalHTTPSPort.(int)
501+
}
484502
if globalCertLifetime != nil && acmeIssuer.CertificateLifetime == 0 {
485503
acmeIssuer.CertificateLifetime = globalCertLifetime.(caddy.Duration)
486504
}

caddytest/integration/caddyfile_adapt/global_options_acme.caddyfiletest

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@
6363
"issuers": [
6464
{
6565
"ca": "https://example.com",
66+
"challenges": {
67+
"http": {
68+
"alternate_port": 8080
69+
},
70+
"tls-alpn": {
71+
"alternate_port": 8443
72+
}
73+
},
6674
"email": "[email protected]",
6775
"external_account": {
6876
"key_id": "4K2scIVbBpNd-78scadB2g",

0 commit comments

Comments
 (0)