Skip to content

Commit d9cc24f

Browse files
Siomachkinmholt
andauthored
caddypki: Disable internal auto-CA when auto_https is disabled (fix #7211) (#7238)
Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
1 parent 38848f7 commit d9cc24f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

caddyconfig/httpcaddyfile/pkiapp.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package httpcaddyfile
1616

1717
import (
18+
"slices"
19+
1820
"github.com/caddyserver/caddy/v2"
1921
"github.com/caddyserver/caddy/v2/caddyconfig"
2022
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
@@ -178,6 +180,15 @@ func (st ServerType) buildPKIApp(
178180
if _, ok := options["skip_install_trust"]; ok {
179181
skipInstallTrust = true
180182
}
183+
184+
// check if auto_https is off - in that case we should not create
185+
// any PKI infrastructure even with skip_install_trust directive
186+
autoHTTPS := []string{}
187+
if ah, ok := options["auto_https"].([]string); ok {
188+
autoHTTPS = ah
189+
}
190+
autoHTTPSOff := slices.Contains(autoHTTPS, "off")
191+
181192
falseBool := false
182193

183194
// Load the PKI app configured via global options
@@ -218,7 +229,8 @@ func (st ServerType) buildPKIApp(
218229
// if there was no CAs defined in any of the servers,
219230
// and we were requested to not install trust, then
220231
// add one for the default/local CA to do so
221-
if len(pkiApp.CAs) == 0 && skipInstallTrust {
232+
// only if auto_https is not completely disabled
233+
if len(pkiApp.CAs) == 0 && skipInstallTrust && !autoHTTPSOff {
222234
ca := new(caddypki.CA)
223235
ca.ID = caddypki.DefaultCAID
224236
ca.InstallTrust = &falseBool

modules/caddyhttp/autohttps.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,22 @@ func (app *App) automaticHTTPSPhase1(ctx caddy.Context, repl *caddy.Replacer) er
265265
}
266266
}
267267

268+
// if all servers have auto_https disabled and no domains need certs,
269+
// skip the rest of the TLS automation setup to avoid creating
270+
// unnecessary PKI infrastructure and automation policies
271+
allServersDisabled := true
272+
for _, srv := range app.Servers {
273+
if srv.AutoHTTPS == nil || !srv.AutoHTTPS.Disabled {
274+
allServersDisabled = false
275+
break
276+
}
277+
}
278+
279+
if allServersDisabled && len(uniqueDomainsForCerts) == 0 {
280+
logger.Debug("all servers have automatic HTTPS disabled and no domains need certificates, skipping TLS automation setup")
281+
return nil
282+
}
283+
268284
// we now have a list of all the unique names for which we need certs
269285
var internal, tailscale []string
270286
uniqueDomainsLoop:

0 commit comments

Comments
 (0)