Skip to content

Commit 27469f4

Browse files
authored
fix: use shared system trust store sds secret (#9357)
* use shared system trust store sds secret Signed-off-by: Guy Daich <guy.daich@sap.com>
1 parent da94ff5 commit 27469f4

82 files changed

Lines changed: 5160 additions & 71 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/v1alpha1/envoygateway_types.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ type GatewayAPISettings struct {
162162
// RuntimeFlag defines a runtime flag used to guard breaking changes or risky experimental features in new Envoy Gateway releases.
163163
// A runtime flag may be enabled or disabled by default and can be toggled through the EnvoyGateway resource.
164164
// +enum
165-
// +kubebuilder:validation:Enum=XDSNameSchemeV2;EndpointSliceIndex
165+
// +kubebuilder:validation:Enum=XDSNameSchemeV2;EndpointSliceIndex;PerResourceSystemCASecret
166166
type RuntimeFlag string
167167

168168
const (
@@ -175,6 +175,14 @@ const (
175175
// If the additional controller memory usage for the indexes becomes a concern,
176176
// consider disabling this flag.
177177
EndpointSliceIndex RuntimeFlag = "EndpointSliceIndex"
178+
179+
// PerResourceSystemCASecret restores the pre-1.x behavior of emitting one SDS secret per
180+
// BackendTLSPolicy or Backend resource that uses WellKnownCACertificates: System, instead
181+
// of sharing a single system_ca_certificates secret across all of them.
182+
// Disabled by default (i.e. the shared secret is used). Enable this flag to opt out during
183+
// upgrades — Envoy must warm the new system_ca_certificates secret before clusters can use
184+
// it, which may cause a brief disruption to new connections on first enable.
185+
PerResourceSystemCASecret RuntimeFlag = "PerResourceSystemCASecret" //nolint:gosec // not a credential
178186
)
179187

180188
// RuntimeFlags provide a mechanism to guard breaking changes or risky experimental features in new Envoy Gateway releases.

internal/gatewayapi/backendtlspolicy.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ func mergeServerValidationTLSConfigs(
192192

193193
if btpValidationTLSConfig.CACertificate != nil {
194194
mergedConfig.CACertificate = btpValidationTLSConfig.CACertificate
195+
// If the BTLSP provides an explicit CA certificate, it overrides the backend's
196+
// system trust store — clear UseSystemTrustStore so the IR is consistent.
197+
if !btpValidationTLSConfig.UseSystemTrustStore {
198+
mergedConfig.UseSystemTrustStore = false
199+
}
195200
}
196201
if btpValidationTLSConfig.SNI != nil { // BTP takes precedence for SNI, if set, it will override Backend resource SNI and disable AutoSNIFromEndpointHostname
197202
mergedConfig.SNI = btpValidationTLSConfig.SNI
@@ -276,8 +281,12 @@ func (t *Translator) processServerValidationTLSSettings(
276281
if !tlsConfig.InsecureSkipVerify {
277282
tlsConfig.UseSystemTrustStore = ptr.Deref(backend.Spec.TLS.WellKnownCACertificates, "") == gwapiv1.WellKnownCACertificatesSystem
278283
if tlsConfig.UseSystemTrustStore {
284+
name := fmt.Sprintf("%s/%s-ca", backend.Name, backend.Namespace)
285+
if !t.PerResourceSystemCASecret {
286+
name = ir.SystemTrustStoreSecretName
287+
}
279288
tlsConfig.CACertificate = &ir.TLSCACertificate{
280-
Name: fmt.Sprintf("%s/%s-ca", backend.Name, backend.Namespace),
289+
Name: name,
281290
}
282291
} else if len(backend.Spec.TLS.CACertificateRefs) > 0 {
283292
caRefs := getObjectReferences(gwapiv1.Namespace(backend.Namespace), backend.Spec.TLS.CACertificateRefs)
@@ -504,8 +513,12 @@ func (t *Translator) getBackendTLSBundle(backendTLSPolicy *gwapiv1.BackendTLSPol
504513
SubjectAltNames: subjectAltNames,
505514
}
506515
if tlsBundle.UseSystemTrustStore {
516+
name := fmt.Sprintf("%s/%s-ca", backendTLSPolicy.Name, backendTLSPolicy.Namespace)
517+
if !t.PerResourceSystemCASecret {
518+
name = ir.SystemTrustStoreSecretName
519+
}
507520
tlsBundle.CACertificate = &ir.TLSCACertificate{
508-
Name: fmt.Sprintf("%s/%s-ca", backendTLSPolicy.Name, backendTLSPolicy.Namespace),
521+
Name: name,
509522
}
510523
return tlsBundle, nil
511524
}

internal/gatewayapi/listener_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ func TestProcessBackendRefsBackendTLSPolicy(t *testing.T) {
14331433
backendMetadata := &ir.ResourceMetadata{Name: backendName, Namespace: ns}
14341434
backendPolicyTLS := &ir.TLSUpstreamConfig{
14351435
SNI: new("otel.example.com"), UseSystemTrustStore: true,
1436-
CACertificate: &ir.TLSCACertificate{Name: "otel-tls/test-ns-ca"}, SubjectAltNames: []ir.SubjectAltName{},
1436+
CACertificate: &ir.TLSCACertificate{Name: ir.SystemTrustStoreSecretName}, SubjectAltNames: []ir.SubjectAltName{},
14371437
TLSConfig: ir.TLSConfig{MinVersion: new(ir.TLSv12), MaxVersion: new(ir.TLSv13)},
14381438
}
14391439

@@ -1472,7 +1472,7 @@ func TestProcessBackendRefsBackendTLSPolicy(t *testing.T) {
14721472
serviceMetadata := &ir.ResourceMetadata{Name: serviceName, Namespace: ns, SectionName: "4317"}
14731473
servicePolicyTLS := &ir.TLSUpstreamConfig{
14741474
SNI: new("otel-svc.example.com"), UseSystemTrustStore: true,
1475-
CACertificate: &ir.TLSCACertificate{Name: "otel-svc-tls/test-ns-ca"}, SubjectAltNames: []ir.SubjectAltName{},
1475+
CACertificate: &ir.TLSCACertificate{Name: ir.SystemTrustStoreSecretName}, SubjectAltNames: []ir.SubjectAltName{},
14761476
TLSConfig: ir.TLSConfig{MinVersion: new(ir.TLSv12), MaxVersion: new(ir.TLSv13)},
14771477
}
14781478

internal/gatewayapi/runner/runner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ func (r *Runner) subscribeAndTranslate(sub <-chan watchable.Snapshot[string, *re
299299
ControllerNamespace: r.ControllerNamespace,
300300
GatewayNamespaceMode: r.EnvoyGateway.GatewayNamespaceMode(),
301301
MergeGateways: gatewayapi.IsMergeGatewaysEnabled(resources),
302+
PerResourceSystemCASecret: r.EnvoyGateway.RuntimeFlags.IsEnabled(egv1a1.PerResourceSystemCASecret),
302303
WasmCache: r.wasmCache,
303304
RunningOnHost: r.EnvoyGateway.Provider != nil && r.EnvoyGateway.Provider.IsRunningOnHost(),
304305
InfraRemotelyManaged: r.EnvoyGateway.Provider != nil && r.EnvoyGateway.Provider.IsInfraManagedRemotely(),
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Two scenarios tested together:
2+
# 1. Backend with wellKnownCACertificates: System overridden by a BackendTLSPolicy
3+
# with an explicit caCertificateRefs — BTLSP's CA cert must win, UseSystemTrustStore cleared.
4+
# 2. Backend with explicit caCertificateRefs overridden by a BackendTLSPolicy
5+
# with wellKnownCACertificates: System — system trust store must win.
6+
gateways:
7+
- apiVersion: gateway.networking.k8s.io/v1
8+
kind: Gateway
9+
metadata:
10+
name: gateway-btls
11+
namespace: envoy-gateway
12+
spec:
13+
gatewayClassName: envoy-gateway-class
14+
listeners:
15+
- name: http
16+
protocol: HTTP
17+
port: 80
18+
allowedRoutes:
19+
namespaces:
20+
from: All
21+
httpRoutes:
22+
- apiVersion: gateway.networking.k8s.io/v1
23+
kind: HTTPRoute
24+
metadata:
25+
name: httproute-btls
26+
namespace: envoy-gateway
27+
spec:
28+
parentRefs:
29+
- namespace: envoy-gateway
30+
name: gateway-btls
31+
sectionName: http
32+
rules:
33+
- matches:
34+
- path:
35+
type: Exact
36+
value: /exact
37+
backendRefs:
38+
- group: gateway.envoyproxy.io
39+
kind: Backend
40+
name: backend-system-ca
41+
namespace: envoy-gateway
42+
port: 8080
43+
- matches:
44+
- path:
45+
type: Exact
46+
value: /exact2
47+
backendRefs:
48+
- group: gateway.envoyproxy.io
49+
kind: Backend
50+
name: backend-inline-ca
51+
namespace: envoy-gateway
52+
port: 8080
53+
backends:
54+
- apiVersion: gateway.envoyproxy.io/v1alpha1
55+
kind: Backend
56+
metadata:
57+
name: backend-system-ca
58+
namespace: envoy-gateway
59+
spec:
60+
endpoints:
61+
- fqdn:
62+
hostname: example.com
63+
port: 8080
64+
tls:
65+
# Scenario 1: Backend uses system trust store, BTLSP overrides with inline CA.
66+
wellKnownCACertificates: System
67+
- apiVersion: gateway.envoyproxy.io/v1alpha1
68+
kind: Backend
69+
metadata:
70+
name: backend-inline-ca
71+
namespace: envoy-gateway
72+
spec:
73+
endpoints:
74+
- fqdn:
75+
hostname: example2.com
76+
port: 8080
77+
tls:
78+
# Scenario 2: Backend uses inline CA, BTLSP overrides with system trust store.
79+
caCertificateRefs:
80+
- name: ca-cmap
81+
group: ""
82+
kind: ConfigMap
83+
backendTLSPolicies:
84+
- apiVersion: gateway.networking.k8s.io/v1alpha2
85+
kind: BackendTLSPolicy
86+
metadata:
87+
name: policy-btls-inline-override
88+
namespace: envoy-gateway
89+
spec:
90+
targetRefs:
91+
- group: gateway.envoyproxy.io
92+
kind: Backend
93+
name: backend-system-ca
94+
validation:
95+
# Scenario 1: BTLSP overrides with explicit CA cert — must win over system trust store.
96+
caCertificateRefs:
97+
- name: ca-cmap
98+
group: ""
99+
kind: ConfigMap
100+
hostname: example.com
101+
- apiVersion: gateway.networking.k8s.io/v1alpha2
102+
kind: BackendTLSPolicy
103+
metadata:
104+
name: policy-btls-system-override
105+
namespace: envoy-gateway
106+
spec:
107+
targetRefs:
108+
- group: gateway.envoyproxy.io
109+
kind: Backend
110+
name: backend-inline-ca
111+
validation:
112+
# Scenario 2: BTLSP overrides with system trust store — must win over inline CA.
113+
wellKnownCACertificates: System
114+
hostname: example2.com
115+
configMaps:
116+
- apiVersion: v1
117+
kind: ConfigMap
118+
metadata:
119+
name: ca-cmap
120+
namespace: envoy-gateway
121+
data:
122+
ca.crt: |
123+
-----BEGIN CERTIFICATE-----
124+
MIIDJzCCAg+gAwIBAgIUAl6UKIuKmzte81cllz5PfdN2IlIwDQYJKoZIhvcNAQEL
125+
BQAwIzEQMA4GA1UEAwwHbXljaWVudDEPMA0GA1UECgwGa3ViZWRiMB4XDTIzMTAw
126+
MjA1NDE1N1oXDTI0MTAwMTA1NDE1N1owIzEQMA4GA1UEAwwHbXljaWVudDEPMA0G
127+
A1UECgwGa3ViZWRiMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwSTc
128+
1yj8HW62nynkFbXo4VXKv2jC0PM7dPVky87FweZcTKLoWQVPQE2p2kLDK6OEszmM
129+
yyr+xxWtyiveremrWqnKkNTYhLfYPhgQkczib7eUalmFjUbhWdLvHakbEgCodn3b
130+
kz57mInX2VpiDOKg4kyHfiuXWpiBqrCx0KNLpxo3DEQcFcsQTeTHzh4752GV04RU
131+
Ti/GEWyzIsl4Rg7tGtAwmcIPgUNUfY2Q390FGqdH4ahn+mw/6aFbW31W63d9YJVq
132+
ioyOVcaMIpM5B/c7Qc8SuhCI1YGhUyg4cRHLEw5VtikioyE3X04kna3jQAj54YbR
133+
bpEhc35apKLB21HOUQIDAQABo1MwUTAdBgNVHQ4EFgQUyvl0VI5vJVSuYFXu7B48
134+
6PbMEAowHwYDVR0jBBgwFoAUyvl0VI5vJVSuYFXu7B486PbMEAowDwYDVR0TAQH/
135+
BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAMLxrgFVMuNRq2wAwcBt7SnNR5Cfz
136+
2MvXq5EUmuawIUi9kaYjwdViDREGSjk7JW17vl576HjDkdfRwi4E28SydRInZf6J
137+
i8HZcZ7caH6DxR335fgHVzLi5NiTce/OjNBQzQ2MJXVDd8DBmG5fyatJiOJQ4bWE
138+
A7FlP0RdP3CO3GWE0M5iXOB2m1qWkE2eyO4UHvwTqNQLdrdAXgDQlbam9e4BG3Gg
139+
d/6thAkWDbt/QNT+EJHDCvhDRKh1RuGHyg+Y+/nebTWWrFWsktRrbOoHCZiCpXI1
140+
3eXE6nt0YkgtDxG22KqnhpAg9gUSs2hlhoxyvkzyF0mu6NhPlwAgnq7+/Q==
141+
-----END CERTIFICATE-----
142+

0 commit comments

Comments
 (0)