Repository navigation
fix(agent): port-qualify TLSRoute SNI chains so 037's floor chains stop shadowing them - #917
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #911.
The bug
Proposal 037 Phase 2 gave every TCP-primary service
destination_port-qualified floor chains (:18082and the primary port), and design (d) gave every servicedestination_portchains for its non-primary raw-TCP ports. Envoy resolvesdestination_portfirst andserver_namesthird, so an SNI chain matching onlyprefix_ranges + server_nameslost 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 carryingserver_nameswins. 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 (buildCaptureTCPPortFilterChainandtcpPrimaryFloorChains), 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:
Both sanctioned ports, green once restored.
e2e
e2e/l4routes.shdialled8443precisely 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.No envoy_validate case, deliberately
The generated config was always valid, only wrongly ordered.
envoy --mode validatecannot 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//agent/...and//e2e/...;format.checkcleanbash -nclean on the e2e🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr