Skip to content

docs(proposal): TPROXY capture for UDP (038) - #923

Merged
bpalermo merged 1 commit into
mainfrom
docs/038-udp-tproxy
Sep 23, 2026
Merged

bpalermo merged 1 commit into
mainfrom
docs/038-udp-tproxy

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Refs #916, #873.

Why this exists

A pod may have at most one UDP service routed to it. #914 made that choice principled — heaviest live backend, weight: 0 honoured as drain, discarded shapes counted rather than silently dropped — but the limit itself is unchanged, and it is not fixable in the control plane.

The capture path destroys the information needed to tell services apart. TCP recovers the pre-DNAT destination via use_original_dst; UDP has no equivalent. Envoy never reads IP_RECVORIGDSTADDR, original_dst is structurally TCP-only, DestinationPortInput is the listening socket's port, and none of the five UdpMatchingData inputs can distinguish two services behind a REDIRECT.

So #873's stated fix direction is wrong on both halves, and the proposal says so: udp_proxy has no weighted route action in any version (the matcher's terminal action is a message with exactly one field, cluster), and adopting matcher buys nothing while its input carries no service identity.

Verified before writing, not asserted

Run in a network namespace with no aether code. Same Envoy, same matcher, only the nftables rule differing:

capture matcher arm reply to a connected socket
TPROXY A — saw the ClusterIP delivered, source <ClusterIP>:<service port>
REDIRECT B — on_no_match delivered, via conntrack un-DNAT
TPROXY, listener off the service port neither (0/0) nothing delivered

Row 2 is the control that makes row 1 meaningful — arm B is reachable, so arm A wasn't a matcher that always picks its first branch. It also explains why this went unnoticed: REDIRECT gives working traffic with lost routing, because conntrack repairs the reply.

Row 3 forces the design. sendmsg never reads self_ip->port(), so a reply's source port is always the bound port and a connected client drops anything else — a port-rewriting TPROXY would produce matching that works and traffic that silently fails one way. Hence: preserve the dport, one transparent listener per distinct UDP service port, destination_ip disambiguating within it. Cheaper than listener-per-service, which was the obvious fallback.

What is NOT established

aether binds capture listeners into the pod netns via network_namespace_filepath (hostNetwork: true proxy). The spike could not settle whether a transparent listener bound that way sees the ClusterIP: in-netns gave arm A reproducibly, via-filepath gave arm B — but so did the control, i.e. the in-netns shape that reliably gives A elsewhere. Two rigs disagreeing on one config means the rig is at fault and neither reading is usable. A rootless user namespace cannot host the test (setns() back needs CAP_SYS_ADMIN in the original netns's user ns).

Phase 0 exists to settle exactly that, on a node. If it says no, the proposal stops and #916 stands as a documented limit — a legitimate outcome, and far cheaper than discovering it in Phase 2.

Corrections this records

Scope discipline

It does not deliver east-west QUIC, and Phase 0 passing should not be read as QUIC being approved. TPROXY is necessary for it — HTTP/3 today is edge-only and never traverses capture — but QUIC also needs a security-model decision (UDP rides the mesh in plaintext; QUIC brings its own TLS 1.3, which differs from proposal 031's per-source mTLS H2 invariant). That shouldn't arrive as a side effect of a CNI change.

Alternatives considered records the three rejected designs with reasons, including do nothing, which remains legitimate.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

A pod may have at most one UDP service routed to it. #914 made that choice
principled — heaviest live backend, weight:0 honoured as drain, the discarded
shapes counted rather than dropped — but the limit itself is unchanged, and it
is not fixable in the control plane.

The cause is that the capture path destroys the information needed to tell one
service from another. TCP recovers the pre-DNAT destination via
use_original_dst; UDP has no equivalent. Envoy never reads IP_RECVORIGDSTADDR,
original_dst is structurally TCP-only, DestinationPortInput is the listening
socket's own port, and the five UdpMatchingData inputs cannot distinguish two
services behind a REDIRECT.

So #873's suggested fix does not work on either half: udp_proxy has no weighted
route action in any version (its matcher's terminal action has exactly one
field, `cluster`), and switching to `matcher` buys nothing while the input
carries no service identity.

This proposes TPROXY instead, which leaves the IP header intact so ipi_addr
still carries the ClusterIP.

Three of four premises were verified by experiment before writing this, in a
netns with no aether code:

  TPROXY   -> matcher arm A (saw the ClusterIP), reply delivered
  REDIRECT -> matcher arm B, reply delivered VIA CONNTRACK UN-DNAT
  TPROXY with the listener off the service port -> nothing delivered

The REDIRECT row is the control that makes the first row mean something, and it
also explains why this was never noticed: REDIRECT produces working traffic with
lost routing information, because conntrack repairs the reply.

The third row forces the design. Envoy's sendmsg never reads self_ip->port(), so
a reply's source port is always the bound port, and a connected UDP client drops
anything else — a port-rewriting TPROXY would give matching that works and
traffic that silently fails one way. Hence: preserve the dport, one transparent
listener per distinct UDP service port, destination_ip disambiguating within it.

The fourth premise is NOT established and Phase 0 exists to settle it: aether
binds capture listeners INTO the pod netns via network_namespace_filepath, and
the spike could not test that — the rig gave contradictory results for the same
nominal config, so neither reading is usable, and a rootless user namespace
cannot host the test at all. If Phase 0 says no, the proposal stops and #916
stands as a documented limit.

Also recorded: the Talos-host persistence risk flagged earlier is superseded.
The rules live in the POD netns, created at pod setup and dying with it, so
machine config never touches them.

Refs #916, #873

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 2acc275 into main Sep 23, 2026
23 checks passed
@bpalermo
bpalermo deleted the docs/038-udp-tproxy branch September 23, 2026 23:43
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