diff --git a/agent/consul/discoverychain/compile.go b/agent/consul/discoverychain/compile.go index dd7dea28df..da8754cb03 100644 --- a/agent/consul/discoverychain/compile.go +++ b/agent/consul/discoverychain/compile.go @@ -1007,15 +1007,15 @@ RESOLVE_AGAIN: // Default mesh gateway settings if serviceDefault := c.entries.GetService(targetID); serviceDefault != nil { target.MeshGateway = serviceDefault.MeshGateway - target.TransparentProxy = serviceDefault.TransparentProxy + target.TransparentProxy.DialedDirectly = serviceDefault.TransparentProxy.DialedDirectly } proxyDefault := c.entries.GetProxyDefaults(targetID.PartitionOrDefault()) if proxyDefault != nil { if target.MeshGateway.Mode == structs.MeshGatewayModeDefault { target.MeshGateway.Mode = proxyDefault.MeshGateway.Mode } - if target.TransparentProxy.IsZero() { - target.TransparentProxy = proxyDefault.TransparentProxy + if !target.TransparentProxy.DialedDirectly { + target.TransparentProxy.DialedDirectly = proxyDefault.TransparentProxy.DialedDirectly } } diff --git a/agent/proxycfg/state_test.go b/agent/proxycfg/state_test.go index 85cf0228e5..894f2bd479 100644 --- a/agent/proxycfg/state_test.go +++ b/agent/proxycfg/state_test.go @@ -2359,7 +2359,16 @@ func TestState_WatchesAndUpdates(t *testing.T) { { CorrelationID: "discovery-chain:" + dbUID.String(), Result: &structs.DiscoveryChainResponse{ - Chain: discoverychain.TestCompileConfigEntries(t, "db", "default", "default", "dc1", "trustdomain.consul", nil), + Chain: discoverychain.TestCompileConfigEntries( + t, "db", "default", "default", "dc1", "trustdomain.consul", nil, + &structs.ServiceConfigEntry{ + Kind: structs.ServiceDefaults, + Name: "db", + TransparentProxy: structs.TransparentProxyConfig{ + DialedDirectly: true, + }, + }, + ), }, Err: nil, }, @@ -2396,7 +2405,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { Proxy: structs.ConnectProxyConfig{ DestinationServiceName: "db", TransparentProxy: structs.TransparentProxyConfig{ - DialedDirectly: true, + DialedDirectly: false, // This is set true by the service-defaults entry above. }, }, RaftIndex: structs.RaftIndex{ @@ -2455,7 +2464,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { Proxy: structs.ConnectProxyConfig{ DestinationServiceName: "db", TransparentProxy: structs.TransparentProxyConfig{ - DialedDirectly: true, + DialedDirectly: false, }, }, RaftIndex: structs.RaftIndex{