Skip to content

feat(agent): TCPRoute/TLSRoute/UDPRoute L4 routing (proposal 018, Phase 3b) - #296

Merged
bpalermo merged 1 commit into
mainfrom
feat/l4-routes-phase3b
Jun 24, 2026
Merged

bpalermo merged 1 commit into
mainfrom
feat/l4-routes-phase3b

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Summary

  • TCPRoute (parentRef=Service): replaces the passthrough TCP floor chain with tcp_proxy.weighted_clusters. All backends across rules are deduplicated and their weights summed. Single-backend case uses the cheaper TcpProxy_Cluster form.
  • TLSRoute (parentRef=Service): adds per-SNI filter_chain_match.server_names filter chains on the capture listener, inserted before the per-ClusterIP floor chain (tls_inspector already in place). Each rule's SNI set becomes one chain. ClusterIP/32 is also included in the match to prevent cross-service SNI contamination.
  • UDPRoute (parentRef=Service): control-plane side only — generates a per-pod UDP listener + udp_proxy. The CNI UDP redirect is NOT wired: the nftables rule in cni/internal/plugin/capture.go only redirects TCP. The listener appears in the snapshot but receives no traffic. Follow-up CNI PR needed before this is live. This is explicitly documented in GenerateUDPCaptureListener.

Architecture

Gate: --l4-routes (default off, independent of --gamma). Requires --transparent-capture to be meaningful.

Route types live in gateway-api v1alpha2 (TCPRoute/TLSRoute/UDPRoute are not yet promoted to v1 in gateway-api v1.5.1). The gatewayv1alpha2.Install(scheme) call registers them.

Filter chain order on the capture listener (most-specific first):

  1. TLSRoute SNI chains: server_names + prefix_ranges=/32 (proposal 018 Phase 3b)
  2. TCPRoute/passthrough floor chain: prefix_ranges=/32 only (Phase 3a/3b)
  3. HCM catch-all: no criteria (HTTP/gRPC)

Backend services from L4 routes are unioned into the dependency set so their EDS clusters generate.

Edge path

TCPRoute/TLSRoute parentRef=Gateway (edge) is a follow-up — scoped out here.

New files

File Role
agent/internal/xds/proxy/l4route.go L4 route types + Envoy config builders (weighted tcp_proxy, TLS SNI chains, UDP listener)
agent/internal/xds/proxy/l4route_test.go 11 unit tests covering weighted routing, SNI chains, UDP, edge cases
agent/internal/l4route/reconciler.go Controller: watches TCPRoute/TLSRoute/UDPRoute, projects to cache
agent/internal/l4route/reconciler_test.go 7 unit tests covering parentRef filtering, weight defaults, SNI propagation
agent/internal/xds/cache/l4route.go Cache side: SetTCPServiceRoutes/SetTLSServiceRoutes/SetUDPServiceRoutes + equality helpers

Test plan

  • bazel build //agent/... clean
  • bazel test //agent/... — 20/20 pass (including proxy_test, l4route_test, cache_test)
  • bazel test //charts/... — 6/6 pass (chart lint + template tests)
  • bazel build --config=lint //agent/... clean
  • make format — no drift
  • e2e on talos-main (coordinate with parent after merge)

Open risks for e2e

  1. UDPRoute CNI gap: UDP listener generates but is unreachable until a follow-up CNI PR adds the UDP nftables redirect. No traffic impact; the listener just sits idle.
  2. Filter-chain precedence for TLSRoute: the SNI match requires the tls_inspector to have read the ClientHello before Envoy selects the chain. This is the documented listener_filter_timeout path — if the TLS ClientHello is fragmented, there can be a brief delay. Not new; the tls_inspector was already in the Phase 3a listener.
  3. Edge path not implemented: TCPRoute/TLSRoute parentRef=Gateway still routes only via HTTP/RDS on the edge. Filed as follow-up.
  4. gatewayv1alpha2.Install idempotency: if --gamma and --l4-routes are both set, gatewayv1.Install and gatewayv1alpha2.Install are called once each. The scheme registration is idempotent so there is no conflict, but the two calls are independent.

🤖 Generated with Claude Code

https://claude.ai/code/session_01N7oY7W8oDXrqDzFgoZh25S

…se 3b)

Add Gateway API L4 route types (parentRef=Service, GAMMA east-west) to the
capture listener's TCP floor:

