Skip to content

Commit

Permalink
Ensure that duplicate listeners are not added when crossMesh is enabl…
Browse files Browse the repository at this point in the history
…ed on a listener and Routes specify hostnames

In the cross-mesh case, the SNI string will be a kuma SNI string for the gateway service (e.g. edge-gateway{mesh=default,port=tcp-8080}). Thus it is not possible to distinguish hosts at the listener level and no filter chain sni matchers are added. This can lead to a duplicate listener filter chain being added if there are multiple hostnames to route.

Thus we truncate the gatewayHosts array to size 1 before creating the listener blocks.

Signed-off-by: Tim Treptow <ttreptow@domaintools.com>
  • Loading branch information
ttreptow committed Oct 26, 2023
1 parent afef153 commit e03462e
Show file tree
Hide file tree
Showing 4 changed files with 1,516 additions and 33 deletions.
99 changes: 96 additions & 3 deletions pkg/plugins/runtime/gateway/gateway_route_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1440,30 +1440,123 @@ conf:
- port: 8080
protocol: HTTP
crossMesh: true
tags:
hostname: route-only
- port: 8081
protocol: HTTP
crossMesh: true
hostname: internal-cross-mesh.mesh
tags:
hostname: internal-cross-mesh.mesh
- port: 8082
protocol: HTTP
crossMesh: true
tags:
hostname: default
`, `
type: MeshGatewayRoute
mesh: default
name: echo-service
name: echo-service-default
selectors:
- match:
kuma.io/service: gateway-default
hostname: default
conf:
http:
rules:
- matches:
- path:
match: PREFIX
value: "/ext"
backends:
- destination:
kuma.io/service: external-httpbin
- matches:
- path:
match: PREFIX
value: "/echo"
backends:
- destination:
kuma.io/service: echo-service
`, `
type: MeshGatewayRoute
mesh: default
name: echo-service-with-hostname
selectors:
- match:
kuma.io/service: gateway-default
hostname: route-only
conf:
http:
hostnames:
- cross-mesh.mesh
- cross-mesh2.mesh
rules:
- matches:
- path:
match: PREFIX
value: "/ext"
value: "/hostname-ext"
backends:
- destination:
kuma.io/service: external-httpbin
- matches:
- path:
match: PREFIX
value: "/echo"
value: "/hostname-echo"
backends:
- destination:
kuma.io/service: echo-service
`, `
type: MeshGatewayRoute
mesh: default
name: echo-service-with-hostname-and-hostname-on-listener
selectors:
- match:
kuma.io/service: gateway-default
hostname: internal-cross-mesh.mesh
conf:
http:
hostnames:
- cross-mesh.mesh
rules:
- matches:
- path:
match: PREFIX
value: "/hostname-and-hostname-on-listener-no-match-ext"
backends:
- destination:
kuma.io/service: external-httpbin
- matches:
- path:
match: PREFIX
value: "/hostname-and-hostname-on-listener-no-match-echo"
backends:
- destination:
kuma.io/service: echo-service
`, `
type: MeshGatewayRoute
mesh: default
name: echo-service-with-hostname-and-different-hostname-on-listener
selectors:
- match:
kuma.io/service: gateway-default
hostname: internal-cross-mesh.mesh
conf:
http:
hostnames:
- internal-cross-mesh.mesh
rules:
- matches:
- path:
match: PREFIX
value: "/hostname-and-hostname-on-listener-match-ext"
backends:
- destination:
kuma.io/service: external-httpbin
- matches:
- path:
match: PREFIX
value: "/hostname-and-hostname-on-listener-match-echo"
backends:
- destination:
kuma.io/service: echo-service
Expand Down
4 changes: 4 additions & 0 deletions pkg/plugins/runtime/gateway/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ func (g Generator) generateLDS(ctx xds_context.Context, info GatewayListenerInfo
for _, hostInfo := range hostInfos {
gatewayHosts = append(gatewayHosts, hostInfo.Host)
}
if info.Listener.CrossMesh {
//for cross-mesh, we can only add one listener filter chain as there will not be any (usable) SNI available for filter chain matching

Check failure on line 260 in pkg/plugins/runtime/gateway/generator.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
gatewayHosts = gatewayHosts[:1]
}

protocol := info.Listener.Protocol
if info.Listener.CrossMesh {
Expand Down
Loading

0 comments on commit e03462e

Please sign in to comment.