Skip to content

fix(capture): stop use_original_dst handing diverted connections to whichever pod bound 0.0.0.0:18008 last (#1007) - #1030

Merged
bpalermo merged 2 commits into
mainfrom
fix/1007-capture-no-use-original-dst
Sep 28, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/1007-capture-no-use-original-dst

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Do not merge until #1022's talos proof is in (#1028 deployed, and the TCP-floor landing counter reads zero on the patched proxy). With this change alone, a node-proxy socket leaked into a pod netns (the #1022 defect) would leave through the correct endpoint's ORIGINAL_DST from a pod IP and succeed silently. The stray in_tcp_<pod> landings are the only signal that shows #1022, and this change would switch them off. That is why this PR is a draft.

What was wrong

The capture listener set use_original_dst: true. In Envoy, that listener field adds two things:

  1. A second copy of the original_dst listener filter (listener_impl.cc buildOriginalDstListenerFilter). aether already configures that filter explicitly, first in the list.
  2. The restored-destination handoff (active_tcp_socket.cc:240-267). When a connection's restored local address matches another listener, Envoy hands the connection to "the listener bound to that address" via getBalancedHandlerByAddress. The lookup is keyed by the address string alone (connection_handler_impl.cc:122, wildcard fallback :425-433), and the string carries no netns.

Every pod's inbound listener binds 0.0.0.0:18008 inside its own netns, so each new pod overwrites the previous entry. Any connection a capture listener accepted with original destination *:18008 therefore ran through the inbound filter chains of whichever pod was added last. That listener presented its own SVID and failed the client's SAN check. This is the "always the newest pod on the node" landing from #1007.

The change

  • UseOriginalDst: false on the capture listener (agent/internal/xds/proxy/capture.go).
  • The explicit original_dst listener filter stays, first in the list. It is the thing that sets localAddressRestored(). It is also all the ORIGINAL_DST passthrough needs: original_dst_cluster.cc:51 reads the downstream local address only if (connection->connectionInfoProvider().localAddressRestored()). Every capture filter chain matches on that restored destination too.
  • Mesh capture never used the handoff. Every decision is either a chain match on the restored VIP:port or the ORIGINAL_DST passthrough.
  • Comments corrected. The comment at the field claimed it was needed for localAddressRestored(). The comment on buildCaptureTCPPortFilterChain, the listener-filter comment and the captureport_test doc all said "already sets use_original_dst". All of them now point at the filter.

Tests

  • capture_test.go (TestGenerateCaptureListener): asserts the field is set explicitly and is false, and still asserts that original_dst is the first listener filter.
  • //test/envoy_validate capture fixture (TestCaptureTCPListenerIsTransparentAndKeepsOriginalDst): the fixture still passes envoy --mode validate against the chart-pinned aether-proxy with the field off. It asserts the field is false next to transparent and next to original_dst being first.
  • Shown red: with the field flipped back to true, both fail:
    --- FAIL: TestGenerateCaptureListener            Should be false  use_original_dst must be false (#1007)
    --- FAIL: TestCaptureTCPListenerIsTransparentAndKeepsOriginalDst  Should be false  use_original_dst must be false: its handoff picks the newest pod's 0.0.0.0:18008 inbound listener (#1007)
    
    With it false, //agent/internal/xds/proxy:proxy_test and //test/envoy_validate:envoy_validate_test pass. Lint (--config=lint --@aspect_rules_lint//lint:fail_on_violation) and //:format are clean.

e2e (kind)

I ran L4_SKIP_BUILD=1 ./e2e/l4routes.sh (up + verify) on kind, with images built from this branch. It exits 0 with every assertion passing:

  • TCPRoute: floor control 20/20; 75/25 split gave alpha 151/200, bravo 49/200, floor 0; weight-0 drain was exact both ways (200/0 and 0/200); all-drained fell back to the passthrough floor 50/50; delete returned 20/20 to the floor.
  • TLSRoute: TLS floor 60/60 on a port no chain claims; SNI alpha/bravo each 20/20 to their own backend; an unmatched SNI fell through to the floor 20/20; delete gave 40/40.
  • UDPRoute: control 20/20 unanswered; delivery 40/40; per-VIP selection 20/20 + 20/20; delete 20/20 unanswered.

The live config_dump from the kind cluster's proxy shows every capture_<pod> listener with use_original_dst: false and envoy.filters.listener.original_dst as the first filter, so the green run really exercised the new config. The cluster was torn down afterwards.

Rollout note

This changes the definition of every per-pod capture listener, so the rollout is a full listener replace plus drain per pod. No charts/ change is needed.

Closes #1007

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…hichever pod bound 0.0.0.0:18008 last (#1007)

The capture listener set use_original_dst: true. In Envoy that field adds two
things: a second copy of the original_dst listener filter (listener_impl.cc
buildOriginalDstListenerFilter), and the restored-destination HANDOFF
(active_tcp_socket.cc): a connection whose restored local address matches
another listener is handed to "the listener bound to that address", found by
the address string alone (connection_handler_impl.cc, no netns). Every pod's
inbound listener binds 0.0.0.0:18008 in its own netns, so a diverted
connection to <endpoint>:18008 ran through the most recently added pod's
inbound chains, which presented that pod's SVID and failed the client's SAN
check.

Nothing in mesh capture needs the handoff: every decision is a filter-chain
match on the restored destination, or the ORIGINAL_DST passthrough, and
original_dst_cluster.cc only needs localAddressRestored(), which the explicit
original_dst LISTENER FILTER (kept, first in the list) sets. The field goes to
false; the comments that claimed it was needed are corrected.

Tests: capture_test and the //test/envoy_validate capture fixture assert the
field is false (the fixture still validates against the pinned proxy); both
went red with the field flipped back to true.

Must merge only after #1022's talos proof: with this alone, a socket leaked
into a pod netns would succeed silently and hide that defect.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo marked this pull request as ready for review September 28, 2026 02:46
@bpalermo
bpalermo merged commit 6ad804b into main Sep 28, 2026
24 checks passed
@bpalermo
bpalermo deleted the fix/1007-capture-no-use-original-dst branch September 28, 2026 02:55
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.

soak: ssl_fail_verify_san ticks on the L4 TLS clusters (tcp-echo, mixed-svc) outside any roll, on every build since at least 2026-09-23

1 participant