Skip to content

fix(agent): port-qualify TLSRoute SNI chains so 037's floor chains stop shadowing them - #917

Merged
bpalermo merged 1 commit into
mainfrom
fix/911-tlsroute-port-qualified
Sep 23, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/911-tlsroute-port-qualified

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Closes #911.

The bug

Proposal 037 Phase 2 gave every TCP-primary service destination_port-qualified floor chains (:18082 and the primary port), and design (d) gave every service destination_port chains for its non-primary raw-TCP ports. Envoy resolves destination_port first and server_names third, so an SNI chain matching only prefix_ranges + server_names lost outright — it never reached the tier where its SNI would have won.

From that commit, a TLSRoute on such a service was Accepted, generated correct-looking config, and was inert on both mesh spellings. Nothing errored.

Its only surviving path was the 037 any-port shim — so TLSRoute traffic was incrementing cap_tcp_anyport_<svc>.downstream_cx_total, the exact counter Phase 4's removal is gated on. The bug quietly contaminated the evidence for deleting the chain that was carrying it.

The fix

Let Envoy's own precedence apply instead of working around it: give each SNI chain a destination_port-matched twin for every port something else claims. The two then tie on tiers 1 and 2, tier 3 decides, and the chain carrying server_names wins. No ordering hack, no special case.

The unqualified chains are retained — they still serve every port nothing claims, which was the only spelling that worked before this fix.

claimedTCPPorts() derives the port set from both producers (buildCaptureTCPPortFilterChain and tcpPrimaryFloorChains), with a test pinning that, so a third producer cannot silently reopen this on a new port.

The comment that made it easy to miss

It said the TLS chains were "inserted first so Envoy evaluates server_names+IP before the destination-IP-only floor chain". True in outcome when written, wrong in mechanism — and when 037 added a destination_port, the wrong mechanism stopped predicting the outcome. Filter chains are selected by specificity tiers, never by list position. Rewritten to say so.

Negative control

Reverting only the qualification — the function is still called and the package still compiles, so the test is what fails, not the build:

--- FAIL: TestTLSRouteChainsSurvivePortQualifiedFloor
    no server_names chain at :18082 — a port-qualified floor chain outranks the SNI
    chain on Envoy's first tier, so the TLSRoute is inert on that spelling (#911)
    no server_names chain at :9000 — ...

Both sanctioned ports, green once restored.

e2e

e2e/l4routes.sh dialled 8443 precisely because nothing claimed it while TLSRoute was shadowed — its header says so at length. That port now passes with or without the fix, so the leg is retargeted to the primary port, which the floor chain also claims. T2.3 (unmatched SNI falls through) still holds and now falls to the port-qualified floor rather than the shim.

⚠️ As when it merged in #912, this e2e has still never been executed — not on kind, not on talos. The unit test is the gate here.

No envoy_validate case, deliberately

The generated config was always valid, only wrongly ordered. envoy --mode validate cannot catch this class, so a case there would be reassurance rather than coverage. The assertion has to be on the match criteria, which is what the unit test does.

Follow-up

Once this deploys, TLSRoute stops riding the any-port shim and Phase 4's gate decouples. The 037 proposal's Phase 4 criterion needs its qualifier updated — tracked separately.

Checks

  • //agent/internal/xds/proxy:all, //agent/internal/xds/cache:all, //agent/internal/l4route:all — pass
  • lint clean on //agent/... and //e2e/...; format.check clean
  • bash -n clean on the e2e

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…op shadowing them

Proposal 037 Phase 2 gave every TCP-primary service destination_port-qualified
floor chains (:18082 and the primary port), and design (d) gave every service
destination_port chains for its non-primary raw-TCP ports. Envoy resolves
destination_port FIRST and server_names third, so an SNI chain matching only
prefix_ranges + server_names lost outright — it never reached the tier where
its SNI would have won.

From that commit, a TLSRoute on such a service was Accepted, generated
correct-looking config, and was INERT on both mesh spellings. Nothing errored.
Its only surviving path was the 037 any-port shim, which means TLSRoute traffic
was incrementing cap_tcp_anyport_<svc>.downstream_cx_total — the exact counter
037 Phase 4's removal is gated on. So the bug also quietly contaminated the
evidence for deleting the chain that was carrying it.

The fix is to let Envoy's own precedence apply rather than work around it: give
each SNI chain a destination_port-matched twin for every port something else
claims. The two then tie on tiers 1 and 2 and tier 3 decides, so the chain
carrying server_names wins. No ordering hack, no special case. The unqualified
chains are retained — they still serve every port nothing claims, which was the
only spelling that worked before this fix.

claimedTCPPorts() derives the port set from BOTH producers, so a third one
cannot silently reopen this on a new port without failing its test.

Also fixes the comment that made this easy to miss. It said the TLS chains were
"inserted first so Envoy evaluates server_names+IP before the destination-IP-only
floor chain" — true in outcome when written, wrong in mechanism, and when 037
added a destination_port the wrong mechanism stopped predicting the outcome.
Filter chains are selected by specificity tiers, never by list position.

e2e/l4routes.sh dialled 8443 precisely BECAUSE nothing claimed it while TLSRoute
was shadowed. That port now passes with or without the fix, so the leg is
retargeted to the primary port, which the floor chain also claims.

Negative control: reverting only the qualification (the function still called,
package still compiles, so the TEST is what fails) produces

  no server_names chain at :18082 — a port-qualified floor chain outranks the
  SNI chain on Envoy's first tier, so the TLSRoute is inert (#911)
  no server_names chain at :9000 — ...

on both sanctioned ports, and green once restored.

No envoy_validate case: the generated config was always VALID, only wrongly
ordered, so validation cannot catch this class. The assertion has to be on the
match criteria, which is what the unit test does.

Closes #911

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo enabled auto-merge (squash) September 23, 2026 16:21
@bpalermo
bpalermo merged commit b680a00 into main Sep 23, 2026
23 checks passed
@bpalermo
bpalermo deleted the fix/911-tlsroute-port-qualified branch September 23, 2026 16:30
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.

TLSRoute SNI chains carry no destination_port, so 037's per-port floor chains shadow them on :18082 and the primary port

1 participant