-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: TLS listeners supported #112
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,6 +434,14 @@ func TestSetControlPlaneDefaults(t *testing.T) { | |
Name: "CONTROLLER_ADMISSION_WEBHOOK_LISTEN", | ||
Value: consts.ControlPlaneAdmissionWebhookEnvVarValue, | ||
}, | ||
{ | ||
Name: "", | ||
Value: consts.ControlPlaneAdmissionWebhookEnvVarValue, | ||
}, | ||
Comment on lines
+437
to
+440
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we don't need this right? |
||
{ | ||
Name: "CONTROLLER_FEATURE_GATES", | ||
Value: "GatewayAlpha=true", | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
@@ -511,6 +519,10 @@ func TestSetControlPlaneDefaults(t *testing.T) { | |
Name: "CONTROLLER_ADMISSION_WEBHOOK_LISTEN", | ||
Value: consts.ControlPlaneAdmissionWebhookEnvVarValue, | ||
}, | ||
{ | ||
Name: "CONTROLLER_FEATURE_GATES", | ||
Value: "GatewayAlpha=true", | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -32,4 +32,10 @@ const ( | |||||||||||||||||||||
// to express that more than one TLS secret has been set in the listener | ||||||||||||||||||||||
// TLS configuration. | ||||||||||||||||||||||
ListenerReasonTooManyTLSSecrets k8sutils.ConditionReason = "TooManyTLSSecrets" | ||||||||||||||||||||||
|
||||||||||||||||||||||
// ListenereReasonInvalidTLSMode must be used with the Accepted condition | ||||||||||||||||||||||
// to express that the listener has an invalid TLS mode. | ||||||||||||||||||||||
// HTTPS can only be configured with mode Terminate, while TLS can only be | ||||||||||||||||||||||
// be configured with mode Passthrough. | ||||||||||||||||||||||
ListenereReasonInvalidTLSMode k8sutils.ConditionReason = "InvalidTLSMode" | ||||||||||||||||||||||
Comment on lines
+36
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We might add a reference link to https://gateway-api.sigs.k8s.io/guides/tls/#clientserver-and-tls which contains the table with allowed modes for particular route types. |
||||||||||||||||||||||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -299,8 +299,8 @@ | |
var ( | ||
protocolTCP = corev1.ProtocolTCP | ||
adminAPISSLPort = intstr.FromInt(consts.DataPlaneAdminAPIPort) | ||
proxyPort = intstr.FromInt(consts.DataPlaneProxyPort) | ||
proxySSLPort = intstr.FromInt(consts.DataPlaneProxySSLPort) | ||
proxyPort = intstr.FromInt(consts.DataPlaneProxyHTTPPort) | ||
proxySSLPort = intstr.FromInt(consts.DataPlaneProxyHTTPSPort) | ||
metricsPort = intstr.FromInt(consts.DataPlaneMetricsPort) | ||
) | ||
|
||
|
@@ -527,9 +527,9 @@ | |
return map[gatewayv1.ProtocolType]map[gatewayv1.Kind]struct{}{ | ||
gatewayv1.HTTPProtocolType: {"HTTPRoute": {}}, | ||
gatewayv1.HTTPSProtocolType: {"HTTPRoute": {}}, | ||
gatewayv1.TLSProtocolType: {"TLSRoute": {}}, | ||
|
||
// L4 routes not supported yet | ||
// gatewayv1.TLSProtocolType: {"TLSRoute": {}}, | ||
// TCP and UDP routes not supported yet | ||
// gatewayv1.TCPProtocolType: {"TCPRoute": {}}, | ||
// gatewayv1.UDPProtocolType: {"UDPRoute": {}}, | ||
} | ||
|
@@ -590,10 +590,25 @@ | |
LastTransitionTime: metav1.Now(), | ||
ObservedGeneration: g.Generation, | ||
} | ||
if listener.Protocol != gatewayv1.HTTPProtocolType && listener.Protocol != gatewayv1.HTTPSProtocolType { | ||
if listener.Protocol != gatewayv1.HTTPProtocolType && | ||
listener.Protocol != gatewayv1.HTTPSProtocolType && | ||
listener.Protocol != gatewayv1.TLSProtocolType { | ||
Comment on lines
+593
to
+595
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use the
and then check |
||
acceptedCondition.Status = metav1.ConditionFalse | ||
acceptedCondition.Reason = string(gatewayv1.ListenerReasonUnsupportedProtocol) | ||
} | ||
// Only TLS terminate mode supported with HTTPS Listeners. | ||
if listener.Protocol == gatewayv1.HTTPSProtocolType && *listener.TLS.Mode != gatewayv1.TLSModeTerminate { | ||
acceptedCondition.Status = metav1.ConditionFalse | ||
acceptedCondition.Reason = string(ListenereReasonInvalidTLSMode) | ||
acceptedCondition.Message = "Only Terminate mode is supported with HTTPS listeners" | ||
} | ||
|
||
// Only TLS passthrough mode supported with TLS Listeners. | ||
if listener.Protocol == gatewayv1.TLSProtocolType && *listener.TLS.Mode != gatewayv1.TLSModePassthrough { | ||
acceptedCondition.Status = metav1.ConditionFalse | ||
acceptedCondition.Reason = string(ListenereReasonInvalidTLSMode) | ||
acceptedCondition.Message = "Only Passthrough mode is supported with TLS listeners" | ||
} | ||
Comment on lines
+599
to
+611
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about using a |
||
listenerConditionsAware := listenerConditionsAware(&g.Status.Listeners[i]) | ||
listenerConditionsAware.SetConditions(append(listenerConditionsAware.Conditions, acceptedCondition)) | ||
} | ||
|
@@ -685,9 +700,11 @@ | |
} | ||
switch l.Protocol { | ||
case gatewayv1.HTTPSProtocolType: | ||
port.TargetPort = intstr.FromInt(consts.DataPlaneProxySSLPort) | ||
port.TargetPort = intstr.FromInt(consts.DataPlaneProxyHTTPSPort) | ||
case gatewayv1.HTTPProtocolType: | ||
port.TargetPort = intstr.FromInt(consts.DataPlaneProxyPort) | ||
port.TargetPort = intstr.FromInt(consts.DataPlaneProxyHTTPPort) | ||
case gatewayv1.TLSProtocolType: | ||
port.TargetPort = intstr.FromInt(consts.DataPlaneProxyTLSPort) | ||
default: | ||
errs = errors.Join(errs, fmt.Errorf("listener %d uses unsupported protocol %s", i, l.Protocol)) | ||
continue | ||
|
@@ -712,67 +729,66 @@ | |
|
||
message := "" | ||
if listener.TLS != nil { | ||
// We currently do not support TLSRoutes, hence only TLS termination supported. | ||
if *listener.TLS.Mode != gatewayv1.TLSModeTerminate { | ||
resolvedRefsCondition.Status = metav1.ConditionFalse | ||
resolvedRefsCondition.Reason = string(gatewayv1.ListenerReasonInvalidCertificateRef) | ||
message = conditionMessage(message, "Only Terminate mode is supported") | ||
} | ||
// We currently do not support more that one listener certificate. | ||
if len(listener.TLS.CertificateRefs) != 1 { | ||
if len(listener.TLS.CertificateRefs) > 1 { | ||
resolvedRefsCondition.Reason = string(ListenerReasonTooManyTLSSecrets) | ||
message = conditionMessage(message, "Only one certificate per listener is supported") | ||
} else { | ||
isValidGroupKind := true | ||
certificateRef := listener.TLS.CertificateRefs[0] | ||
if certificateRef.Group != nil && *certificateRef.Group != "" && *certificateRef.Group != gatewayv1.Group(corev1.SchemeGroupVersion.Group) { | ||
resolvedRefsCondition.Reason = string(gatewayv1.ListenerReasonInvalidCertificateRef) | ||
message = conditionMessage(message, fmt.Sprintf("Group %s not supported in CertificateRef", *certificateRef.Group)) | ||
isValidGroupKind = false | ||
} | ||
if certificateRef.Kind != nil && *certificateRef.Kind != "" && *certificateRef.Kind != gatewayv1.Kind("Secret") { | ||
resolvedRefsCondition.Reason = string(gatewayv1.ListenerReasonInvalidCertificateRef) | ||
message = conditionMessage(message, fmt.Sprintf("Kind %s not supported in CertificateRef", *certificateRef.Kind)) | ||
isValidGroupKind = false | ||
} | ||
secretNamespace := gatewayNamespace | ||
if certificateRef.Namespace != nil && *certificateRef.Namespace != "" { | ||
secretNamespace = string(*certificateRef.Namespace) | ||
} | ||
|
||
var secretExists bool | ||
if isValidGroupKind { | ||
// Get the secret and check it exists. | ||
certificateSecret := &corev1.Secret{} | ||
err = c.Get(ctx, types.NamespacedName{ | ||
Namespace: secretNamespace, | ||
Name: string(certificateRef.Name), | ||
}, certificateSecret) | ||
if err != nil { | ||
if !k8serrors.IsNotFound(err) { | ||
return | ||
} | ||
// check certificate references only when Terminate mode is used. | ||
// Passthrough mode does not need a certificate. | ||
if len(listener.TLS.CertificateRefs) != 0 { | ||
isValidGroupKind := true | ||
certificateRef := listener.TLS.CertificateRefs[0] | ||
if certificateRef.Group != nil && *certificateRef.Group != "" && *certificateRef.Group != gatewayv1.Group(corev1.SchemeGroupVersion.Group) { | ||
resolvedRefsCondition.Reason = string(gatewayv1.ListenerReasonInvalidCertificateRef) | ||
message = conditionMessage(message, fmt.Sprintf("Referenced secret %s/%s does not exist", secretNamespace, certificateRef.Name)) | ||
} else { | ||
secretExists = true | ||
message = conditionMessage(message, fmt.Sprintf("Group %s not supported in CertificateRef", *certificateRef.Group)) | ||
isValidGroupKind = false | ||
} | ||
if certificateRef.Kind != nil && *certificateRef.Kind != "" && *certificateRef.Kind != gatewayv1.Kind("Secret") { | ||
resolvedRefsCondition.Reason = string(gatewayv1.ListenerReasonInvalidCertificateRef) | ||
message = conditionMessage(message, fmt.Sprintf("Kind %s not supported in CertificateRef", *certificateRef.Kind)) | ||
isValidGroupKind = false | ||
} | ||
secretNamespace := gatewayNamespace | ||
if certificateRef.Namespace != nil && *certificateRef.Namespace != "" { | ||
secretNamespace = string(*certificateRef.Namespace) | ||
} | ||
} | ||
|
||
if secretExists { | ||
// In case there is a cross-namespace reference, check if there is any referenceGrant allowing it. | ||
if secretNamespace != gatewayNamespace { | ||
referenceGrantList := &gatewayv1beta1.ReferenceGrantList{} | ||
err = c.List(ctx, referenceGrantList, client.InNamespace(secretNamespace)) | ||
var secretExists bool | ||
if isValidGroupKind { | ||
// Get the secret and check it exists. | ||
certificateSecret := &corev1.Secret{} | ||
err = c.Get(ctx, types.NamespacedName{ | ||
Namespace: secretNamespace, | ||
Name: string(certificateRef.Name), | ||
}, certificateSecret) | ||
if err != nil { | ||
return | ||
if !k8serrors.IsNotFound(err) { | ||
return | ||
} | ||
resolvedRefsCondition.Reason = string(gatewayv1.ListenerReasonInvalidCertificateRef) | ||
message = conditionMessage(message, fmt.Sprintf("Referenced secret %s/%s does not exist", secretNamespace, certificateRef.Name)) | ||
} else { | ||
secretExists = true | ||
} | ||
if !isSecretCrossReferenceGranted(gatewayv1.Namespace(gatewayNamespace), certificateRef.Name, referenceGrantList.Items) { | ||
resolvedRefsCondition.Reason = string(gatewayv1.ListenerReasonRefNotPermitted) | ||
message = conditionMessage(message, fmt.Sprintf("Secret %s/%s reference not allowed by any referenceGrant", secretNamespace, certificateRef.Name)) | ||
} | ||
|
||
if secretExists { | ||
// In case there is a cross-namespace reference, check if there is any referenceGrant allowing it. | ||
if secretNamespace != gatewayNamespace { | ||
referenceGrantList := &gatewayv1beta1.ReferenceGrantList{} | ||
err = c.List(ctx, referenceGrantList, client.InNamespace(secretNamespace)) | ||
if err != nil { | ||
return | ||
} | ||
if !isSecretCrossReferenceGranted(gatewayv1.Namespace(gatewayNamespace), certificateRef.Name, referenceGrantList.Items) { | ||
resolvedRefsCondition.Reason = string(gatewayv1.ListenerReasonRefNotPermitted) | ||
message = conditionMessage(message, fmt.Sprintf("Secret %s/%s reference not allowed by any referenceGrant", secretNamespace, certificateRef.Name)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add one more sample with just the
TLSRoute
and aGateway
withTLS
listener?