Skip to content

Commit df99502

Browse files
authored
httpcaddyfile: Enable TLS for catch-all site if tls directive is specified (#5808)
1 parent e0aaefa commit df99502

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

caddyconfig/httpcaddyfile/httptype.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,20 @@ func (st *ServerType) serversFromPairings(
716716
}
717717
}
718718

719+
// If TLS is specified as directive, it will also result in 1 or more connection policy being created
720+
// Thus, catch-all address with non-standard port, e.g. :8443, can have TLS enabled without
721+
// specifying prefix "https://"
722+
// Second part of the condition is to allow creating TLS conn policy even though `auto_https` has been disabled
723+
// ensuring compatibility with behavior described in below link
724+
// https://caddy.community/t/making-sense-of-auto-https-and-why-disabling-it-still-serves-https-instead-of-http/9761
725+
createdTLSConnPolicies, ok := sblock.pile["tls.connection_policy"]
726+
hasTLSEnabled := (ok && len(createdTLSConnPolicies) > 0) ||
727+
(addr.Host != "" && srv.AutoHTTPS != nil && !sliceContains(srv.AutoHTTPS.Skip, addr.Host))
728+
719729
// we'll need to remember if the address qualifies for auto-HTTPS, so we
720730
// can add a TLS conn policy if necessary
721731
if addr.Scheme == "https" ||
722-
(addr.Scheme != "http" && addr.Host != "" && addr.Port != httpPort) {
732+
(addr.Scheme != "http" && addr.Port != httpPort && hasTLSEnabled) {
723733
addressQualifiesForTLS = true
724734
}
725735
// predict whether auto-HTTPS will add the conn policy for us; if so, we
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
:8443 {
2+
tls internal {
3+
on_demand
4+
}
5+
}
6+
----------
7+
{
8+
"apps": {
9+
"http": {
10+
"servers": {
11+
"srv0": {
12+
"listen": [
13+
":8443"
14+
],
15+
"tls_connection_policies": [
16+
{}
17+
]
18+
}
19+
}
20+
},
21+
"tls": {
22+
"automation": {
23+
"policies": [
24+
{
25+
"issuers": [
26+
{
27+
"module": "internal"
28+
}
29+
],
30+
"on_demand": true
31+
}
32+
]
33+
}
34+
}
35+
}
36+
}
37+

0 commit comments

Comments
 (0)