Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
httpcaddyfile: Fix unexpectedly removed policy (#4128)
* httpcaddyfile: Fix unexpectedly removed policy When user set on_demand tls option in a catch-all (:443) policy, we expect other policies to not have the on_demand enabled See ex in tls_automation_policies_5.txt Btw, we can remove policies if they are **all** empty. * Update caddyconfig/httpcaddyfile/tlsapp.go Co-authored-by: Matt Holt <mholt@users.noreply.github.com> Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
Alban Lecocq committed
Apr 29, 2021 at 18:56 UTC
ff6ca577ec7196e2cf3991c817d3655754de4b24
2 files changed
+69
-3
caddyconfig/httpcaddyfile/tlsapp.go
+7
-3
@@ -480,15 +480,19 @@ func consolidateAutomationPolicies(aps []*caddytls.AutomationPolicy) []*caddytls
480
return len(aps[i].Subjects) > len(aps[j].Subjects)
481
})
482
483
- // remove any empty policies (except subjects, of course)
483
+ emptyAPCount := 0
484
+ // compute the number of empty policies (disregarding subjects) - see #4128
485
emptyAP := new(caddytls.AutomationPolicy)
486
for i := 0; i < len(aps); i++ {
487
emptyAP.Subjects = aps[i].Subjects
488
if reflect.DeepEqual(aps[i], emptyAP) {
488
- aps = append(aps[:i], aps[i+1:]...)
489
- i--
489
+ emptyAPCount++
490
}
491
}
492
+ // If all policies are empty, we can return nil, as there is no need to set any policy
493
+ if emptyAPCount == len(aps) {
494
+ return nil
495
+ }
496
497
// remove or combine duplicate policies
498
outer:
caddytest/integration/caddyfile_adapt/tls_automation_policies_5.txt
new
+62
@@ -0,0 +1,62 @@
1
+a.example.com {
2
+}
3
+
4
+b.example.com {
5
+}
6
+
7
+:443 {
8
+ tls {
9
+ on_demand
10
+ }
11
+}
12
+----------
13
+{
14
+ "apps": {
15
+ "http": {
16
+ "servers": {
17
+ "srv0": {
18
+ "listen": [
19
+ ":443"
20
+ ],
21
+ "routes": [
22
+ {
23
+ "match": [
24
+ {
25
+ "host": [
26
+ "a.example.com"
27
+ ]
28
+ }
29
+ ],
30
+ "terminal": true
31
+ },
32
+ {
33
+ "match": [
34
+ {
35
+ "host": [
36
+ "b.example.com"
37
+ ]
38
+ }
39
+ ],
40
+ "terminal": true
41
+ }
42
+ ]
43
+ }
44
+ }
45
+ },
46
+ "tls": {
47
+ "automation": {
48
+ "policies": [
49
+ {
50
+ "subjects": [
51
+ "a.example.com",
52
+ "b.example.com"
53
+ ]
54
+ },
55
+ {
56
+ "on_demand": true
57
+ }
58
+ ]
59
+ }
60
+ }
61
+ }
62
+}
\ No newline at end of file