Skip to content

Commit 9305124

Browse files
committed
use shared system trust store sds secret
Signed-off-by: Guy Daich <guy.daich@sap.com>
1 parent 4eb8bb6 commit 9305124

40 files changed

Lines changed: 499 additions & 59 deletions

File tree

internal/gatewayapi/globalresources.go

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,22 @@ func (t *Translator) ProcessGlobalResources(resources *resource.Resources, xdsIR
4747
}
4848

4949
for _, xdsIR := range xdsIRs {
50-
if containsGlobalRateLimit(xdsIR.HTTP) || containsWasm(xdsIR.HTTP) {
50+
hasRateLimit, hasWasm, hasSystemTrustStore := scanXdsIR(xdsIR)
51+
if hasRateLimit || hasWasm || hasSystemTrustStore {
5152
if xdsIR.GlobalResources == nil {
5253
xdsIR.GlobalResources = &ir.GlobalResources{}
5354
}
55+
}
56+
if hasRateLimit || hasWasm {
5457
xdsIR.GlobalResources.EnvoyClientCertificate = &ir.TLSCertificate{
5558
Name: irGlobalConfigName(envoyTLSSecret),
5659
Certificate: envoyTLSSecret.Data[corev1.TLSCertKey],
5760
PrivateKey: envoyTLSSecret.Data[corev1.TLSPrivateKeyKey],
5861
}
5962
}
63+
if hasSystemTrustStore {
64+
xdsIR.GlobalResources.UseSystemTrustStore = true
65+
}
6066
}
6167

6268
return nil
@@ -101,27 +107,47 @@ func irGlobalConfigName(object metav1.Object) string {
101107
return fmt.Sprintf("%s/%s", object.GetNamespace(), object.GetName())
102108
}
103109

104-
func containsGlobalRateLimit(httpListeners []*ir.HTTPListener) bool {
105-
for _, httpListener := range httpListeners {
106-
for _, route := range httpListener.Routes {
107-
if route.Traffic != nil &&
110+
// scanXdsIR scans the xDS IR in a single pass and returns flags for features
111+
// that require global resources to be created.
112+
func scanXdsIR(xdsIR *ir.Xds) (hasGlobalRateLimit, hasWasm, hasSystemTrustStore bool) {
113+
for _, http := range xdsIR.HTTP {
114+
for _, route := range http.Routes {
115+
if !hasGlobalRateLimit && route.Traffic != nil &&
108116
route.Traffic.RateLimit != nil &&
109117
route.Traffic.RateLimit.Global != nil {
110-
return true
118+
hasGlobalRateLimit = true
119+
}
120+
if !hasWasm && route.EnvoyExtensions != nil &&
121+
len(route.EnvoyExtensions.Wasms) > 0 {
122+
hasWasm = true
123+
}
124+
if !hasSystemTrustStore && route.Destination != nil {
125+
for _, ds := range route.Destination.Settings {
126+
if ds.TLS != nil && ds.TLS.UseSystemTrustStore {
127+
hasSystemTrustStore = true
128+
break
129+
}
130+
}
131+
}
132+
if hasGlobalRateLimit && hasWasm && hasSystemTrustStore {
133+
return hasGlobalRateLimit, hasWasm, hasSystemTrustStore
111134
}
112135
}
113136
}
114-
return false
115-
}
116-
117-
func containsWasm(httpListeners []*ir.HTTPListener) bool {
118-
for _, httpListener := range httpListeners {
119-
for _, route := range httpListener.Routes {
120-
if route.EnvoyExtensions != nil &&
121-
len(route.EnvoyExtensions.Wasms) > 0 {
122-
return true
137+
if !hasSystemTrustStore {
138+
for _, tcp := range xdsIR.TCP {
139+
for _, route := range tcp.Routes {
140+
if route.Destination == nil {
141+
continue
142+
}
143+
for _, ds := range route.Destination.Settings {
144+
if ds.TLS != nil && ds.TLS.UseSystemTrustStore {
145+
hasSystemTrustStore = true
146+
return hasGlobalRateLimit, hasWasm, hasSystemTrustStore
147+
}
148+
}
123149
}
124150
}
125151
}
126-
return false
152+
return hasGlobalRateLimit, hasWasm, hasSystemTrustStore
127153
}

internal/gatewayapi/testdata/backend-tls-settings.out.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,7 @@ xdsIR:
10161016
sectionName: "8080"
10171017
name: envoy-gateway/gateway-1
10181018
protocol: TCP
1019+
useSystemTrustStore: true
10191020
http:
10201021
- address: 0.0.0.0
10211022
externalPort: 80
@@ -1397,6 +1398,7 @@ xdsIR:
13971398
sectionName: "8080"
13981399
name: envoy-gateway/gateway-2-with-backend-tls
13991400
protocol: TCP
1401+
useSystemTrustStore: true
14001402
http:
14011403
- address: 0.0.0.0
14021404
externalPort: 80
@@ -1485,6 +1487,7 @@ xdsIR:
14851487
sectionName: "8080"
14861488
name: envoy-gateway/gateway-3-without-backend-tls
14871489
protocol: TCP
1490+
useSystemTrustStore: true
14881491
http:
14891492
- address: 0.0.0.0
14901493
externalPort: 80

internal/gatewayapi/testdata/backendtlspolicy-serviceimport-target.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ xdsIR:
165165
sectionName: "8080"
166166
name: envoy-gateway/gateway-btls
167167
protocol: TCP
168+
useSystemTrustStore: true
168169
http:
169170
- address: 0.0.0.0
170171
externalPort: 80

internal/gatewayapi/testdata/backendtlspolicy-system-truststore.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ xdsIR:
154154
sectionName: "8080"
155155
name: envoy-gateway/gateway-btls
156156
protocol: TCP
157+
useSystemTrustStore: true
157158
http:
158159
- address: 0.0.0.0
159160
externalPort: 80

internal/gatewayapi/testdata/envoyproxy-tls-settings.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ xdsIR:
250250
sectionName: "8080"
251251
name: envoy-gateway/gateway-tls
252252
protocol: TCP
253+
useSystemTrustStore: true
253254
http:
254255
- address: 0.0.0.0
255256
externalPort: 443

internal/gatewayapi/testdata/gateway-tls-frontend-backend.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,7 @@ xdsIR:
18101810
sectionName: "8080"
18111811
name: envoy-gateway/invalid-gateway-backend-client-cert-no-fallback
18121812
protocol: TCP
1813+
useSystemTrustStore: true
18131814
http:
18141815
- address: 0.0.0.0
18151816
externalPort: 8080

internal/gatewayapi/testdata/httproute-dynamic-resolver-host-rewriting.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ xdsIR:
297297
sectionName: "8080"
298298
name: envoy-gateway/gateway-1
299299
protocol: TCP
300+
useSystemTrustStore: true
300301
http:
301302
- address: 0.0.0.0
302303
externalPort: 80

internal/gatewayapi/testdata/httproute-dynamic-resolver.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ xdsIR:
192192
sectionName: "8080"
193193
name: envoy-gateway/gateway-1
194194
protocol: TCP
195+
useSystemTrustStore: true
195196
http:
196197
- address: 0.0.0.0
197198
externalPort: 80

internal/gatewayapi/testdata/httproute-rule-with-non-service-backends-and-websocket-app-protocols.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ xdsIR:
247247
sectionName: "8080"
248248
name: envoy-gateway/gateway-1
249249
protocol: TCP
250+
useSystemTrustStore: true
250251
http:
251252
- address: 0.0.0.0
252253
externalPort: 80

internal/gatewayapi/testdata/httproute-with-tls-and-http.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ xdsIR:
179179
sectionName: "8080"
180180
name: envoy-gateway/gateway-1
181181
protocol: TCP
182+
useSystemTrustStore: true
182183
http:
183184
- address: 0.0.0.0
184185
externalPort: 80

0 commit comments

Comments
 (0)