Skip to content

test(spike): TPROXY Phase 0b — full ruleset, both transports, proven on a node - #944

Merged
bpalermo merged 2 commits into
mainfrom
feat/tproxy-phase0b-spike
Sep 26, 2026
Merged

bpalermo merged 2 commits into
mainfrom
feat/tproxy-phase0b-spike

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

PR 0 of the TPROXY plan. The gate for the CNI change: PR 3 will be written against this exact ruleset, which has now run on a Talos kernel. Refs #916.

What Phase 0 had not established

Phase 0 proved a transparent UDP socket created inside a pod netns via setns and read from outside sees the pre-divert destination. It never installed a prerouting tproxy rule (so never proved nft_tproxy loads on 6.18.34-talos), never ran TCP, never sent a reply, and never exercised the one rule that keeps the design from breaking every pod.

Result — main-worker-04, first run, exit 0

T1  TCP -> VIP:8080, ONE transparent listener on 18001
      accepted, getsockname() = 10.250.0.7:8080, client got the reply
      SO_ORIGINAL_DST on that socket = 10.250.0.7:8080
T2  TCP -> VIP:53          not captured; client timed out
U1  UDP -> VIP:18082       ipi_addr = VIP; reply sent FROM VIP:18082 reached a CONNECTED client
S1  inbound over a veth, redirect-all ON
      with    ct direction reply accept   ECHO=inbound   SERVED
      without ct direction reply accept   client TimeoutError, server TimeoutError   <- red state

Why S1 is the arm that matters

A type route chain sees every locally-generated packet. Under redirect-all that includes the pod's own server replies to inbound clients — a SYN-ACK whose dport is the client's ephemeral port. Without ct direction reply accept it is marked, looped to lo, tproxy'd to the 18001 LISTEN socket, and answered with a reset: every inbound connection to every redirect-all pod dies. This was the adversarial review's critical finding against the first draft, and S1 is run twice so the rule's absence is seen to break something — a run where S1 passes without the rule exits 2 (rig broken), not 0.

ct state established,related accept is not a substitute: in a route chain it would also exempt the 2nd+ packets of the pod's own captured outbound flows, routing them out eth0 mid-connection.

Two facts from T1 worth keeping

  • TCP keeps one listener. tproxy to :18001 looks the socket up by target port with the header intact; the accepted socket's local endpoint is VIP:8080 and the reply is correct with no conntrack NAT. Delivery-port rewrite is fine for TCP and not for UDP (reply source port = bound port), which is why U1 binds the dialed port.
  • SO_ORIGINAL_DST succeeds on a diverted flow — tracked but un-NATed, getorigdst returns the original destination, the same answer getsockname gives. Envoy's original_dst takes its normal branch; the IP_TRANSPARENT fallback is a backstop.

Shape

Same as Phase 0: aether-system (already PodSecurity privileged), NET_ADMIN + SYS_ADMIN, no host namespaces, no privileged: true. Setup failures raise, the ruleset is verified with nft list ruleset before measuring, and a control that does not discriminate is a broken rig. Cluster resources cleaned up after the run.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits September 26, 2026 06:47
…a node

Phase 0 proved one thing: a transparent UDP socket created inside a pod netns
via setns and read from outside sees the pre-divert destination. It never
installed a prerouting `tproxy` rule, never ran TCP, never sent a reply, and
never exercised the rule that keeps the design from breaking every pod. This
does all four with the exact ruleset the CNI will program.

Arms: T1 TCP to VIP:8080 lands on ONE transparent listener on 18001 with
getsockname() == VIP:8080 and the reply (src VIP) returns; T2 TCP :53 is not
diverted; U1 a UDP reply sent from VIP:18082 via IP_PKTINFO spec_dst reaches a
CONNECTED client; S1 an inbound connection from a peer netns over a veth to a
plain server in the pod netns, run twice -- WITH `ct direction reply accept`
(must connect) and with it REMOVED (must fail). Under redirect-all the server's
SYN-ACK is locally-generated TCP with dport = the client's ephemeral port; without
that rule it is marked, looped to lo, tproxy'd to the 18001 LISTEN socket and
answered with a reset. A run where S1 passes without the rule is a broken rig,
not a pass.

Exit 0 = every arm as designed incl. S1's red state; 1 = the design fails on
this kernel; 2 = rig broken (a control did not run or did not discriminate,
including nft rejecting the table because nft_tproxy is unavailable).

Same Job shape as Phase 0: NET_ADMIN + SYS_ADMIN, no host namespaces.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
… state proven

main-worker-04, 6.18.34-talos, first run, exit 0. T1 one transparent TCP
listener on 18001 sees VIP:8080 and replies (SO_ORIGINAL_DST = 10.250.0.7:8080,
so Envoy's original_dst takes its normal branch on a diverted flow); T2 :53 not
diverted; U1 UDP reply from VIP:18082 reaches a connected client; S1 inbound
replies survive with `ct direction reply accept` and BOTH ends time out without
it. nft_tproxy loads on this kernel. PR 3 is written against this ruleset.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.IPPROTO_IP, IP_TRANSPARENT, 1)
s.bind(("0.0.0.0", CAPTURE_PORT))
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.IPPROTO_IP, IP_TRANSPARENT, 1)
s.setsockopt(socket.IPPROTO_IP, socket.IP_PKTINFO, 1)
s.bind(("0.0.0.0", UDP_PORT))
@bpalermo
bpalermo merged commit 95788da into main Sep 26, 2026
23 checks passed
@bpalermo
bpalermo deleted the feat/tproxy-phase0b-spike branch September 26, 2026 09:54
bpalermo added a commit that referenced this pull request Sep 26, 2026
…UDP leg (#949)

Chart 0.93.3 -> 0.94.0: #947 changed what every managed pod's CNI programs
(mark-and-divert for both transports, no REDIRECT) and where plaintext UDP is
served (18082, transparent, per-VIP matcher). A breaking data-plane change
takes a minor bump; the deploy notes are in the PR.

e2e/soak/udp.yaml: the first continuous UDP client on talos-main -- `udp-echo`
(UDP-primary, socat RECVFROM echo, 3 replicas spread, a self-parented
UDPRoute) and the `udp-dialer` DaemonSet dialling
udp-echo.<ns>.aether.internal:18082 from every node with a unique token per
datagram, reporting AETHER_METRIC udp_dialer={cycles,ok,fail}. The echo answers
a CONNECTED nc client from the dialled port, verified locally as non-root with
a read-only root. README: run step, grading subsection (dialer tallies, the
udp.capture_udp_* rx/tx series, udp_no_healthy_backend, and the CNI's
capture_divert error counter that must stay at zero), files entry.

docs/proposals/038: status note recording that Phases 1, 2 and 5 were
superseded by the both-transports plan and shipped as #944-#948 with no mode
flag; Phases 3 and 4 stand.


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

Co-authored-by: Claude Fable 5.1 <[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.

2 participants