httpcaddyfile: keep a site block's TLS policy for ECH public names (#8156)
Some checks are pending
Tests / test (./cmd/caddy/caddy, ~1.26.0, macos-14, 0, 1.26, mac) (push) Waiting to run
Tests / test (./cmd/caddy/caddy, ~1.26.0, ubuntu-latest, 0, 1.26, linux) (push) Waiting to run
Tests / test (./cmd/caddy/caddy.exe, ~1.26.0, windows-latest, True, 1.26, windows) (push) Waiting to run
Tests / test (s390x on IBM Z) (push) Waiting to run
Tests / goreleaser-check (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, aix) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, darwin) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, dragonfly) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, freebsd) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, illumos) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, linux) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, netbsd) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, openbsd) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, solaris) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, windows) (push) Waiting to run
Lint / lint (push) Waiting to run
Lint / lint-1 (push) Waiting to run
Lint / lint-2 (push) Waiting to run
Lint / govulncheck (push) Waiting to run
Lint / dependency-review (push) Waiting to run
OpenSSF Scorecard supply-chain security / Scorecard analysis (push) Waiting to run

* httpcaddyfile: keep a site block's TLS policy for ECH public names

The global ech option added its own automation policy for every public
name, even when a site block already had a policy for that name. If the
site block set its own TLS options, adapting failed with "hostname
appears in more than one automation policy". If a hostless catch-all
with the same settings was also present, the site's policy was merged
away and the name got only the global settings.

Skip public names that already have a policy, as tls_automate_names
does, and only add the ECH policy when it still has subjects, since a
policy without subjects acts as a catch-all.

* httpcaddyfile: check ECH public names the way the TLS app matches them

The check for an existing site policy only matched a subject spelled
exactly like the ECH public name. A site policy for *.example.com, or
for example.com when the public name is written Example.COM, already
covers that name at runtime, but the global ECH policy was still added
and sorted ahead of it, so the site's issuer settings were overridden.

Lowercase and trim the public name as ECH provisioning does and compare
it with certmagic.MatchWildcard, which is how the TLS app picks a policy
for a name.
This commit is contained in:
awss 2026-10-09 07:48:00 +01:00 • committed by GitHub
parent 519be12306
commit c8591a1e46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 399 additions and 6 deletions

View file

@ -344,20 +344,27 @@ func (st ServerType) buildTLSApp(
tlsApp.EncryptedClientHello = ech
// outer server names will need certificates, so make sure they're included
// in an automation policy for them that applies any global options
// in an automation policy for them that applies any global options. A name
// that a site block's policy already covers keeps that policy, because a
// second policy for it would be rejected as ambiguous or picked ahead of
// the site's.
ap, err := newBaseAutomationPolicy(options, warnings, true)
if err != nil {
return nil, warnings, err
}
for _, cfg := range ech.Configs {
if cfg.PublicName != "" {
ap.SubjectsRaw = append(ap.SubjectsRaw, cfg.PublicName)
if cfg.PublicName == "" || automationPolicyCoversName(tlsApp.Automation, cfg.PublicName) {
continue
}
ap.SubjectsRaw = append(ap.SubjectsRaw, cfg.PublicName)
}
if tlsApp.Automation == nil {
tlsApp.Automation = new(caddytls.AutomationConfig)
// without subjects, the policy would apply to every name as a catch-all
if len(ap.SubjectsRaw) > 0 {
if tlsApp.Automation == nil {
tlsApp.Automation = new(caddytls.AutomationConfig)
}
tlsApp.Automation.Policies = append(tlsApp.Automation.Policies, ap)
}
tlsApp.Automation.Policies = append(tlsApp.Automation.Policies, ap)
}
// if the storage clean interval is a boolean, then it's "off" to disable cleaning
@ -955,6 +962,23 @@ func automationPolicyExistsForSubject(automation *caddytls.AutomationConfig, sub
})
}
// automationPolicyCoversName reports whether some automation policy with
// subjects would be selected for the ECH public name at runtime. The TLS app
// trims and lowercases public names, then picks a policy for each one with
// certmagic.MatchWildcard, so a wildcard or differently cased subject covers
// it too. A catch-all policy names no subjects and so never matches.
func automationPolicyCoversName(automation *caddytls.AutomationConfig, publicName string) bool {
if automation == nil {
return false
}
name := strings.ToLower(strings.TrimSpace(publicName))
return slices.ContainsFunc(automation.Policies, func(ap *caddytls.AutomationPolicy) bool {
return slices.ContainsFunc(ap.SubjectsRaw, func(subj string) bool {
return certmagic.MatchWildcard(name, subj)
})
})
}
// hasGlobalACMEDefaults reports whether any global option is set that an
// automation policy without issuers of its own would later be filled in with.
// A policy is worth creating for a subject when this is true, even if the