- TCPRoute: per-service weighted_clusters tcp_proxy replaces the passthrough
  floor chain when a TCPRoute attaches to a Service. Multiple rules/backends
  are flattened into a deduplicated weighted cluster list.

- TLSRoute: per-SNI filter chains (filter_chain_match.server_names) are
  inserted before the per-ClusterIP TCP floor chain on the capture listener.
  The tls_inspector already present reads SNI; no TLS termination — mesh mTLS
  stays intact. Chains are also scoped to the service ClusterIP/32 to prevent
  SNI cross-contamination between services.

- UDPRoute: control-plane side (Envoy udp_proxy listener per pod) is
  implemented; the CNI UDP redirect is explicitly NOT wired. The nftables
  rule in cni/internal/plugin/capture.go only covers TCP. The listener is
  generated in the snapshot but receives no traffic until a follow-up CNI
  change adds: `meta l4proto udp; udp dport <meshPort>; redirect to :<udpCapturePort>`.

All three route types are gated behind --l4-routes (default off, separable from
--gamma which owns L7). Requires gateway-api v1alpha2 CRDs (TCPRoute/TLSRoute/
UDPRoute are not yet promoted to v1 in gateway-api v1.5.1). L4 route backend
services are unioned into the dependency set so their EDS clusters generate.

The edge path (TCPRoute/TLSRoute parentRef=Gateway) is a follow-up; this PR
scopes to GAMMA east-west.

Chart version bumped 0.36 → 0.37; RBAC for tcproutes/tlsroutes/udproutes added
under the agent.l4Routes flag.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01N7oY7W8oDXrqDzFgoZh25S
@bpalermo
bpalermo merged commit a0a238e into main Jun 24, 2026
13 checks passed
@bpalermo
bpalermo deleted the feat/l4-routes-phase3b branch June 24, 2026 12:09
bpalermo added a commit that referenced this pull request Jun 24, 2026
PR #294 (TCP-over-mTLS floor) and #296 (TCPRoute/TLSRoute/UDPRoute L4
routing) were both unreachable because the service model was HTTP-only: a
workload could never be classified as TCP. This lets a workload be
registered and generated as a PROTOCOL_TCP service so the capture TCP
floor and L4 routes become reachable and e2e-testable.

- proto: add Service.Protocol PROTOCOL_TCP = 2.
- registration (registry/cni.go): pick the protocol from the new
  endpoint.aether.io/protocol pod annotation (default "http"; "tcp" =>
  PROTOCOL_TCP; unknown values rejected).
- generator: project PROTOCOL_TCP services into selectorless mesh Services
  annotated aether.io/app-protocol=tcp (the agent capture reconciler's
  TCP-floor signal); one mesh Service per name, HTTP claimed first.
- registrar snapshot/sync/server: list + sync every protocol; supersede
  write-behind unregisters across protocols.
- agent watch cache (RegistrarRegistry): partition the watch-fed cache by
  protocol so ListAllEndpoints(protocol) returns only that protocol's
  services; ListAllEndpoints now gates on watch readiness (not a non-empty
  partition) so an empty protocol returns the truthful empty set.
- agent EDS (cache/cluster.go): build TCP service cluster entries holding
  the bare-name EDS load assignment (+ SAN/sni) that the floor's
  "tcp:<svc>.<domain>" cluster references; no HTTP h2 cluster/vhost is
  emitted for a TCP service.
- ghost sweep: reconcile both protocols so TCP endpoints aren't ghost-pruned.

Operator marks a workload TCP with the pod annotation:
  endpoint.aether.io/protocol: tcp

Adds unit tests: registration picks TCP from the annotation; the generator
emits a tcp-annotated mesh Service; the agent builds a tcp:<svc> cluster
with EDS endpoints. HTTP behavior is unchanged (default is HTTP).


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

Co-authored-by: Claude Opus 4.8 <[email protected]>
bpalermo added a commit that referenced this pull request Jul 2, 2026
…ped (#460) (#463)

The 'in progress / not yet shipped' list was fully stale: the TCP-over-mTLS floor
(#295/#304), Phase 3b L4 routes (#296), VirtualHost retirement (#292), MCS phase 1,
and conformance (both profiles hard-gated) have all landed. Documents the tcp
protocol-declaration chain (endpoint.aether.io/protocol -> PROTOCOL_TCP ->
aether.io/app-protocol -> /32 floor chain) and the destination-IP-beats-ALPN
filter-chain-match gotcha.


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

Co-authored-by: Claude Opus 4.8 <[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