Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions internal/gatewayapi/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,17 @@ func isOverlappingHostname(hostname1, hostname2 *gwapiv1.Hostname) bool {
if hostname1 == nil || hostname2 == nil {
return true
}
domain1 := strings.Replace(string(*hostname1), "*.", "", 1)
domain2 := strings.Replace(string(*hostname2), "*.", "", 1)
return isSubdomain(domain1, domain2) || isSubdomain(domain2, domain1)
}

h1 := strings.Replace(string(*hostname1), "*.", "", 1)
h2 := strings.Replace(string(*hostname2), "*.", "", 1)
return strings.HasSuffix(h1, h2) || strings.HasSuffix(h2, h1)
// isSubdomain checks if subDomain is a sub-domain of domain
func isSubdomain(subDomain, domain string) bool {
if subDomain == domain {
return true
}
return strings.HasSuffix(subDomain, fmt.Sprintf(".%s", domain))
}

func buildListenerMetadata(listener *ListenerContext, gateway *GatewayContext) *ir.ResourceMetadata {
Expand Down
6 changes: 6 additions & 0 deletions internal/gatewayapi/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ func TestIsOverlappingHostname(t *testing.T) {
hostname2: ptr.To(gwapiv1.Hostname("*.test.com")),
want: false,
},
{
name: "different sub domains of same domain",
hostname1: ptr.To(gwapiv1.Hostname("api.foo.dev")),
hostname2: ptr.To(gwapiv1.Hostname("testing-api.foo.dev")),
want: false,
},
}

for _, tt := range tests {
Expand Down
1 change: 1 addition & 0 deletions release-notes/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bug fixes: |
Keep ALPN configuration for listeners with overlapping certificates when ALPN is explicitly set in ClientTrafficPolicy.
Fixed issue that switch on wrong SubjectAltNameType enum value in BackendTLSPolicy.
Fixed issue that BackendTLSPolicy should not reference ConfigMap or Secret across namespace.
Fixed bug in certificate SANs overlap detection in listeners.

# Enhancements that improve performance.
performance improvements: |
Expand Down