View file

@ -0,0 +1,56 @@
{
ech Example.COM
}
example.com {
tls internal
}
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":443"
],
"routes": [
{
"match": [
{
"host": [
"example.com"
]
}
],
"terminal": true
}
]
}
}
},
"tls": {
"automation": {
"policies": [
{
"subjects": [
"example.com"
],
"issuers": [
{
"module": "internal"
}
]
}
]
},
"encrypted_client_hello": {
"configs": [
{
"public_name": "Example.COM"
}
]
}
}
}
}

View file

@ -0,0 +1,76 @@
{
email nobody@example.com
ech example.com ech.example.net
}
example.com {
tls internal
}
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":443"
],
"routes": [
{
"match": [
{
"host": [
"example.com"
]
}
],
"terminal": true
}
]
}
}
},
"tls": {
"automation": {
"policies": [
{
"subjects": [
"example.com"
],
"issuers": [
{
"module": "internal"
}
]
},
{
"subjects": [
"ech.example.net"
],
"issuers": [
{
"email": "nobody@example.com",
"module": "acme"
},
{
"ca": "https://acme.zerossl.com/v2/DV90",
"email": "nobody@example.com",
"module": "acme"
}
]
}
]
},
"encrypted_client_hello": {
"configs": [
{
"public_name": "example.com"
},
{
"public_name": "ech.example.net"
}
]
}
}
}
}

View file

@ -0,0 +1,85 @@
{
acme_dns mock foo
ech example.com
}
example.com {
tls {
resolvers 1.1.1.1
}
}
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":443"
],
"routes": [
{
"match": [
{
"host": [
"example.com"
]
}
],
"terminal": true
}
]
}
}
},
"tls": {
"automation": {
"policies": [
{
"subjects": [
"example.com"
],
"issuers": [
{
"challenges": {
"dns": {
"provider": {
"argument": "foo",
"name": "mock"
},
"resolvers": [
"1.1.1.1"
]
}
},
"module": "acme"
}
]
},
{
"issuers": [
{
"challenges": {
"dns": {
"provider": {
"argument": "foo",
"name": "mock"
}
}
},
"module": "acme"
}
]
}
]
},
"encrypted_client_hello": {
"configs": [
{
"public_name": "example.com"
}
]
}
}
}
}

View file

@ -0,0 +1,76 @@
{
email nobody@example.com
ech ech.example.com ech.example.net
}
*.example.com {
tls internal
}
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":443"
],
"routes": [
{
"match": [
{
"host": [
"*.example.com"
]
}
],
"terminal": true
}
]
}
}
},
"tls": {
"automation": {
"policies": [
{
"subjects": [
"*.example.com"
],
"issuers": [
{
"module": "internal"
}
]
},
{
"subjects": [
"ech.example.net"
],
"issuers": [
{
"email": "nobody@example.com",
"module": "acme"
},
{
"ca": "https://acme.zerossl.com/v2/DV90",
"email": "nobody@example.com",
"module": "acme"
}
]
}
]
},
"encrypted_client_hello": {
"configs": [
{
"public_name": "ech.example.com"
},
{
"public_name": "ech.example.net"
}
]
}
}
}
}

View file

@ -0,0 +1,76 @@
{
ech example.com
}
example.com {
tls internal
}
:8443 {
tls internal
respond "catch-all"
}
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":443"
],
"routes": [
{
"match": [
{
"host": [
"example.com"
]
}
],
"terminal": true
}
]
},
"srv1": {
"listen": [
":8443"
],
"routes": [
{
"handle": [
{
"body": "catch-all",
"handler": "static_response"
}
]
}
],
"tls_connection_policies": [
{}
]
}
}
},
"tls": {
"automation": {
"policies": [
{
"issuers": [
{
"module": "internal"
}
]
}
]
},
"encrypted_client_hello": {
"configs": [
{
"public_name": "example.com"
}
]
}
}
}
}