Skip to content

fix(proxy): use transport_socket_filter_state extension in upstream matcher - #301

Merged
bpalermo merged 1 commit into
mainfrom
fix/tcp-floor-upstream-mtls
Jun 24, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/tcp-floor-upstream-mtls

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Root cause

The cluster transport_socket_matcher was wired with the wrong Envoy extension name.

Wrong: "envoy.matching.inputs.filter_state" — the generic network/HTTP FilterStateInput (envoy/extensions/matching/common_inputs/network/v3)

Correct: "envoy.matching.inputs.transport_socket_filter_state" — the transport-socket-scoped FilterStateInput (envoy/extensions/matching/common_inputs/transport_socket/v3)

These are two distinct registered extensions with different MatchingData contexts:

  • The generic filter_state reads from StreamInfo::filterState() directly. It is registered for NetworkMatchingData / HttpMatchingData (filter chain selection, route matching).
  • The transport-socket-specific transport_socket_filter_state reads from TransportSocketOptions::downstreamSharedFilterStateObjects() — the filter state objects propagated from the downstream connection via SharedWithUpstream: ONCE. It is registered for TransportSocketMatchingData, which is what a cluster transport_socket_matcher evaluates against.

Using the generic name in a transport_socket_matcher causes Envoy to resolve the input factory against the wrong MatchingData type. The input returns nullopt silently, the exact-match map never fires, and evaluation falls to OnNoMatch for every upstream connection. Per-source certificate selection was silently broken on every cluster in the mesh.

