@@ -704,35 +704,19 @@ func (t *Translator) translateSecurityPolicyForRoute(
704704 irKey := t .getIRKey (gtwCtx .Gateway )
705705 switch route .GetRouteType () {
706706 case resource .KindTCPRoute :
707- // Only client-IP Authorization is applicable for TCP routes.
708- // TCP IR route names are flat. The computed prefix includes a trailing
709- // '/' (e.g. "tcproute/default/tcp-app-2/"), so trim the suffix to
710- // get the exact TCP route name used in the IR:
711- // prefix == "tcproute/default/tcp-app-2/" -> expectedTCPRouteName == "tcproute/default/tcp-app-2"
712- expectedTCPRouteName := strings .TrimSuffix (prefix , "/" )
713707 for _ , listener := range parentRefCtx .listeners {
714708 tl := xdsIR [irKey ].GetTCPListener (irListenerName (listener ))
715- if tl == nil {
716- continue
717- }
718709 for _ , r := range tl .Routes {
719- if r == nil {
720- continue
721- }
722710 // If target.SectionName is specified it must match the route-rule section name
723711 // in the IR. For HTTP/GRPC routes this is r.Metadata.SectionName; for TCP
724712 // routes the section name is currently stored on r.Destination.Metadata.SectionName.
725713 if target .SectionName != nil && string (* target .SectionName ) != r .Destination .Metadata .SectionName {
726714 continue
727715 }
728- // if already set - there's a specific level policy, so skip.
716+
729717 if r .Authorization != nil {
730718 continue
731719 }
732- // exact match only (TCP route names are flat in IR)
733- if r .Name != expectedTCPRouteName {
734- continue
735- }
736720 // Only authorization for TCP
737721 authCopy := * authorization
738722 r .Authorization = & authCopy
@@ -741,30 +725,26 @@ func (t *Translator) translateSecurityPolicyForRoute(
741725 case resource .KindHTTPRoute , resource .KindGRPCRoute :
742726 for _ , listener := range parentRefCtx .listeners {
743727 irListener := xdsIR [irKey ].GetHTTPListener (irListenerName (listener ))
744- if irListener == nil {
745- continue
746- }
747- for _ , r := range irListener .Routes {
748- if r == nil {
749- continue
750- }
751- // If specified the sectionName must match route rule from ir route metadata.
752- if target .SectionName != nil && string (* target .SectionName ) != r .Metadata .SectionName {
753- continue
754- }
755-
756- // A Policy targeting the most specific scope(xRoute rule) wins over a policy
757- // targeting a lesser specific scope(xRoute).
758- if strings .HasPrefix (r .Name , prefix ) {
759- // if already set - there's a specific level policy, so skip.
760- if r .Security != nil {
728+ if irListener != nil {
729+ for _ , r := range irListener .Routes {
730+ // If specified the sectionName must match route rule from ir route metadata.
731+ if target .SectionName != nil && string (* target .SectionName ) != r .Metadata .SectionName {
761732 continue
762733 }
763734
764- r .Security = securityFeatures
765- if errorResponse != nil {
766- // Return a 500 direct response to avoid unauthorized access
767- r .DirectResponse = errorResponse
735+ // A Policy targeting the most specific scope(xRoute rule) wins over a policy
736+ // targeting a lesser specific scope(xRoute).
737+ if strings .HasPrefix (r .Name , prefix ) {
738+ // if already set - there's a specific level policy, so skip.
739+ if r .Security != nil {
740+ continue
741+ }
742+
743+ r .Security = securityFeatures
744+ if errorResponse != nil {
745+ // Return a 500 direct response to avoid unauthorized access
746+ r .DirectResponse = errorResponse
747+ }
768748 }
769749 }
770750 }
0 commit comments