Skip to content

Commit f610278

Browse files
authored
Merge pull request #2721 from robscott/self-service-tls
Loosening TLS validation to enable indirect TLS config
2 parents e862ebe + 097d08a commit f610278

File tree

6 files changed

+236
-77
lines changed

6 files changed

+236
-77
lines changed

apis/v1/gateway_types.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ type GatewaySpec struct {
186186
// +listMapKey=name
187187
// +kubebuilder:validation:MinItems=1
188188
// +kubebuilder:validation:MaxItems=64
189-
// +kubebuilder:validation:XValidation:message="tls must be specified for protocols ['HTTPS', 'TLS']",rule="self.all(l, l.protocol in ['HTTPS', 'TLS'] ? has(l.tls) : true)"
190189
// +kubebuilder:validation:XValidation:message="tls must not be specified for protocols ['HTTP', 'TCP', 'UDP']",rule="self.all(l, l.protocol in ['HTTP', 'TCP', 'UDP'] ? !has(l.tls) : true)"
191190
// +kubebuilder:validation:XValidation:message="tls mode must be Terminate for protocol HTTPS",rule="self.all(l, (l.protocol == 'HTTPS' && has(l.tls)) ? (l.tls.mode == '' || l.tls.mode == 'Terminate') : true)"
192191
// +kubebuilder:validation:XValidation:message="hostname must not be specified for protocols ['TCP', 'UDP']",rule="self.all(l, l.protocol in ['TCP', 'UDP'] ? (!has(l.hostname) || l.hostname == '') : true)"
@@ -376,18 +375,19 @@ const (
376375

377376
// GatewayTLSConfig describes a TLS configuration.
378377
//
379-
// +kubebuilder:validation:XValidation:message="certificateRefs must be specified when TLSModeType is Terminate",rule="self.mode == 'Terminate' ? size(self.certificateRefs) > 0 : true"
378+
// +kubebuilder:validation:XValidation:message="certificateRefs or options must be specified when mode is Terminate",rule="self.mode == 'Terminate' ? size(self.certificateRefs) > 0 || size(self.options) > 0 : true"
380379
type GatewayTLSConfig struct {
381380
// Mode defines the TLS behavior for the TLS session initiated by the client.
382381
// There are two possible modes:
383382
//
384-
// - Terminate: The TLS session between the downstream client
385-
// and the Gateway is terminated at the Gateway. This mode requires
386-
// certificateRefs to be set and contain at least one element.
383+
// - Terminate: The TLS session between the downstream client and the
384+
// Gateway is terminated at the Gateway. This mode requires certificates
385+
// to be specified in some way, such as populating the certificateRefs
386+
// field.
387387
// - Passthrough: The TLS session is NOT terminated by the Gateway. This
388388
// implies that the Gateway can't decipher the TLS stream except for
389-
// the ClientHello message of the TLS protocol.
390-
// CertificateRefs field is ignored in this mode.
389+
// the ClientHello message of the TLS protocol. The certificateRefs field
390+
// is ignored in this mode.
391391
//
392392
// Support: Core
393393
//
@@ -701,8 +701,10 @@ const (
701701
// true.
702702
GatewayReasonProgrammed GatewayConditionReason = "Programmed"
703703

704-
// This reason is used with the "Programmed" and "Accepted" conditions when the Gateway is
705-
// syntactically or semantically invalid.
704+
// This reason is used with the "Programmed" and "Accepted" conditions when
705+
// the Gateway is syntactically or semantically invalid. For example, this
706+
// could include unspecified TLS configuration, or some unrecognized or
707+
// invalid values in the TLS configuration.
706708
GatewayReasonInvalid GatewayConditionReason = "Invalid"
707709

708710
// This reason is used with the "Programmed" condition when the

config/crd/experimental/gateway.networking.k8s.io_gateways.yaml

Lines changed: 18 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/standard/gateway.networking.k8s.io_gateways.yaml

Lines changed: 18 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/test/cel/gateway_test.go

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ func TestValidateGateway(t *testing.T) {
125125
},
126126
}
127127
},
128-
wantErrors: []string{"tls must be specified for protocols ['HTTPS', 'TLS']"},
129128
},
130129
{
131130
desc: "tls config not set with tls protocol",
@@ -138,7 +137,6 @@ func TestValidateGateway(t *testing.T) {
138137
},
139138
}
140139
},
141-
wantErrors: []string{"tls must be specified for protocols ['HTTPS', 'TLS']"},
142140
},
143141
{
144142
desc: "tls config not set with http protocol",
@@ -207,7 +205,7 @@ func TestValidateGateway(t *testing.T) {
207205
wantErrors: []string{"hostname must not be specified for protocols ['TCP', 'UDP']"},
208206
},
209207
{
210-
desc: "certificateRefs not set with https protocol and TLS terminate mode",
208+
desc: "certificateRefs not set with HTTPS protocol and TLS terminate mode",
211209
mutate: func(gw *gatewayv1.Gateway) {
212210
tlsMode := gatewayv1.TLSModeType("Terminate")
213211
gw.Spec.Listeners = []gatewayv1.Listener{
@@ -221,10 +219,10 @@ func TestValidateGateway(t *testing.T) {
221219
},
222220
}
223221
},
224-
wantErrors: []string{"certificateRefs must be specified when TLSModeType is Terminate"},
222+
wantErrors: []string{"certificateRefs or options must be specified when mode is Terminate"},
225223
},
226224
{
227-
desc: "certificateRefs not set with tls protocol and TLS terminate mode",
225+
desc: "certificateRefs not set with TLS protocol and TLS terminate mode",
228226
mutate: func(gw *gatewayv1.Gateway) {
229227
tlsMode := gatewayv1.TLSModeType("Terminate")
230228
gw.Spec.Listeners = []gatewayv1.Listener{
@@ -238,10 +236,29 @@ func TestValidateGateway(t *testing.T) {
238236
},
239237
}
240238
},
241-
wantErrors: []string{"certificateRefs must be specified when TLSModeType is Terminate"},
239+
wantErrors: []string{"certificateRefs or options must be specified when mode is Terminate"},
242240
},
243241
{
244-
desc: "certificateRefs set with tls protocol and TLS terminate mode",
242+
desc: "certificateRefs set with HTTPS protocol and TLS terminate mode",
243+
mutate: func(gw *gatewayv1.Gateway) {
244+
tlsMode := gatewayv1.TLSModeType("Terminate")
245+
gw.Spec.Listeners = []gatewayv1.Listener{
246+
{
247+
Name: gatewayv1.SectionName("https"),
248+
Protocol: gatewayv1.HTTPSProtocolType,
249+
Port: gatewayv1.PortNumber(8443),
250+
TLS: &gatewayv1.GatewayTLSConfig{
251+
Mode: &tlsMode,
252+
CertificateRefs: []gatewayv1.SecretObjectReference{
253+
{Name: gatewayv1.ObjectName("foo")},
254+
},
255+
},
256+
},
257+
}
258+
},
259+
},
260+
{
261+
desc: "certificateRefs set with TLS protocol and TLS terminate mode",
245262
mutate: func(gw *gatewayv1.Gateway) {
246263
tlsMode := gatewayv1.TLSModeType("Terminate")
247264
gw.Spec.Listeners = []gatewayv1.Listener{
@@ -259,6 +276,44 @@ func TestValidateGateway(t *testing.T) {
259276
}
260277
},
261278
},
279+
{
280+
desc: "options set with HTTPS protocol and TLS terminate mode",
281+
mutate: func(gw *gatewayv1.Gateway) {
282+
tlsMode := gatewayv1.TLSModeType("Terminate")
283+
gw.Spec.Listeners = []gatewayv1.Listener{
284+
{
285+
Name: gatewayv1.SectionName("https"),
286+
Protocol: gatewayv1.HTTPSProtocolType,
287+
Port: gatewayv1.PortNumber(8443),
288+
TLS: &gatewayv1.GatewayTLSConfig{
289+
Mode: &tlsMode,
290+
Options: map[gatewayv1.AnnotationKey]gatewayv1.AnnotationValue{
291+
"networking.example.com/tls-version": "1.2",
292+
},
293+
},
294+
},
295+
}
296+
},
297+
},
298+
{
299+
desc: "options set with tls protocol and TLS terminate mode",
300+
mutate: func(gw *gatewayv1.Gateway) {
301+
tlsMode := gatewayv1.TLSModeType("Terminate")
302+
gw.Spec.Listeners = []gatewayv1.Listener{
303+
{
304+
Name: gatewayv1.SectionName("tls"),
305+
Protocol: gatewayv1.TLSProtocolType,
306+
Port: gatewayv1.PortNumber(8443),
307+
TLS: &gatewayv1.GatewayTLSConfig{
308+
Mode: &tlsMode,
309+
Options: map[gatewayv1.AnnotationKey]gatewayv1.AnnotationValue{
310+
"networking.example.com/tls-version": "1.2",
311+
},
312+
},
313+
},
314+
}
315+
},
316+
},
262317
{
263318
desc: "names are not unique within the Gateway",
264319
mutate: func(gw *gatewayv1.Gateway) {

0 commit comments

Comments
 (0)