Skip to content

test(envoy-validate): gate the three L4 listener shapes on every PR (#868) - #876

Merged
bpalermo merged 2 commits into
mainfrom
test/868-envoy-validate-l4
Sep 20, 2026
Merged

bpalermo merged 2 commits into
mainfrom
test/868-envoy-validate-l4

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

PR1 of #868. Adds //test/envoy_validate coverage for the three L4 listener shapes so they gate every PR as unit targets, rather than waiting on the nightly kind harness (PRs 2–4). Test-only: no charts/ change, so no Chart.yaml bump. No production code touched.

What is covered

Three new bootstraps go through the pinned production Envoy in --mode validate:

bootstrap shape
capture_tcproute_bootstrap.json capture listener whose per-ClusterIP floor chain is a weighted_clusters tcp_proxy over two backends, 75/25
capture_tlsroute_bootstrap.json two per-SNI chains matching prefix_ranges <VIP>/32 plus server_names, on the same listener as the floor chain matching the same /32 with no server_names
capture_udp_bootstrap.json connection-less capture_udp_<pod> listener with udp_proxy as a listener filter and no filter_chains, plus the plaintext STATIC udp: cluster

Envoy's opinion is the point for two of them. Dropping the SNI match makes it reject the TLS listener outright; moving the udp_proxy config into a filter chain makes it reject the UDP one. So it is Envoy — not a Go assertion — that certifies the SNI chains and the floor chain can share a listener.

That coexistence is the fall-through #868 asks about. The acceptance list was first written as "a non-matching SNI does not fall through to a default", and the correction on the issue is right: Envoy selects filter chains by specificity, so a chain with no server_names is a wildcard on SNI and a non-matching SNI lands on the floor by design. This PR asserts that positively — the floor chain exists, shares the /32, sets no server_names, and routes to the parent's own cluster rather than to either TLSRoute backend.

Validation is fail-open about everything it has no opinion on, and is entirely satisfied by a fixture that stopped emitting the thing under test. So each leg also gets a structural assertion over the serialised bytes:

  • TestCaptureTCPRouteWeightedFloorChain — the floor really carries weighted_clusters, at the weights the route asked for, and every weighted cluster is defined by the bootstrap (tcp_proxy has no on-demand CDS: an undefined backend gives a chain that matches and then has nowhere to send the connection).
  • TestCaptureTCPRouteDrainCollapsesToSingleCluster — the fix(l4route): honor weight:0 as drain, don't normalize to 1 #492 property at the config layer: an explicit weight: 0 backend is absent, so the proxy collapses to the single-cluster form.
  • TestCaptureTLSRouteSNIChainsCoexistWithFloor — one hostname per chain, each scoped to the /32; both SNIs routed, to different backends (a one-SNI assertion passes even if server_names is ignored and chain 0 always wins); the floor unconstrained on SNI and pointed at the parent.
  • TestCaptureUDPListenerIsConnectionless — zero filter_chains, binds UDP in the pod netns on the capture port, udp_proxy present and naming a defined cluster.
  • TestCaptureUDPClusterIsPlaintextAtTheAppPort — the concrete shape of "UDP rides the mesh in plaintext": STATIC, inline load assignment, no transport socket, endpoints rewritten to protocol: UDP at the backend's application port. Per the plan this lives here rather than as a wire-level check in the shell harness.

Two assertions that could not fail — found and fixed

Before the red runs below, two of the first-draft assertions were vacuous: they compared the generated weights, and the UDP listener's port, against the same constants the fixture was built from.

Measured: editing L4TCPWeightA from 75 to 50 left the test GREEN.

Both now assert independent literals, with that measurement recorded in a comment next to them. This is the aether#853 shape appearing inside the test written to avoid aether#853, which is exactly why the issue asks for the red run rather than for a passing test.

Red-run evidence

Every assertion was seen red once — by reverting the production hunk it guards where one exists. Breaks were applied in a throwaway git worktree, never in the shared checkout.

(a) Revert the #492 fix — restore if b.Weight == 0 { b.Weight = 1 } in l4RulesToWeightedClusters. This reproduces the bug that actually shipped:

--- FAIL: TestCaptureTCPRouteDrainCollapsesToSingleCluster (0.00s)
    validate_test.go:553: one backend drained (weight 0) but tcp_proxy still carries weighted_clusters
        [tcp:l4-a.default.mesh.local=100 tcp:l4-b.default.mesh.local=1]; weight 0 means DRAIN,
        not an equal share (#492)

(b) Drop ServerNames from BuildCaptureTLSRouteFilterChains — Envoy itself rejects the listener:

--- FAIL: TestEnvoyValidate/capture_tlsroute_bootstrap.json (0.07s)
    error adding listener '0.0.0.0:18001': filter chain
    'cap_tls_tcp:l4-tls-front.default.mesh.local_1' has the same matching rules defined as
    'cap_tls_tcp:l4-tls-front.default.mesh.local_0'. duplicate matcher is:
    {"prefix_ranges":[{"address_prefix":"10.96.2.30","prefix_len":32}]}
--- FAIL: TestCaptureTLSRouteSNIChainsCoexistWithFloor (0.00s)
    validate_test.go:594: chain "cap_tls_..._0": server_names = [], want exactly one hostname
    validate_test.go:620: SNI chains = map[], want one chain per hostname
        map[a.l4.test:tcp:l4-tls-a.default.mesh.local b.l4.test:tcp:l4-tls-b.default.mesh.local]

(c) Constrain the floor chain on SNI (ServerNames: ["floor.invalid"] in buildCaptureTCPFloorFilterChain):

    validate_test.go:603: floor chain "cap_tcp_tcp:l4-tls-front.default.mesh.local" constrains
        server_names to [floor.invalid]; it must not, or a connection whose SNI matches no
        TLSRoute has nowhere to land

(d) Put udp_proxy in a filter chain instead of listener_filters — Envoy rejects it, with the exact message l4route.go only had in a comment:

--- FAIL: TestEnvoyValidate/capture_udp_bootstrap.json (0.09s)
    error adding listener '0.0.0.0:18001': 1 filter chain(s) specified for connection-less UDP listener.
--- FAIL: TestCaptureUDPListenerIsConnectionless (0.00s)
    validate_test.go:688: UDP listener "capture_udp_test-pod" carries 1 filter_chains; ...
    validate_test.go:717: UDP listener "capture_udp_test-pod" has no udp_proxy listener filter: ...

(e) Stop rewriting the endpoint port in UDPLoadAssignment:

    validate_test.go:796: cluster "udp:l4-udp-a.default.mesh.local": endpoint 10.244.3.7
        port = 18008, want the backend's APPLICATION port 9001 — the UDP floor has no
        inbound mTLS hop to dial

(f) Weights (the fixed, non-vacuous form) — L4TCPWeightA 75 → 50:

    validate_test.go:487: chain "cap_tcp_tcp:l4-front.default.mesh.local": cluster
        "tcp:l4-a.default.mesh.local" weight = 50, want 75
        (weighted_clusters: map[tcp:l4-a...:50 tcp:l4-b...:25])

(g) Remove a weighted backend's cluster from the bootstrap:

    validate_test.go:498: chain "cap_tcp_..." routes to cluster "tcp:l4-b.default.mesh.local",
        which the bootstrap does not define — tcp_proxy has no on-demand CDS, so this chain
        matches and then has nowhere to send the connection

(h) Point both SNI chains at the same backend (the mirror assertion):

    validate_test.go:624: SNI "b.l4.test" routes to "tcp:l4-tls-a.default.mesh.local",
        want "tcp:l4-tls-b.default.mesh.local"

(i) Give the udp: cluster a transport socket — the Go assertion fires, and --mode validate segfaults (the documented STATIC-cluster-with-SDS-over-ads validation-server bug that rewriteSDSToExplicitSource already works around, so validation alone would not have been a usable signal here):

    validate_test.go:770: cluster "udp:l4-udp-a.default.mesh.local" carries transport_socket
        "envoy.transport_sockets.tls"; the UDP floor is PLAINTEXT — mesh mTLS is a TCP/TLS
        construct and DTLS is not implemented, so a socket here would claim protection the
        data path does not provide

(j) / (k) Widen the SNI chain match to /24, then drop prefix_ranges entirely:

    validate_test.go:603: chain "cap_tls_..._0": prefix_ranges =
        [address_prefix:"10.96.2.30" prefix_len:{value:24}], want exactly 10.96.2.30/32 —
        without the /32 an SNI chain would claim any service's connection carrying that hostname
    validate_test.go:603: chain "cap_tls_..._0": prefix_ranges = [], want exactly 10.96.2.30/32 — ...

(l)–(q), the remainder — one backend only (tcp_proxy has cluster_specifier *TcpProxy_Cluster, want weighted_clusters); drain the other backend (tcp_proxy cluster = "tcp:l4-front...", want "tcp:l4-a..." — the surviving backend); floor pointed at a TLSRoute backend (floor chain routes to "tcp:l4-tls-a...", the backend of SNI "a.l4.test" — a non-matching SNI would reach a TLSRoute backend); UDP listener binds TCP (binds protocol TCP, want UDP, and --mode validate also exits 1); endpoint protocol left TCP (endpoint 10.244.3.7 protocol = TCP, want UDP); cluster type changed to STRICT_DNS (type = STRICT_DNS, want STATIC with an inline load assignment).

What I judged not worth asserting

  • UDP backend selection or weights. GenerateUDPCaptureListener takes a bare Cluster from backends[0] of the lexicographically first service key, so weights are discarded and a second UDPRoute-backed service on the node has no effect. Any selection assertion would fail by design; that is UDPRoute ignores backend weights and collapses multiple services onto one cluster #873, and this PR's UDP scope is delivery shape only.
  • backendRef.port on an L4 route. It is ignored — the tcp:/udp: cluster's endpoints already carry the port — so asserting on it would pin something that carries no meaning.
  • The floor chain's own prefix_ranges as a separate red run. It goes through the same assertMatchesParentIP helper that breaks (j)/(k) drove red on the SNI chains.
  • A wire-level "UDP is not encrypted" check. Per the plan, that belongs here as a config-shape assertion (TestCaptureUDPClusterIsPlaintextAtTheAppPort); in the shell harness it would be decoration.

Verification

bazel test //test/envoy_validate/...                                   PASSED
make format-check                                                      clean
bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...   clean (398 targets)
make gazelle                                                           run; BUILD.bazel deps regenerated

Envoy really runs over the three new bootstraps (--test_arg=-test.v):

--- PASS: TestEnvoyValidate/capture_tcproute_bootstrap.json (0.08s)
--- PASS: TestEnvoyValidate/capture_tlsroute_bootstrap.json (0.08s)
--- PASS: TestEnvoyValidate/capture_udp_bootstrap.json (0.07s)

Refs #868. Next: PRs 2–4 (the e2e/l4routes.sh kind harness), in progress separately.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits September 20, 2026 15:58
…868)

L4 routing (proposal 018 Phase 3b) is shipped, default-on and unconditional,
and the only thing standing behind it is unit tests of the projector. This is
PR1 of #868: the cheap half, so the config shapes are gated on every PR rather
than once a night (scripts/ci-impacted-targets.sh classifies
//test/envoy_validate as a unit target).

Three bootstraps now go through the pinned production Envoy in --mode validate:

  - capture_tcproute_bootstrap.json  weighted_clusters tcp_proxy on the floor
                                     chain, two backends 75/25
  - capture_tlsroute_bootstrap.json  two per-SNI chains matching <VIP>/32 +
                                     server_names, ALONGSIDE the floor chain
                                     matching the same /32 with no server_names
  - capture_udp_bootstrap.json       connection-less udp_proxy listener plus
                                     the plaintext STATIC "udp:" cluster

Envoy's opinion is the point for two of these. Dropping the SNI match makes it
reject the TLS listener outright ("filter chain ... has the same matching rules
defined as ..."), and moving the udp_proxy config into a filter chain makes it
reject the UDP one ("1 filter chain(s) specified for connection-less UDP
listener") -- a rule l4route.go records in a comment and nothing enforced until
now. So it is Envoy, not a Go assertion, that certifies the SNI chains and the
floor chain can share a listener. That coexistence IS the fall-through #868
asks about: a non-matching SNI reaching the floor is designed behaviour, since
Envoy selects chains by specificity, so it is asserted positively rather than
assumed away. The issue's original wording had this backwards.

Validation is fail-open about everything it has no opinion on, though, and it
is entirely satisfied by a fixture that stopped emitting the thing under test.
So each leg also gets a structural assertion over the serialised bytes: the
weights survive, a drained backend (weight 0) collapses the proxy to the
single-cluster form rather than being normalised to an equal share (#492),
every weighted cluster is actually defined (tcp_proxy has no on-demand CDS),
the UDP listener carries zero filter_chains and binds UDP in the pod netns, and
the "udp:" cluster has no transport socket and dials the backend's APPLICATION
port.

Every assertion was seen red once, by reverting the production hunk it guards
where one exists -- including the pre-#492 `weight 0 -> 1` normalisation, which
this reproduces as "bravo still present at weight 1". Two of the first drafts
could NOT fail: they compared the generated weights and the capture port
against the same constants the fixture was built from. Both now assert
independent literals, with the measurement in a comment, because that is the
aether#853 shape appearing inside the test written to avoid it.

UDP scope is delivery only. GenerateUDPCaptureListener takes a bare Cluster
from the first backend of the first sorted service, so backend selection is not
expressible (#873); no assertion pretends otherwise.

Test-only: no charts/ change, so no Chart.yaml bump.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 6ac9a6c into main Sep 20, 2026
22 checks passed
@bpalermo
bpalermo deleted the test/868-envoy-validate-l4 branch September 20, 2026 19:20
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