Skip to content

Commit 92d3fa1

Browse files
fix: add trailing slash to gateway name prefix check in CTP port overlap validation
When mergeGateways is enabled and two Gateways exist where one name is a string prefix of the other (e.g. 'gw' and 'gw-b'), a Gateway-wide ClientTrafficPolicy targeting the shorter-named Gateway was incorrectly accepted even though a same-port HTTP listener exists on the other Gateway. The port overlap validation used strings.Index without a trailing slash, causing 'envoy-gateway/gw' to falsely match 'envoy-gateway/gw-b/http'. This fix adds a trailing slash to the gateway name prefix and uses strings.HasPrefix for clarity. Fixes #9226 Signed-off-by: Arunesh Dwivedi <[email protected]>
1 parent d65425e commit 92d3fa1

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎internal/gatewayapi/clienttrafficpolicy.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,10 @@ func validatePortOverlapForClientTrafficPolicy(l *ListenerContext, xds *ir.Xds,
401401
// is turned on, validate that all the listeners affected by this policy originated
402402
// from the same Gateway resource. The name of the Gateway from which this listener
403403
// originated is part of the listener's name by construction.
404-
gatewayName := extractGatewayNameFromListener(irListenerName)
404+
gatewayName := extractGatewayNameFromListener(irListenerName) + "/"
405405
conflictingListeners := []string{}
406406
for _, currName := range sameListeners {
407-
if strings.Index(currName, gatewayName) != 0 {
407+
if !strings.HasPrefix(currName, gatewayName) {
408408
conflictingListeners = append(conflictingListeners, currName)
409409
}
410410
}

0 commit comments

Comments
 (0)