Blast radius

  • HTTP (HCM) clusters: OnNoMatch selects the node identity socket, which does connect. Traffic flows, but every pod's egress presents the node cert (not the pod's SVID). The SAN of the node identity is within the trust domain, so SAN pinning is loose enough that connections succeed — but the per-source identity claim is wrong.

  • TCP floor clusters (tcp_proxy): OnNoMatch also selects the node identity socket. The node identity (spiffe://aether.internal/ns/aether-system/sa/aether-agent) does not match the service's expected SPIFFE IDs (which are scoped to the service's own namespace, e.g., aether-test). The TLS handshake fails at the destination SAN check. Because the connection resets immediately after TLS, cluster.<svc>.upstream_cx_total stays at 0 — the symptom reported.

Why tcp_proxy and HCM behave differently for the TCP floor

Confirmed in Envoy source (tcp_proxy.cc Filter::establishUpstreamConnection): tcp_proxy propagates SharedWithUpstream: ONCE filter state through TransportSocketOptions via the identical code path as HCM (TransportSocketOptionsUtility::fromFilterState → objectsSharedWithUpstreamConnection()). The two-fix assumption (previous PRs #298/#299) that the extension name or match names were wrong was correct for those bugs, but the root cause of upstream_cx_total = 0 was this extension name mismatch — also present on the HCM path but masked by the loose SAN check.

Fix

One-line change: filterStateInputName = "envoy.matching.inputs.transport_socket_filter_state".

The TypedConfig proto was already using the correct type (transport_socket.v3.FilterStateInput) — only the Name field in the TypedExtensionConfig needed correction.

Tests

  • TestUpstreamTransportSocketMatcherExtensionName: explicit regression test asserting the extension name is the transport-socket variant and is not the generic one.
  • TestUpstreamTransportSocketMatcher: updated comment + assertion message to document the distinction.
  • TestServiceClusterMTLSInjected: asserts the HTTP cluster's matcher also uses the correct extension name.
  • TestLoadClustersFromRegistry_TCPCluster: asserts the TCP floor cluster's matcher uses the correct extension name and provides a causal explanation in the failure message.

Confidence

High. The extension name mismatch is the only code-level difference between what the code emits and what Envoy expects for TransportSocketMatchingData. The tcp_proxy propagation path is verified in source. After this fix, per-source SVID selection will work for both HCM and tcp_proxy upstreams for the first time.

🤖 Generated with Claude Code

https://claude.ai/code/session_01N7oY7W8oDXrqDzFgoZh25S

…atcher

The cluster transport_socket_matcher was wired with the wrong Envoy
extension name: "envoy.matching.inputs.filter_state" (the generic
network/HTTP FilterStateInput) instead of
"envoy.matching.inputs.transport_socket_filter_state" (the
transport-socket-scoped FilterStateInput).

These are two distinct registered extensions backed by different proto
types and different MatchingData contexts:

  - envoy.matching.inputs.filter_state reads from StreamInfo::filterState()
    on the connection. It is registered for NetworkMatchingData /
    HttpMatchingData contexts (filter chain selection, route matching).

  - envoy.matching.inputs.transport_socket_filter_state reads from
    TransportSocketOptions::downstreamSharedFilterStateObjects() — the
    filter state objects propagated from the downstream connection via
    SharedWithUpstream. It is registered for TransportSocketMatchingData,
    which is what a cluster transport_socket_matcher evaluates against.

Using the generic name in a transport_socket_matcher causes Envoy to
resolve the factory for the wrong MatchingData type. The input returns
nullopt (no value found), the exact-match map never fires, and evaluation
falls to OnNoMatch for every upstream connection. Per-source certificate
selection is silently broken: all egress presents the node identity
regardless of the originating pod.

For HTTP (HCM) upstream clusters, OnNoMatch uses the node identity socket
which does connect — so traffic flows, but the certificate is always the
node cert rather than the pod's. For TCP floor clusters (tcp_proxy
upstream), the node identity cert's SAN does not match the service's
expected SPIFFE IDs (different namespace), so the TLS handshake fails at
the destination. Because the connection resets during or immediately after
TLS, the stat counter (cluster.<svc>.upstream_cx_total) stays at 0.

Fix: change filterStateInputName to the correct transport-socket extension
name. The proto TypedConfig already uses the correct type
(envoy/extensions/matching/common_inputs/transport_socket/v3/FilterStateInput)
— only the Name field in the TypedExtensionConfig needed correction. The
tcp_proxy filter propagates SharedWithUpstream filter state through
TransportSocketOptions via the identical path as HCM (confirmed in Envoy
source: tcp_proxy.cc Filter::establishUpstreamConnection() calls
TransportSocketOptionsUtility::fromFilterState, which collects
objectsSharedWithUpstreamConnection(); the transport socket matcher
then reconstructs the filter state from those options and evaluates).

Add regression tests at the extension-name level in both the proxy unit
tests and the cache integration tests, with comments explaining the
distinction and the failure mode.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01N7oY7W8oDXrqDzFgoZh25S
@bpalermo
bpalermo merged commit 2565e3c into main Jun 24, 2026
11 checks passed
@bpalermo
bpalermo deleted the fix/tcp-floor-upstream-mtls branch June 24, 2026 15:57
bpalermo added a commit that referenced this pull request Jun 24, 2026
…sport path (#304)

The bespoke "aether-tcp" ALPN forced a duplicated TCP-specific transport-socket
stack (UpstreamTCPTransportSocket, the :tcp matches/OnNoMatch) parallel to the proven
HTTP one — and all three earlier floor fixes (#298/#299/#301) lived in that copy,
yet the upstream mTLS still never connected (upstream_cx_total=0).

Collapse the demux onto the standard h2 ALPN instead:
- Egress: UpstreamTCPTransportSocket now advertises NO ALPN (HTTP keeps "h2"); it
  otherwise reuses the same per-source matcher/matches machinery that already works.
- Inbound :15008: the no-SNI HCM chain matches application_protocols:["h2"]; per-port
  HCM chains keep their port SNI; the TCP floor becomes the listener's DEFAULT chain
  (no match). Envoy precedence (server_names > application_protocols > default) routes
  h2+SNI → per-port, h2 → default-HCM, no-ALPN mTLS → the floor — no bespoke token.
- Removed the AetherTCPALPN constant.

This deletes the duplicated TCP transport stack that harbored the per-source-cert
selection bug, so the floor rides the validated HTTP per-source mTLS path. Validate
on talos: echo-tcp.aether.internal:18081 (HTTP over the mTLS TCP floor) -> 200.


Claude-Session: https://claude.ai/code/session_01N7oY7W8oDXrqDzFgoZh25S

Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant