Skip to content

Commit 537b50e

Browse files
Backport of [NET-9098] Narrow scope of peering config on terminating gw filter chain to TCP services into release/1.18.x (#21057)
backport of commit d65f512 Co-authored-by: Nathan Coleman <nathan.coleman@hashicorp.com>
1 parent a08bcba commit 537b50e

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

agent/xds/listeners.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -1759,14 +1759,8 @@ type terminatingGatewayFilterChainOpts struct {
17591759
}
17601760

17611761
func (s *ResourceGenerator) makeFilterChainTerminatingGateway(cfgSnap *proxycfg.ConfigSnapshot, tgtwyOpts terminatingGatewayFilterChainOpts) (*envoy_listener_v3.FilterChain, error) {
1762-
// We need to at least match the SNI and use the root PEMs from the local cluster; however, requests coming
1763-
// from peered clusters where the external service is exported to will have their own SNI and root PEMs.
1762+
// We need to at least match the SNI and use the root PEMs from the local cluster
17641763
sniMatches := []string{tgtwyOpts.cluster}
1765-
for _, bundle := range tgtwyOpts.peerTrustBundles {
1766-
svc := tgtwyOpts.service
1767-
sourceSNI := connect.PeeredServiceSNI(svc.Name, svc.NamespaceOrDefault(), svc.PartitionOrDefault(), bundle.PeerName, cfgSnap.Roots.TrustDomain)
1768-
sniMatches = append(sniMatches, sourceSNI)
1769-
}
17701764

17711765
tlsContext := &envoy_tls_v3.DownstreamTlsContext{
17721766
CommonTlsContext: makeCommonTLSContext(
@@ -1777,9 +1771,19 @@ func (s *ResourceGenerator) makeFilterChainTerminatingGateway(cfgSnap *proxycfg.
17771771
RequireClientCertificate: &wrapperspb.BoolValue{Value: true},
17781772
}
17791773

1780-
err := injectSpiffeValidatorConfigForPeers(cfgSnap, tlsContext.CommonTlsContext, tgtwyOpts.peerTrustBundles)
1781-
if err != nil {
1782-
return nil, err
1774+
// For TCP connections, TLS is not terminated at the mesh gateway but is instead proxied through;
1775+
// therefore, we need to account for callers from other datacenters when setting up our filter chain.
1776+
if tgtwyOpts.protocol == "tcp" {
1777+
for _, bundle := range tgtwyOpts.peerTrustBundles {
1778+
svc := tgtwyOpts.service
1779+
sourceSNI := connect.PeeredServiceSNI(svc.Name, svc.NamespaceOrDefault(), svc.PartitionOrDefault(), bundle.PeerName, cfgSnap.Roots.TrustDomain)
1780+
sniMatches = append(sniMatches, sourceSNI)
1781+
}
1782+
1783+
err := injectSpiffeValidatorConfigForPeers(cfgSnap, tlsContext.CommonTlsContext, tgtwyOpts.peerTrustBundles)
1784+
if err != nil {
1785+
return nil, err
1786+
}
17831787
}
17841788

17851789
transportSocket, err := makeDownstreamTLSTransportSocket(tlsContext)

0 commit comments

Comments
 (0)