Skip to content

feat(038): TPROXY-style capture for TCP and UDP — CNI divert + per-VIP UDP listener on 18082 - #947

Merged
bpalermo merged 1 commit into
mainfrom
feat/tproxy-pr3-divert
Sep 26, 2026
Merged

bpalermo merged 1 commit into
mainfrom
feat/tproxy-pr3-divert

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

PR 3 of the TPROXY plan (after #944 spike, #945 constants, #946 transparent TCP listener). Breaking change, by decision: the nat REDIRECT of 018/022 is gone; no compat flag, no deprecation window.

What

CNI — one table aether_capture, two chains, both transports, plus the policy-routing pair (ip rule fwmark 0xae71 lookup 100, ip route local 0/0 dev lo table 100), all inside the pod netns and gone with it:

output (type route, hook output, priority mangle)
  meta mark 0xae7e accept
  ct direction reply accept              ← THE load-bearing rule
  ip daddr 127/8 | 169.254/16 | 224/4 accept
  tcp dport 53 accept / udp dport 53 accept
  [tcp|udp dport <excluded> accept]      ← per-pod excludes now cover UDP
  [ip daddr <excluded range> accept]
  udp dport 18082 mark set 0xae71
  tcp dport {18081,18082} mark set 0xae71
  meta l4proto tcp mark set 0xae71       ← redirect-all only
divert (type filter, hook prerouting, priority mangle)
  iif lo meta mark 0xae71 tcp tproxy to :18001 accept
  iif lo meta mark 0xae71 udp accept

ct direction reply accept: a route chain sees every locally-generated packet, including the pod's own server replies. Under redirect-all those would be marked, looped to lo, tproxy'd onto the :18001 LISTEN socket and reset — every inbound connection to every pod dies. ct state established is not a substitute (it would also exempt the 2nd+ packets of the pod's own captured outbound flows). vishvananda/netlink is a new direct dep; the rule is built with netlink.NewRule() on purpose (a struct literal sends FRA_SUPPRESS_PREFIXLEN=0 and the divert silently does nothing).

Agent — the UDP capture listener binds 18082 (ProxyL4OutboundPort: Envoy replies from the bound port, so it must be the port the client dialled; the divert has no UDP port rewrite), is transparent, and carries a udp_proxy matcher on DestinationIPInput with one arm per UDPRoute parent ClusterIP → that route's heaviest live backend. #873's one-cluster-per-node limit is gone: a second service is a second arm. VIPs are joined from the capture reconciler's Service list (the same source the TCP floor chains match on); the per-push reconcile compares the canonical arm set, so a late VIP or a second service is seen. SelectedUDPCluster removed.

Signal — aether.cni.operations{operation="capture_divert",result="error"} when the table is rejected; a pod running uncaptured used to be a log line only.

Gates — each seen red

gate red state
TestDivertRuleOrder ct rule removed → "missing"; ct rule after the marks → "accept after a mark rule is dead code"
TestDivertPreroutingRules UDP tproxy'd to 18001 → 9 exprs not 7
TestUDPCaptureListenerResolvesAgainstCDS routable filter disabled → arm names the ghost cluster
envoy_validate TestCaptureUDPListenerIsConnectionless parent B's arm dropped → "1 arm(s), want 2"
envoy --mode validate (pinned proxy) accepts the matcher listener
//cni/internal/plugin:capture_netns_test (requires-root, new netns CI job) see below

The kernel gate creates two netnses + a veth, programs the real ruleset, and drives sockets: T1 tcp→VIP:8080 accepted on the transparent :18001 with local addr VIP:8080; U1 udp→VIP:18082 received with pktinfo dst = VIP and the VIP-sourced reply delivered to a connected client; T2 :53 and X1 the excluded port not diverted; S1 an inbound connection from the peer netns succeeds, then the ct rule is deleted and the same connection must fail. 3/3 PASS on 6.8 via unshare -Urn --map-root-user (no sudo needed locally; recipe in the BUILD file). The CI job greps the PASS line so a skip cannot pass it.

Local: 112/112, --config=race clean on plugin/cache/proxy, lint clean with fail_on_violation, make deps-audit OK.

Not in this PR

  • e2e/l4routes.sh still dials 18081/udp — PR 4 (that suite is nightly-only, so per-PR CI is unaffected).
  • Chart bump, talos deploy, rollout restart, soak UDP workload, 8h soak — PR 5.
  • Pods created before this CNI keep REDIRECT until recreated: TCP is dual-mode on one listener (SO_ORIGINAL_DST gives the same answer), UDP moves outright — nothing on talos-main uses it today.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…P UDP listener on 18082

One mechanism, both transports, breaking change (no compat flags): the nat
REDIRECT of proposals 018/022 is replaced by mark-and-divert with the IP header
left intact, so the proxy sees the ORIGINAL destination on every captured flow.

CNI (cni/internal/plugin/capture.go, one table `aether_capture`):
  output  (type route, hook output, priority mangle)
    meta mark 0xae7e accept · ct direction reply accept · 127/8 · 169.254/16 ·
    224/4 · tcp/udp dport 53 accept · per-pod excludes on BOTH transports ·
    exclude ranges · udp dport 18082 / tcp dport {18081,18082} mark set 0xae71 ·
    [redirect-all] meta l4proto tcp mark set 0xae71
  divert  (type filter, hook prerouting, priority mangle)
    iif lo mark 0xae71 tcp  tproxy to :18001 accept
    iif lo mark 0xae71 udp  accept
  + ip rule fwmark 0xae71 lookup 100 · ip route local 0/0 dev lo table 100
  (vishvananda/netlink, new direct dep; netlink.NewRule() to dodge the
  FRA_SUPPRESS_PREFIXLEN=0 zero-value trap; RouteReplace, EEXIST tolerated).

`ct direction reply accept` is the load-bearing rule: a route chain sees every
locally-generated packet including the pod's own server replies, and under
redirect-all those would be marked, looped to lo, tproxy'd onto the 18001
LISTEN socket and reset — every inbound connection to every pod. `ct state
established` is NOT a substitute (it would exempt the 2nd+ packets of the pod's
own captured outbound flows). TestDivertRuleOrder pins the order; the netns
gate DELETES the rule mid-test and requires the inbound connection to fail.

Agent: the UDP capture listener binds ProxyL4OutboundPort (18082 — Envoy
replies from the bound port, so it must be the port the client dialled; the
divert has no UDP port rewrite), `transparent: true`, and a udp_proxy MATCHER
on DestinationIPInput with one arm per UDPRoute parent ClusterIP → that route's
heaviest live backend. The one-cluster-per-node limit of #873 is gone; a
second service is an ordinary second arm. ClusterIPs are joined from the same
capture-reconciler list the TCP floor chains match on; the per-push reconcile
compares the canonical arm set (UDPCaptureArmsKey) instead of one string, so a
late VIP or a second service is seen. SelectedUDPCluster removed.

Signals: aether.cni.operations{operation="capture_divert",result="error"} when
the table is rejected (a pod running UNCAPTURED was previously a log line only).

Gates, each seen red: TestDivertRuleOrder (ct rule removed; ct rule after the
marks), TestDivertPreroutingRules (udp tproxy'd), TestUDPCaptureListener
ResolvesAgainstCDS (routable filter disabled → arm names an absent cluster),
envoy_validate TestCaptureUDPListenerIsConnectionless (parent B's arm dropped
→ "1 arm(s), want 2"); `envoy --mode validate` on the pinned proxy accepts the
matcher listener. Kernel gate: //cni/internal/plugin:capture_netns_test
(requires-root; new `netns` CI job builds it and runs it under sudo, anti-vacuity
grep on the PASS line) — T1 tcp diverted with local addr VIP:8080, U1 udp
diverted with pktinfo VIP and the VIP-sourced reply received by a connected
client, T2 :53 and X1 excluded port not diverted, S1 inbound reply exempt AND
fails once the ct rule is deleted. 3/3 PASS on 6.8 via `unshare -Urn`.

Not here: e2e/l4routes.sh still dials 18081/udp (PR 4, nightly-only); chart
bump + talos deploy + soak (PR 5). Pods created before this CNI keep REDIRECT
until recreated (TCP is dual-mode on one listener; UDP moves outright).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 8db8d7d into main Sep 26, 2026
24 checks passed
@bpalermo
bpalermo deleted the feat/tproxy-pr3-divert branch September 26, 2026 10:42
bpalermo added a commit that referenced this pull request Sep 26, 2026
… (038 PR 4) (#948)

The UDP leg dials ProxyL4OutboundPort (18082) -- the L4 mesh spelling plaintext
UDP now shares with raw TCP -- instead of 18081, and gains a SECOND UDPRoute
parent (l4udp-front2 -> l4udp-c) beside the first so T3.3 can assert what the
transparent capture in #947 made possible: one listener, one udp_proxy matcher
arm per dialled ClusterIP. T3.0 and T3.2 cover both VIPs. The header comment,
dump_state selectors and the T3.1 failure text describe the divert rather than
the REDIRECT it replaced.

Three runs on kind, each labelled for what it can and cannot show:

  * OLD build (pre-#947 images), new script: TCP and TLS legs green (the
    regression net for TCP-under-TPROXY), T3.0 green, T3.1 RED with
    NOREPLY=10 -- red because 18082/udp is uncaptured by the REDIRECT CNI, NOT
    because the second service is dropped.
  * NEW build: green end to end -- T3.1 40/40 alpha, T3.3 20/20 to front by
    l4udp-a AND 20/20 to front2 by l4udp-c, T3.2 20/20 unanswered again.
  * NEW build with ONE arm removed in the agent (selectUDPCaptureArms keeps
    the first service only): T3.3 RED -- "l4udp-front2 was never answered by
    l4udp-c: NOREPLY=10 ... the pre-038 shape". The selection assertion can
    fail on its own, not only via an uncaptured port.

Docs: getting-started (UDPRoute dials :18082; the one-service-per-pod limit is
gone, the split limit stays), workload-requirements (the L4 spelling table
gains the UDP row; ":18082 does not require redirect-all" now says both
transports and that UDP has no any-port capture), configuration
(exclude-outbound-ports covers TCP+UDP).


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

Co-authored-by: Claude Fable 5.1 <[email protected]>
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]>
bpalermo added a commit that referenced this pull request Sep 26, 2026
…#950)

The CNI plugin binary is exec'd by the container runtime on the HOST, under
the host's resolver, which cannot resolve cluster Service names on Talos (or
kind). Every flush failed with "name resolver error: produced zero addresses"
and no aether_cni_* series ever existed in Prometheus -- including the
capture_divert error counter (#947), the only non-log signal of a pod that
started uncaptured.

cni-install runs in the agent pod (dnsPolicy ClusterFirstWithHostNet), so it
resolves the endpoint's host through cluster DNS and writes "<ClusterIP>:port"
into the netconf (--otlp-pin-endpoint, default true). Addresses, empty
endpoints and names that fail to resolve are written unchanged (the pre-#950
behaviour). Multiple answers pin deterministically (lowest, IPv4 first). The
transport is unchanged: plaintext OTLP gRPC, so no TLS server name to keep.

Chart 0.95.1: cniInstall.pinOTLPEndpoint (default true) and
cniInstall.otlpEndpoint (overrides otel.endpoint for the CNI alone). Flush
failures are logged at WARN instead of DEBUG.

Gates: install_test (pin + netconf render), cmd_test (flag default),
aether_cni_otlp_{pin,override}_test (chart argv), and e2e/uds.sh assertion f:
an OTLP collector at otel-collector.o11y.svc.cluster.local must receive
aether.cni.operations after a pod ADD on kind, whose node resolver cannot
resolve cluster names either.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
bpalermo added a commit that referenced this pull request Sep 26, 2026
…ost-resolver plugin can export (#950) (#969)

* fix(cni): pin the plugin's OTLP endpoint to the collector's ClusterIP (#950)

The CNI plugin binary is exec'd by the container runtime on the HOST, under
the host's resolver, which cannot resolve cluster Service names on Talos (or
kind). Every flush failed with "name resolver error: produced zero addresses"
and no aether_cni_* series ever existed in Prometheus -- including the
capture_divert error counter (#947), the only non-log signal of a pod that
started uncaptured.

cni-install runs in the agent pod (dnsPolicy ClusterFirstWithHostNet), so it
resolves the endpoint's host through cluster DNS and writes "<ClusterIP>:port"
into the netconf (--otlp-pin-endpoint, default true). Addresses, empty
endpoints and names that fail to resolve are written unchanged (the pre-#950
behaviour). Multiple answers pin deterministically (lowest, IPv4 first). The
transport is unchanged: plaintext OTLP gRPC, so no TLS server name to keep.

Chart 0.95.1: cniInstall.pinOTLPEndpoint (default true) and
cniInstall.otlpEndpoint (overrides otel.endpoint for the CNI alone). Flush
failures are logged at WARN instead of DEBUG.

Gates: install_test (pin + netconf render), cmd_test (flag default),
aether_cni_otlp_{pin,override}_test (chart argv), and e2e/uds.sh assertion f:
an OTLP collector at otel-collector.o11y.svc.cluster.local must receive
aether.cni.operations after a pod ADD on kind, whose node resolver cannot
resolve cluster names either.

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

* e2e(uds): the telemetry gate must not pipe kubectl logs into grep -q (pipefail SIGPIPE false negative)

The first kind run of assertion f stayed red for 60s while the collector's
debug log already carried aether.cni.operations: under set -o pipefail,
grep -q's early exit SIGPIPEs kubectl logs and the pipeline reports failure
(rc 141) even though the metric matched. Grep a captured string instead.
Seen: rc=141 on the exact pipeline against the live cluster; green after.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
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.

1 participant