From 9854a0ecb461bd546106cf547029cd90b7c0a3e8 Mon Sep 17 00:00:00 2001 From: David Winiarski Date: Tue, 8 Apr 2025 13:29:24 -0600 Subject: [PATCH] validate group and kind on the spec.parentRef. Move check into gwRouteHasParentRef --- source/gateway.go | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/source/gateway.go b/source/gateway.go index 797d6914c..854a0f77c 100644 --- a/source/gateway.go +++ b/source/gateway.go @@ -307,16 +307,11 @@ func (c *gatewayRouteResolver) resolve(rt gatewayRoute) (map[string]endpoint.Tar for _, rps := range rt.RouteStatus().Parents { // Confirm the Parent is the standard Gateway kind. ref := rps.ParentRef - // Ensure that the parent reference is in the routeParentRefs list - found := false - for _, rpr := range routeParentRefs { - if string(rpr.Name) == string(ref.Name) && string(*rpr.Namespace) == string(*ref.Namespace) { - found = true - break - } - } namespace := strVal((*string)(ref.Namespace), meta.Namespace) - if !found { + // Ensure that the parent reference is in the routeParentRefs list + hasParentRef := gwRouteHasParentRef(routeParentRefs, ref, meta) + + if !hasParentRef { log.Debugf("Parent reference %s/%s not found in routeParentRefs for %s %s/%s", namespace, string(ref.Name), c.src.rtKind, meta.Namespace, meta.Name) continue } @@ -481,6 +476,26 @@ func (c *gatewayRouteResolver) routeIsAllowed(gw *v1beta1.Gateway, lis *v1.Liste return false } +func gwRouteHasParentRef(routeParentRefs []v1.ParentReference, ref v1.ParentReference, meta *metav1.ObjectMeta) bool { + // Ensure that the parent reference is in the routeParentRefs list + namespace := strVal((*string)(ref.Namespace), meta.Namespace) + group := strVal((*string)(ref.Group), gatewayGroup) + kind := strVal((*string)(ref.Kind), gatewayKind) + for _, rpr := range routeParentRefs { + rprGroup := strVal((*string)(rpr.Group), gatewayGroup) + rprKind := strVal((*string)(rpr.Kind), gatewayKind) + if rprGroup != group || rprKind != kind { + continue + } + rprNamespace := strVal((*string)(rpr.Namespace), meta.Namespace) + if string(rpr.Name) != string(ref.Name) || rprNamespace != namespace { + continue + } + return true + } + return false +} + func gwRouteIsAccepted(conds []metav1.Condition) bool { for _, c := range conds { if v1.RouteConditionType(c.Type) == v1.RouteConditionAccepted {