Skip to content

Commit

Permalink
Skip comparing wildcards against eachother when consolidating APs
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Oct 17, 2024
1 parent 2864a6f commit 8ecfe37
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
6 changes: 6 additions & 0 deletions caddyconfig/httpcaddyfile/tlsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,15 @@ outer:
iSubjs := aps[i].SubjectsRaw
for iSubj := 0; iSubj < len(iSubjs); iSubj++ {
for jSubj := range aps[j].SubjectsRaw {
// if j is not a wildcard, don't test against it
if !strings.HasPrefix(aps[j].SubjectsRaw[jSubj], "*.") {
continue
}
// if i is a wildcard, don't remove it
if strings.HasPrefix(aps[i].SubjectsRaw[iSubj], "*.") {
continue
}
// if i is covered by j (a wildcard), remove it
if certmagic.MatchWildcard(aps[i].SubjectsRaw[iSubj], aps[j].SubjectsRaw[jSubj]) {
iSubjs = slices.Delete(iSubjs, iSubj, iSubj+1)
iSubj--
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
auto_https prefer_wildcard
}

*.one.example.com {
tls {
dns mock
}
respond "one fallback"
}

*.two.example.com {
tls {
dns mock
}
respond "two fallback"
}

foo.one.example.com {
respond "foo"
}
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":443"
],
"routes": [
{
"match": [
{
"host": [
"foo.one.example.com"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"body": "foo",
"handler": "static_response"
}
]
}
]
}
],
"terminal": true
},
{
"match": [
{
"host": [
"*.one.example.com"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"body": "one fallback",
"handler": "static_response"
}
]
}
]
}
],
"terminal": true
},
{
"match": [
{
"host": [
"*.two.example.com"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"body": "two fallback",
"handler": "static_response"
}
]
}
]
}
],
"terminal": true
}
],
"automatic_https": {
"skip": [
"foo.one.example.com"
],
"prefer_wildcard": true
}
}
}
},
"tls": {
"automation": {
"policies": [
{
"subjects": [
"*.one.example.com",
"*.two.example.com"
],
"issuers": [
{
"challenges": {
"dns": {
"provider": {
"name": "mock"
}
}
},
"module": "acme"
}
]
}
]
}
}
}
}

0 comments on commit 8ecfe37

Please sign in to comment.