Skip to content

UDP per-service routing is impossible behind the CNI REDIRECT — needs TPROXY or a listener per service #916

Closed

Description

@bpalermo

Split out of #873. That issue asked for two things; this is the half that cannot be fixed in the control plane, and #873's suggested direction does not work.

#873 proposed: "Envoy's udp_proxy supports matcher-based route selection (and weighted clusters via the matcher API) in current versions; the comment's premise that it is unavailable predates the version now in use."

Verified against Envoy v1.39.0 source while fixing the other half (#914). Both clauses are wrong.

1. There is no weighted route action for udp_proxy, in any version

UdpProxyConfig.route_specifier is a oneof of cluster (deprecated) and matcher. The matcher's terminal action is udp_proxy.v3.Route — a message with exactly one field, cluster. The action registry is keyed on udp_proxy's private RouteActionContext (router_impl.cc:30) and contains that single action; the HTTP router's weighted route_list lives in a disjoint registry and is unreachable from here.

tcp_proxy.weighted_clusters simply has no udp_proxy counterpart. Switching to the matcher specifier buys nothing today and costs a field still marked work_in_progress in 1.39.

2. Per-service selection is blocked one layer below the control plane

This is the part #873 does not mention, and it is what makes the matcher suggestion moot. Behind the CNI's nftables redirect, the UDP capture listener cannot know which service a datagram was addressed to:

  • A datagram listener's only addressing cmsg is IP_PKTINFO (listener_impl.cc:776-780), so DestinationIPInput reads the post-DNAT header. The ClusterIP is already gone.
  • Envoy never reads IP_RECVORIGDSTADDR / IP_ORIGDSTADDR anywhere in the tree, and original_dst is structurally TCP-only — OriginalDstFilter implements Network::ListenerFilter, not UdpListenerFilter, and LDS hard-rejects it on a UDP listener.
  • DestinationPortInput is not packet-derived at all. The port is stamped from the listening socket's own port (io_socket_handle_impl.cc:258-281), so it is the constant ProxyCapturePort. This one is genuinely counter-intuitive and is worth remembering before anyone designs against it.
  • Only five inputs exist for Network::UdpMatchingData — source/dest IP and port, plus network_namespace (always nullopt here). There is no ServerNameInput and no FilterStateInput.

The TCP path does not have this problem because use_original_dst recovers the pre-REDIRECT address, which is exactly what UDP lacks.

What it would take

Either:

  • TPROXY capture for UDP instead of REDIRECT, preserving the original destination — a CNI change; or
  • a listener per service on its own port, so the listening socket's port identifies the service — also a CNI change, and it multiplies listeners per pod.

Both are data-path changes in cni/internal/plugin/capture.go, not xDS work. Neither should be attempted as a drive-by.

Current behaviour (after #914)

One service wins per pod — the heaviest live backend, ties broken by cluster name for determinism (#135). weight: 0 is honoured as a drain. The discarded shapes are reported, not faked: UnsupportedUDPRouteShapes plus the aether.agent.l4route.udp_unsupported counter, which is now seeded (#882/#905) so its zero is meaningful.

docs/conformance/gateway-api-features.md and docs/getting-started.md now state the limit rather than claiming UDPRoute is simply "Supported".

Note

UDP rides the mesh in plaintext by design — mTLS is a TCP/TLS construct and there is no DTLS here — so none of this is a security regression. It is a routing-expressiveness limit.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Activity

  1. bpalermo commented on Sep 23, 2026

    @bpalermo
    OwnerAuthor

    P0 spike result: GO on the Envoy/kernel question

    Ran the experiment rather than reasoning further. Same Envoy, same udp_proxy matcher (DestinationIPInput exact-match 10.96.99.99 → cluster A, on_no_match → cluster B). Only the nft rule differs:

    capture matcher arm reply to a connected socket
    TPROXY (mark + ip route local) A — saw 10.96.99.99 A:probe, source 10.96.99.99:5300
    REDIRECT (status quo) B — on_no_match B:probe — still works, via conntrack un-DNAT
    TPROXY, dport preserved, listener on a different port neither (0/0) timeout, nothing delivered

    What this settles

    1. transparent: true genuinely binds on a UDP listener — 20 sockets on 0.0.0.0:5300, no rejection.
    2. The original destination survives TPROXY. Envoy's addressFromMessage reads info->ipi_addr — the IP header's daddr — not ipi_spec_dst. TPROXY does not rewrite the header; REDIRECT does. So DestinationIPInput sees the ClusterIP and per-service matching works.
    3. Arm B is reachable, so row 1 is not a vacuous pass. This was the control worth running.
    4. The listener must bind the service port. Preserving the dport but binding elsewhere delivers nothing. That is what forces listener-per-PORT rather than per-service — and distinct UDP service ports are few (53, 161, 514, 8125…), with destination_ip disambiguating services that share one. Much cheaper than the listener-per-service fallback.

    The status quo is worse than this issue states

    REDIRECT produces working traffic with lost routing information, because conntrack un-DNATs the reply. Nothing ever failed visibly, which is why this went unnoticed until #873.

    Design correction from the source review

    sendmsg sets only ipi_spec_dst from the local IP — self_ip->port() is never read — so a reply's source port is always the socket's bound port. A port-rewriting tproxy would therefore give working matching and silently one-way traffic. Preserve the dport and bind the listener on it.

    Caveats, stated rather than buried

    • Ran with Envoy v1.39.1 (local image), not the pinned 1.40.0-dev.20260904.13144fb. (proxy/MODULE.bazel:22 — earlier notes on this issue and UDPRoute ignores backend weights and collapses multiple services onto one cluster #873 said "v1.39.0", which was wrong.) The load-bearing files were diffed byte-identical across v1.39.0, the dev pin, and main.
    • Workstation x86_64 user netns, not Talos arm64.
    • Used mark + local route rather than nft's tproxy statement, because that statement is prerouting-only and aether captures locally-originated traffic inside the pod netns. Arguably more representative of the real path, not less.
    • UdpProxyConfig.matcher is work_in_progress — a warning plus a server.wip_protos counter, not a reject.

    Remaining P0, Talos-only

    ip rule / ip route local persistence across a Talos config re-apply, and the mixed TCP-REDIRECT + UDP-TPROXY ruleset in cni/internal/plugin/capture.go. NET_ADMIN is already granted on the proxy container (agent-proxy-daemonset.yaml:224), so that unknown is closed.

    Proposal 038 to follow once the Talos half is answered.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

  2. bpalermo commented on Sep 26, 2026

    @bpalermo
    OwnerAuthor

    Phase 0 of proposal 038 is settled on a node. The answer is YES, and Phase 1 is unblocked. PR #940.

    Run 2026-09-25 on main-worker-04, kernel 6.18.34-talos.

    C1   in-netns create + read, mark-and-divert   ipi_addr=10.250.0.7   (the VIP)
    C2   REDIRECT, in-netns read                   ipi_addr=127.0.0.1    (rewritten)
    C3   no capture rule                           nothing delivered
    MAIN create in-netns via setns, read outside   ipi_addr=10.250.0.7   (the VIP)
    

    A transparent socket created inside a pod netns via setns and read from another netns does observe the pre-TPROXY destination — which is aether's real shape, since the proxy is hostNetwork and binds capture listeners into each pod's netns via network_namespace_filepath.

    C2 is why MAIN is believable. It proves ipi_addr reports the real post-NAT header rather than echoing the address that was sent; C3 only shows that delivery needs a rule. The 2026-09-23 attempt was unusable precisely because its control agreed with its negative result, and the first run of this script lost C2 the same way — redirect is terminal in nftables, so a trailing counter invalidated the rule and C2 silently became a duplicate of C3 while still passing its own assertion. The rig now aborts rather than measuring with an unverified ruleset.

    Two scope notes so this is not over-read:

    • The rig tests the kernel half, on the socket Envoy would use, rather than standing up Envoy. transparent: true on a datagram socket and Envoy's read of ipi_addr were already established in 038; the open question was the setns interaction, and isolating it kept Envoy's config surface out of the result.
    • It binds the service port, not the capture port. tproxy is prerouting-only so locally-originated egress uses mark-and-divert, which does not rewrite the destination port — a listener on any other port receives nothing. That is the constraint forcing listener-per-port in Phase 2.

    Also worth separating from today's other work: the #931 series (#933–#938) made one UDP service work end to end — it did not touch this issue. #916 is telling two apart, which is still Phase 1 (CNI TPROXY rules, behind a flag) and Phase 2 (one transparent listener per distinct UDP service port, matcher on DestinationIPInput).

    The spike is checked in at e2e/spike/ so it can be re-run rather than taken on trust.

  3. bpalermo commented on Sep 26, 2026

    @bpalermo
    OwnerAuthor

    Reassessment: QUIC changes 038's endgame, and the TCP/UDP capture question with it

    Two things were asked after Phase 0 landed: should TCP and UDP capture be normalized onto TPROXY, and does the recent QUIC mTLS work on Envoy change that. Facts first, then the verdict.

    The QUIC premise, verified

    038 deferred east-west QUIC on a security-model objection: "QUIC brings its own TLS 1.3, which is a different model from the per-source mTLS H2 invariant proposal 031 settled on." That objection is now largely dissolved upstream. A five-PR series in envoyproxy/envoy (facts from the envoy session, PR numbers/dates/SHAs verified against GitHub):

    PR merged what in our pin?
    #45980 2026-07-28 c982e14d3c upstream: an HTTP/3 cluster presents its client cert when asked yes
    #47076 2026-09-03 a954913a99 downstream: require_client_certificate on a QUIC filter chain requests and validates the client cert through the same CertValidator as TCP — trusted_ca, match_typed_subject_alt_names, the SPIFFE validator; identity reaches XFCC, RBAC and access logs yes
    #47219 2026-09-09 4c7a07550d enable_resumption / enable_early_data default off when a client cert is required no
    #47341 2026-09-17 c2eed43cda optional mTLS no
    #45978 2026-09-17 b6a6137a6e peer-cert details (issuer digest, serial, PEM) on QUIC connection info no

    Our pin is 1.40.0-dev.20260904.13144fb — 2026-09-04 — and the envoy bazel-registry publishes exactly one version, so the two load-bearing PRs are already in the binary we ship and there is no later resolvable snapshot as of 2026-09-26.

    The envoy session measured #47076 directly with a quic-go client: trusted cert → 200 with the SPIFFE URI SAN in XFCC; no cert → certificate required; self-signed → unknown CA. SDS works through the same onSecretUpdated path as TCP, so SPIRE-delivered certs and bundles carry over. Connection migration does not re-handshake, so identity persists across a path change the way a TCP connection keeps its identity.

    So QUIC can carry the per-source mTLS identity invariant rather than replacing it. The accurate framing for 038 is: QUIC's TLS 1.3 handshake carries client certificates in Envoy since #47076, validated through the same validation_context as TCP — provided resumption and early data are disabled on the filter chain.

    The one caveat that is a hard requirement at our pin

    QUIC never re-verifies the client certificate on a resumed session — a resumed session carries the identity from the original handshake without touching the trust bundle again. #47219 makes the safe default automatic, but it is not in our snapshot. So until the pin moves past 2026-09-09, every mTLS QUIC filter chain must set enable_resumption: false and enable_early_data: false explicitly, and a validate-gate should assert it. With those set, every connection does a full handshake and the model matches 031's invariant. Without them, an SVID revocation would not take effect on resumed sessions — the exact class of silent identity drift #829 was about.

    Also at our pin: required mode only (optional mTLS is #47341), and none of the extra peer-cert fields.

    What this changes for 038

    QUIC moves from "deferred pending an architecture decision that should not arrive as a side effect of a CNI change" to a planned requirement. The decision that was deferred has been made upstream in the direction that preserves aether's invariant. That in turn changes the normalization question.

    Normalize TCP and UDP capture onto TPROXY?

    Not now, and not for symmetry. Yes, eventually, and QUIC is the reason.

    Why not now:

    • TPROXY solves nothing on the TCP side. TCP already recovers the original destination — envoy.filters.listener.original_dst reads SO_ORIGINAL_DST from conntrack, and passthrough_original_dst is built on it. REDIRECT loses nothing for TCP. The absence of a UDP equivalent (OriginalDstFilter is a Network::ListenerFilter, not a UdpListenerFilter) is the entire motivation for 038.
    • Blast radius is wildly asymmetric. TCP capture carries 100% of mesh traffic with months of soak evidence. UDP capture carries approximately nothing today. TPROXY has zero production hours in this codebase.
    • The mark space collides with loop prevention. redirect-all depends on CapturePassthroughFwMark = 0xae7e: Envoy stamps it via SO_MARK on passthrough_original_dst's upstream sockets, and passthroughMarkAcceptExprs RETURNs on it ahead of the redirect so the proxy's own forwarded egress is never re-captured. TPROXY is also mark-driven (mark → ip rule → ip route local). Two mark mechanisms on one path, where one of them is the only thing preventing an infinite capture loop on all mesh TCP traffic. This is the gating analysis for any TCP move, QUIC or not.
    • Every pod netns would gain ip rule/ip route local plumbing on the critical path, and the CNI has no route/rule capability today (038 Phase 1 adds it plus a dependency).

    Why eventually, and why QUIC decides it: TCP and QUIC sharing a port with two different capture mechanisms underneath is exactly the split that produced this issue in the first place — REDIRECT giving "working traffic with lost routing information", invisible for months because conntrack repaired the reply. With QUIC now a planned requirement rather than a maybe, the mixed state has an expiry date.

    The middle path, which I recommend Phase 1 take

    Normalize the code, not the deployed behaviour. captureRedirectExprs(proto, meshPort, capturePort) is already protocol-parameterised — one builder serves TCP and UDP because the transport dport offset is identical. Phase 1 should extend that to a capture-mode parameter (redirect | tproxy) rather than grow a second parallel rule path. That buys most of the comprehension benefit and makes the eventual TCP switch a flag flip with a tested code path behind it, at zero runtime risk today.

    Sequencing

    1. 038 Phases 1–3 with TPROXY on UDP only, behind the flag. Mistakes cost nothing there.
    2. Soak it. Operational hours on TPROXY in this codebase.
    3. East-west QUIC as its own proposal: UDP inbound listener with a QUIC transport socket, the SDS/SAN-pinning machinery reproduced against it, enable_resumption: false + enable_early_data: false gated in //test/envoy_validate until the pin passes #47219. HTTP/3 exists only at the edge today (BuildEdgeGatewayH3Listener, 029) and never traverses capture; east-west is a different path with no existing code.
    4. Then TCP → TPROXY, with the 0xae7e mark-collision analysis as the gate.

    The two design questions from the previous comment still stand and precede Phase 1: which UDP ports the CNI diverts, and whether the dial spelling leaves :18081.

  4. bpalermo commented on Sep 26, 2026

    @bpalermo
    OwnerAuthor

    Design constraint for the east-west QUIC follow-on, pinned in code: one port number for both transports. PR #942.

    When east-west QUIC lands it binds UDP on DefaultEastWestTunnelPort (18009) beside the TCP tunnel — never a new port. The edge already does exactly this: BuildEdgeGatewayHTTP3Listener binds UDP on the same internalPort as the TCP HTTPS listener with EnableReusePort, and alt-svc advertises that one port. The capture port (ProxyCapturePort) states the same principle.

    A second number would need a second CNI rule, a second Service port, a second cross-cluster "must match" agreement, and a second capture path — and TCP and QUIC on different capture mechanisms is the split that produced this issue.

    Gated by TestEastWestPortIsSharedAcrossTransports, which scans the proxy package's constants and fails on any east-west QUIC/H3/UDP port constant whose value isn't 18009. Green today; red-state proven with a probe constant before commit. So the QUIC proposal cannot quietly allocate 18010 — the test names it.

  5. bpalermo commented on Sep 26, 2026

    @bpalermo
    OwnerAuthor

    038 reassessed with QUIC folded in as a requirement — PR #943. Summary of what changed and where the verdicts landed.

    Shape. It was a proposal to fix plaintext UDP selection with QUIC as a "does NOT deliver" appendix. It is now a proposal for one UDP capture path carrying two traffic classes with different security properties — plaintext per-service UDP (R1) and an identity-bearing QUIC mesh transport under the unchanged 031 invariant (R2). The discriminator is the destination port class: 18008/18009 → QUIC chain with require_client_certificate and the same validation_context as TCP; a declared PORT_PROTOCOL_UDP service port → udp_proxy matcher on destination IP; anything else uncaptured. Separated at the port, before any matcher runs, so the classes cannot bleed (R5).

    Phases. 0 done · 1 CNI mark-and-divert for exactly two port sets, built with a capture-mode parameter (R6) and a divert mark disjoint from 0xae7e · 2 agent per-port transparent listeners · 3 e2e turns delivery into selection, on a floor that only started working on 2026-09-25 · 4 QUIC transport — inbound on UDP:18008 beside TCP:18008, HTTP/3 upstream presenting the source cert, east-west gw on UDP:18009 last, resumption/early-data off and gated (R4) · 5 TCP → TPROXY, gated on the mark analysis and a soak with Phase 4 on.

    Normalization verdict, revised. Was "not now, eventually, QUIC is the reason". Now it has a slot and a gate: Phase 5, after Phase 4 soaks, on a written 0xae7e analysis. Not for symmetry — TCP loses nothing under REDIRECT — but because TCP and QUIC on two capture mechanisms is the split that produced this issue, and R6 makes it a flag flip.

    Flagged rather than decided.

    • D1 the plaintext dial spelling: :18081 today; the design implies the service's application port. Recommendation: adopt it, keep :18081 one release.
    • D2 the divert mark value.
    • Q1 how the CNI learns the declared UDP port set at pod ADD.
    • Q2 — the sharpest — does transport_socket_matches select a QUIC upstream transport the way it selects a TLS one? Decides one cluster vs one per source in Phase 4.
    • Q3 does the per-source binding (keyed by SPIFFE ID since fix(agent): key the per-source mTLS matcher by source SPIFFE ID, not netns path (#815, release 2/3) #822) survive a QUIC path migration? Expected yes; verify in Phase 4 e2e.
    • Q4 when the Envoy pin can move past #47219/#47341.

    "Do nothing" downgraded. It was legitimate on 09-23. #931 showed the plaintext path had been silently broken for its whole life, and QUIC mTLS is now in the pinned binary — the cost of not acting is no longer just a documented limit.

    D1 and D2 need a call before Phase 1 writes nft rules.

  6. bpalermo commented on Sep 26, 2026

    @bpalermo
    OwnerAuthor

    D1 decided: plaintext UDP dials :18082, the L4 spelling shared with raw TCP. Folded into #943 as a second commit.

    Applying the one-number-both-transports rule one level down. A client dials <svc>.<ns>.<mesh-domain>:18082 for a UDP service exactly as for a raw-TCP one; only the transport differs. R3 now reads:

    role number TCP UDP
    L4 mesh spelling 18082 raw TCP floor (037) plaintext UDP services
    per-pod inbound 18008 mTLS H2 QUIC, mTLS
    east-west gateway 18009 mTLS SNI tunnel QUIC, mTLS

    This is more than a naming decision — it simplifies the design:

    • Phase 2 collapses from "one listener per distinct UDP service port" to one transparent listener on UDP:18082 per pod. Listener count no longer scales with services or ports.
    • Phase 1's rule set is three literals (18082, 18008, 18009). No declared-port-set plumbing.
    • Q1 dissolves. The CNI never needs to know which application ports UDP services bind — UDPLoadAssignment already rewrites the udp: cluster to the app port, which is exactly how tcp: clusters reach a raw-TCP backend from the shared :18082 today.

    It is the TCP floor's shape under 037, transport for transport. :18081/udp stays captured for one release. The east-west port gate (#942) extends to 18082 in Phase 1 and 18008 in Phase 4; ProxyTCPOutboundPort's name and the CNI's "18082 is a TCP spelling" comment go stale and Phase 1 corrects them.

    Still open: D2 (the divert mark value) and Q2 (does transport_socket_matches select a QUIC upstream transport — one cluster vs one per source in Phase 4).

  7. bpalermo commented on Sep 26, 2026

    @bpalermo
    OwnerAuthor

    Q2 answered from source: Q2a = no, Q2b = yes. Phase 4b is one QUIC cluster per source ServiceAccount. Folded into #943.

    Facts from the envoy session, the decisive line verified against quic_client_transport_socket_factory.cc at our pinned 13144fb:

    • Q2a — no. QuicClientTransportSocketFactory::create rejects a certificate selector at config load (lines 93–94: UnimplementedError("Client certificate selector not supported on QUIC")). Loud, not silent. The client cert is installed once per crypto config on the shared QUICHE SSL_CTX via SSL_CTX_set_chain_and_key (line 80), because the QUICHE handshaker needs direct access to the private key. It changes only when SDS rotates the context.
    • Q2b — yes. The HTTP pool key is protocol-agnostic (ClusterEntry::httpConnPool → transportSocketFactory().hashKey), and the QUIC factory inherits CommonUpstreamTransportSocketFactory::hashKey, which folds hashable filter state. HTTP/3 pools partition per (host, source identity) exactly as h2 pools do.

    Net. Pooling does not reopen #831 — two identities never share a QUIC connection. But partitioning alone does not give per-source identity, because the certificate presented is the cluster's regardless of partition. So Phase 4b's outbound is one QUIC cluster per source ServiceAccount — the pre-#842 shape, for QUIC only. The identity-set re-push cost #842 removed returns for those clusters only: bounded by local ServiceAccounts, not mesh services, and never touching the TCP clusters. //test/mtlspool still gains a QUIC arm, because the pooling guarantee is real even though the cert is per cluster.

    D3 (new, Bruno's call): whether to pursue a per-connection client-certificate selector for QUIC upstream in envoyproxy/envoy — running the selector before the chain is installed on a per-connection SSL instead of the shared SSL_CTX. Unsized. If landed, Phase 4b collapses back to one cluster and #842's invariance returns for QUIC. The plan does not depend on it; per-source clusters are correct meanwhile. Recorded so the per-source shape reads as a workaround with a known exit, not a design.

    With this the ADR has no open contingencies: D1 and D2 decided, Q1 dissolved, Q2 answered, Q3/Q4 are verification items inside Phase 4. Only D3 is open, and it is optional.

  8. bpalermo commented on Sep 26, 2026

    @bpalermo
    OwnerAuthor

    Delivered by the TPROXY ladder (#944–#949), which took the first of the two directions this issue named: the CNI now marks and diverts UDP to a transparent listener on :18082 that keeps the original destination (VIP) intact, and GenerateUDPCaptureListener builds one udp_proxy matcher arm per UDPRoute-parent ClusterIP (DestinationIPInput → that service's udp: cluster). Per-service UDP routing is proven by e2e/l4routes.sh T3.3 (two parents, per-VIP selection, #948) and by the rev239 8h soak's UDP leg (2026-09-26).

    What remains is the other half this issue already called an Envoy limit: udp_proxy has no weighted route action, so a UDPRoute with multiple weighted backends still collapses to one cluster. That is surfaced by #874's udp_unsupported counter/log rather than hidden, and it is an upstream feature request if it ever matters, not an aether issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions