Skip to content

Commit 4d15041

Browse files
committed
fix: more robust HTTPRoute validation
1 parent da0be9c commit 4d15041

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ Adding a new version? You'll need three changes:
134134
- For `HTTPRoute`, protocol now matches the attached Gateway listener protocol (and when `parentRef.sectionName` is set, it must match that specific listener). When `parentRef.sectionName` is not specified it binds to all `Gateway`s listeners.
135135
- For `Ingress`, default protocol relies on Kong Gateway, can be set explicitly via `konghq.com/protocols: "http"` (or `https`)
136136
annotation on particular `Ingress`.
137+
[#7901](https://github.com/Kong/kubernetes-ingress-controller/pull/7901)
138+
- More robust validation for `HTTPRoute`, when unsupported feature is used and route refers existing and non-existing `Gateway`, it will be rejected.
139+
[#7913](https://github.com/Kong/kubernetes-ingress-controller/pull/7913)
137140

138141
## [3.5.6]
139142

internal/admission/validation/gateway/httproute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func ensureHTTPRouteIsManagedByController(ctx context.Context, httproute *gatewa
105105
Name: string(parentRef.Name),
106106
}, &gateway); err != nil {
107107
if apierrors.IsNotFound(err) {
108-
return false, nil
108+
continue
109109
}
110110
return false, fmt.Errorf("failed to get Gateway: %w", err)
111111
}

internal/admission/validation/gateway/httproute_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,47 @@ func TestValidateHTTPRoute(t *testing.T) {
10151015
},
10161016
valid: true,
10171017
},
1018+
{
1019+
msg: "HTTPRoute with unsupported filter when reference both existing and non-existing gateway should be rejected",
1020+
cachedObjects: []client.Object{
1021+
gatewayClass,
1022+
&gatewayapi.Gateway{
1023+
ObjectMeta: metav1.ObjectMeta{
1024+
Namespace: corev1.NamespaceDefault,
1025+
Name: "existing-managed-gateway",
1026+
},
1027+
Spec: gatewayapi.GatewaySpec{GatewayClassName: gatewayClassName},
1028+
},
1029+
},
1030+
route: &gatewayapi.HTTPRoute{
1031+
ObjectMeta: metav1.ObjectMeta{
1032+
Namespace: corev1.NamespaceDefault,
1033+
Name: "example-route",
1034+
},
1035+
Spec: gatewayapi.HTTPRouteSpec{
1036+
CommonRouteSpec: gatewayapi.CommonRouteSpec{
1037+
ParentRefs: []gatewayapi.ParentReference{
1038+
{
1039+
Name: "non-existent-gateway",
1040+
Namespace: lo.ToPtr(gatewayapi.Namespace(corev1.NamespaceDefault)),
1041+
},
1042+
{
1043+
Name: "existing-managed-gateway",
1044+
Namespace: lo.ToPtr(gatewayapi.Namespace(corev1.NamespaceDefault)),
1045+
},
1046+
},
1047+
},
1048+
Rules: []gatewayapi.HTTPRouteRule{{
1049+
Filters: []gatewayapi.HTTPRouteFilter{{
1050+
// RequestMirror is explicitly unsupported — should be rejected.
1051+
Type: gatewayapi.HTTPRouteFilterRequestMirror,
1052+
}},
1053+
}},
1054+
},
1055+
},
1056+
valid: false,
1057+
validationMsg: "HTTPRoute spec did not pass validation: rules[0].filters[0]: filter type RequestMirror is unsupported",
1058+
},
10181059
} {
10191060
t.Run(tt.msg, func(t *testing.T) {
10201061
fakeClient := fakeclient.

0 commit comments

Comments
 (0)