Repository navigation
fix(agent): disable upstream TLS session resumption — a resumed session carries the wrong peer identity (#829) - #834
Conversation
…on carries the wrong peer identity (#829) Envoy defaults max_session_keys to 1, so every upstream cluster keeps a client-side TLS session cache. A resumed session carries the peer certificate of the server that CREATED it, and Envoy re-runs match_typed_subject_alt_names against that certificate. Resume a session made against one server while dialling another and the handshake reports a peer SVID that never came off the connection — which is exactly what #829 observed twice: a client identity (sa/prober) and a co-located neighbour's identity (sa/svc-4) appearing as the "peer certificate" on clusters those workloads have nothing to do with. Upstream envoy#45982 already scopes that cache by SNI, and its own comment says why: "Reusing sessions across these names can resume the wrong TLS session." That fix cannot help aether. We repurposed SNI as a destination PORT selector (see the comment this change sits under), so every upstream context collapses onto the cache key "8080" — or "" for the TCP floor and the inbound-readiness probe. The scoping discriminator is a constant here, and we are effectively still on the unscoped path with the guard on. Switching resumption off costs nothing. Upstream connections are long-lived pooled h2, so full handshakes are rare and amortised, and the mesh's entire premise is that the SVID on a connection belongs to that connection's peer. Correctness beats a handshake we almost never perform. All five upstream builders funnel through upstreamTransportSocket, so the field lands on the east-west HTTP and TCP sockets, both edge sockets, and the inboundready_<pod> probe. The probe matters most: it dials each local pod's inbound listener inside that pod's netns, so its peers are this node's own pods — precisely the population whose SVIDs leaked into other clusters' handshakes, and the reason the leaked identity was always a source-node neighbour rather than the destination's. The test pins the field on every builder and fails if it is merely unset, since unset means Envoy's default of 1 rather than 0. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
|
Live confirmation from the rev226 soak, which deliberately ran the unfixed build with this PR held back so the mechanism could show itself. It reproduced twice more, and the second one is decisive.
The w01 occurrence settles the shape: one distinct presented SAN across all seven clusters (131/131 lines), six of the seven starting within 0.6 s of each other and all over within ~14 s, with three different source pods (k6 loader, prober, uds-client) all leaking the same neighbour's identity. That is one cache shared per proxy, not per cluster and not per workload — exactly what Two findings that sharpen the rationale in the PR body: 1. The upstream fix may be the mechanism here, not merely inert. envoy#45982 scopes the cache by SNI. When SNI is a hostname that partitions the cache per service; when SNI is a constant port — ours is, 2. It is not volume-driven. All 17 Session reuse itself remains universal and almost always harmless: 28–33% of handshakes on every node after every epoch, across ~31 rolls, with failures on only one of them. Ready to merge once the soak grades at 07:11:22Z. The branch is BEHIND main and needs updating first. |
… unpinned cluster loud (#836, #832) (#840) Two identity defects found while investigating #829, in the same files and the same subsystem (upstream TLS / server-identity pinning). #836 — the inboundready_<pod> probe shared the mesh clusters' upstream TLS builder. That probe dials each local pod's mesh inbound INSIDE that pod's netns every 5 s, so its TLS peer is always a local pod presenting that pod's SVID; in #829 a probe-sourced session ended up serving mesh clusters, which is how a local pod's certificate reached unrelated clusters' handshakes. The probe now builds its OWN UpstreamTlsContext (InboundReadyProbeTransportSocket) carrying its own MaxSessionKeys: 0, so the boundary holds if #834's global switch is later reversed for a good reason. The SAN pin and the empty SNI are unchanged — both are load-bearing. #832 — a cluster whose SAN pin cannot be rendered (no trust domain yet, or endpoints with no namespace metadata) ships a validation context with no match_typed_subject_alt_names, so the handshake proves only trust-domain membership: any mesh workload satisfies it. Emitting that rather than the unservable "spiffe:///ns/…" is the right call (#815/#819), but shipping it silently is not. Each snapshot now WARNs once naming the affected clusters with the reason, and counts them in aether.agent.identity.cluster_unpinned — seeded at zero, because a counter that is never incremented is not a series. Plus the config-shape gate: //test/envoy_validate asserts every upstream TLS context in a generated bootstrap carries a non-empty match_typed_subject_alt_names. `envoy --mode validate` ACCEPTS an unpinned context, so a passing validate says nothing about it. Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr Co-authored-by: Claude Opus 5 <[email protected]>
…nd put the source identity in the pool key (#842) Replaces the per-identity `transport_socket_matches` + `transport_socket_matcher` on every mesh cluster with ONE transport socket whose `custom_tls_certificate_selector` resolves the client certificate per connection, and drops `connection_pool_per_downstream_connection`. Both halves are the same mechanism — the source SPIFFE ID in a downstream-shared filter-state object — so they ship together. ## The filter state Mesh-originating chains now stamp a third object, under the name Envoy's `filter_state_override` upstream certificate mapper hardcodes (`envoy.tls.certificate_mappers.on_demand_secret`) and with the `envoy.hashable_string` factory. That factory is the whole point: `set_filter_state`'s default `envoy.string` builds a `Router::StringAccessorImpl`, which is not `Envoy::Hashable`, and `CommonUpstreamTransportSocketFactory::hashKey` folds a shared filter-state object into the upstream pool key only behind a `dynamic_cast` to `Hashable`. `aether.source.spiffe_id` keeps being stamped for one release: it is what a pre-#842 cluster's matcher reads, so a rollback stays hitless (the dual-key overlap #815 used), and it is the access log's `source_spiffe_id`. ## The cluster custom_tls_certificate_selector: envoy.tls.certificate_selectors.on_demand_secret config_source: ads (the agent's own stream) certificate_mapper: ...upstream_certificate_mappers.filter_state_override default_value: <node SVID> prefetch_secret_names: [<node SVID>] The mapper returns the filter-state string VERBATIM as the SDS secret name, which works only because aether's secret names are SPIFFE IDs. `default_value` is the node SVID — the same identity, for the same connections, that the removed matcher's `on_no_match` presented. Workload identities are deliberately NOT prefetched: listing them would put the node's identity set back into every cluster's bytes. Consequence beyond tidiness: a mesh cluster now has NO workload input at all. #815 release two made cluster bytes invariant under pod churn within a ServiceAccount; the first pod of a new ServiceAccount arriving and the last one leaving still rewrote every mesh cluster on the node, each re-warming for the full 15 s EDS initial_fetch_timeout and draining every upstream pool on the warming→active swap. Those are free now. `max_session_keys: 0` (from #834, for #829) becomes a precondition rather than just a defence: a client context supports a custom certificate selector only with session resumption off. ## What is deliberately unchanged - The `inboundready_<pod>` probe cluster keeps its own statically named certificate and its own `MaxSessionKeys: 0` (#836/#840). A health checker carries no filter state, so a selector there would take `default_value` on every probe — the same node SVID by a longer route — while breaking the #836 boundary that nothing the probe does may be observable by application traffic. - The edge keeps `EdgeUpstreamTransportSocket`: one identity, no source filter state, SDS straight from the SPIRE agent. A selector would add a handshake pause and buy nothing. - The server-identity SAN pin and the SDS-rotated trust bundle. Never per-source. - The proposal 019 waypoint split, which is about SNI, not certificates — but its matcher is now a constant over two fixed sockets (`local`, `waypoint`) instead of a two-level tree over the identity set. ## BREAKS A LIVE ALERT — cross-repo `envoy_cluster_match_count_total{aether_transport_socket_match=...}` does not exist for mesh clusters any more, because they have no transport-socket matches. `AetherClusterIdentityNoMatch` (k8s-talos-main, GitOps #109) therefore matches nothing and evaluates to a clean zero — a vacuous gate, not an error. It must be removed or repointed in the same window this ships. docs/runbook.md, "#842", proposes the replacement: the destination access log's `downstream_peer_uri_san` (already the authoritative check) plus a `-` `source_spiffe_id` on source-reporter lines, which is exactly the condition that makes the mapper fall back to `default_value`. ## Tests `//test/mtlspool` gained a real SDS server (certificate resolution now happens DURING the handshake, so file-backed certs no longer exercise it) and three distinct assertions against the pinned Envoy, plus the negative control: - 11/11 requests from each source verified as that source; - EXACTLY TWO upstream connections, one per identity — the observable that distinguishes #842 from the old flag, which would give 22; - each connection presented the originating pod's own certificate, never `default_value`; - negative control, `envoy.string` instead of `envoy.hashable_string` as the ONLY change: 11/11 of source-B's requests verified as source-A, on ONE shared connection. `//test/envoy_validate` gained a non-vacuity guard, after checking that an empty `default_value` really does make `envoy --mode validate` fail. It also established that the TypedExtensionConfig `name` is informational — a corrupted one validates fine — so the names are pinned in a unit test instead. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…nd put the source identity in the pool key (#842) Replaces the per-identity `transport_socket_matches` + `transport_socket_matcher` on every mesh cluster with ONE transport socket whose `custom_tls_certificate_selector` resolves the client certificate per connection, and drops `connection_pool_per_downstream_connection`. Both halves are the same mechanism — the source SPIFFE ID in a downstream-shared filter-state object — so they ship together. ## The filter state Mesh-originating chains now stamp a third object, under the name Envoy's `filter_state_override` upstream certificate mapper hardcodes (`envoy.tls.certificate_mappers.on_demand_secret`) and with the `envoy.hashable_string` factory. That factory is the whole point: `set_filter_state`'s default `envoy.string` builds a `Router::StringAccessorImpl`, which is not `Envoy::Hashable`, and `CommonUpstreamTransportSocketFactory::hashKey` folds a shared filter-state object into the upstream pool key only behind a `dynamic_cast` to `Hashable`. `aether.source.spiffe_id` keeps being stamped for one release: it is what a pre-#842 cluster's matcher reads, so a rollback stays hitless (the dual-key overlap #815 used), and it is the access log's `source_spiffe_id`. ## The cluster custom_tls_certificate_selector: envoy.tls.certificate_selectors.on_demand_secret config_source: ads (the agent's own stream) certificate_mapper: ...upstream_certificate_mappers.filter_state_override default_value: <node SVID> prefetch_secret_names: [<node SVID>] The mapper returns the filter-state string VERBATIM as the SDS secret name, which works only because aether's secret names are SPIFFE IDs. `default_value` is the node SVID — the same identity, for the same connections, that the removed matcher's `on_no_match` presented. Workload identities are deliberately NOT prefetched: listing them would put the node's identity set back into every cluster's bytes. Consequence beyond tidiness: a mesh cluster now has NO workload input at all. #815 release two made cluster bytes invariant under pod churn within a ServiceAccount; the first pod of a new ServiceAccount arriving and the last one leaving still rewrote every mesh cluster on the node, each re-warming for the full 15 s EDS initial_fetch_timeout and draining every upstream pool on the warming→active swap. Those are free now. `max_session_keys: 0` (from #834, for #829) becomes a precondition rather than just a defence: a client context supports a custom certificate selector only with session resumption off. ## What is deliberately unchanged - The `inboundready_<pod>` probe cluster keeps its own statically named certificate and its own `MaxSessionKeys: 0` (#836/#840). A health checker carries no filter state, so a selector there would take `default_value` on every probe — the same node SVID by a longer route — while breaking the #836 boundary that nothing the probe does may be observable by application traffic. - The edge keeps `EdgeUpstreamTransportSocket`: one identity, no source filter state, SDS straight from the SPIRE agent. A selector would add a handshake pause and buy nothing. - The server-identity SAN pin and the SDS-rotated trust bundle. Never per-source. - The proposal 019 waypoint split, which is about SNI, not certificates — but its matcher is now a constant over two fixed sockets (`local`, `waypoint`) instead of a two-level tree over the identity set. ## BREAKS A LIVE ALERT — cross-repo `envoy_cluster_match_count_total{aether_transport_socket_match=...}` does not exist for mesh clusters any more, because they have no transport-socket matches. `AetherClusterIdentityNoMatch` (k8s-talos-main, GitOps #109) therefore matches nothing and evaluates to a clean zero — a vacuous gate, not an error. It must be removed or repointed in the same window this ships. docs/runbook.md, "#842", proposes the replacement: the destination access log's `downstream_peer_uri_san` (already the authoritative check) plus a `-` `source_spiffe_id` on source-reporter lines, which is exactly the condition that makes the mapper fall back to `default_value`. ## Tests `//test/mtlspool` gained a real SDS server (certificate resolution now happens DURING the handshake, so file-backed certs no longer exercise it) and three distinct assertions against the pinned Envoy, plus the negative control: - 11/11 requests from each source verified as that source; - EXACTLY TWO upstream connections, one per identity — the observable that distinguishes #842 from the old flag, which would give 22; - each connection presented the originating pod's own certificate, never `default_value`; - negative control, `envoy.string` instead of `envoy.hashable_string` as the ONLY change: 11/11 of source-B's requests verified as source-A, on ONE shared connection. `//test/envoy_validate` gained a non-vacuity guard, after checking that an empty `default_value` really does make `envoy --mode validate` fail. It also established that the TypedExtensionConfig `name` is informational — a corrupted one validates fine — so the names are pinned in a unit test instead. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…nd put the source identity in the pool key (#842) Replaces the per-identity `transport_socket_matches` + `transport_socket_matcher` on every mesh cluster with ONE transport socket whose `custom_tls_certificate_selector` resolves the client certificate per connection, and drops `connection_pool_per_downstream_connection`. Both halves are the same mechanism — the source SPIFFE ID in a downstream-shared filter-state object — so they ship together. ## The filter state Mesh-originating chains now stamp a third object, under the name Envoy's `filter_state_override` upstream certificate mapper hardcodes (`envoy.tls.certificate_mappers.on_demand_secret`) and with the `envoy.hashable_string` factory. That factory is the whole point: `set_filter_state`'s default `envoy.string` builds a `Router::StringAccessorImpl`, which is not `Envoy::Hashable`, and `CommonUpstreamTransportSocketFactory::hashKey` folds a shared filter-state object into the upstream pool key only behind a `dynamic_cast` to `Hashable`. `aether.source.spiffe_id` keeps being stamped for one release: it is what a pre-#842 cluster's matcher reads, so a rollback stays hitless (the dual-key overlap #815 used), and it is the access log's `source_spiffe_id`. ## The cluster custom_tls_certificate_selector: envoy.tls.certificate_selectors.on_demand_secret config_source: ads (the agent's own stream) certificate_mapper: ...upstream_certificate_mappers.filter_state_override default_value: <node SVID> prefetch_secret_names: [<node SVID>] The mapper returns the filter-state string VERBATIM as the SDS secret name, which works only because aether's secret names are SPIFFE IDs. `default_value` is the node SVID — the same identity, for the same connections, that the removed matcher's `on_no_match` presented. Workload identities are deliberately NOT prefetched: listing them would put the node's identity set back into every cluster's bytes. Consequence beyond tidiness: a mesh cluster now has NO workload input at all. #815 release two made cluster bytes invariant under pod churn within a ServiceAccount; the first pod of a new ServiceAccount arriving and the last one leaving still rewrote every mesh cluster on the node, each re-warming for the full 15 s EDS initial_fetch_timeout and draining every upstream pool on the warming→active swap. Those are free now. `max_session_keys: 0` (from #834, for #829) becomes a precondition rather than just a defence: a client context supports a custom certificate selector only with session resumption off. ## What is deliberately unchanged - The `inboundready_<pod>` probe cluster keeps its own statically named certificate and its own `MaxSessionKeys: 0` (#836/#840). A health checker carries no filter state, so a selector there would take `default_value` on every probe — the same node SVID by a longer route — while breaking the #836 boundary that nothing the probe does may be observable by application traffic. - The edge keeps `EdgeUpstreamTransportSocket`: one identity, no source filter state, SDS straight from the SPIRE agent. A selector would add a handshake pause and buy nothing. - The server-identity SAN pin and the SDS-rotated trust bundle. Never per-source. - The proposal 019 waypoint split, which is about SNI, not certificates — but its matcher is now a constant over two fixed sockets (`local`, `waypoint`) instead of a two-level tree over the identity set. ## BREAKS A LIVE ALERT — cross-repo `envoy_cluster_match_count_total{aether_transport_socket_match=...}` does not exist for mesh clusters any more, because they have no transport-socket matches. `AetherClusterIdentityNoMatch` (k8s-talos-main, GitOps #109) therefore matches nothing and evaluates to a clean zero — a vacuous gate, not an error. It must be removed or repointed in the same window this ships. docs/runbook.md, "#842", proposes the replacement: the destination access log's `downstream_peer_uri_san` (already the authoritative check) plus a `-` `source_spiffe_id` on source-reporter lines, which is exactly the condition that makes the mapper fall back to `default_value`. ## Tests `//test/mtlspool` gained a real SDS server (certificate resolution now happens DURING the handshake, so file-backed certs no longer exercise it) and three distinct assertions against the pinned Envoy, plus the negative control: - 11/11 requests from each source verified as that source; - EXACTLY TWO upstream connections, one per identity — the observable that distinguishes #842 from the old flag, which would give 22; - each connection presented the originating pod's own certificate, never `default_value`; - negative control, `envoy.string` instead of `envoy.hashable_string` as the ONLY change: 11/11 of source-B's requests verified as source-A, on ONE shared connection. `//test/envoy_validate` gained a non-vacuity guard, after checking that an empty `default_value` really does make `envoy --mode validate` fail. It also established that the TypedExtensionConfig `name` is informational — a corrupted one validates fine — so the names are pinned in a unit test instead. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…nd put the source identity in the pool key (#842) Replaces the per-identity `transport_socket_matches` + `transport_socket_matcher` on every mesh cluster with ONE transport socket whose `custom_tls_certificate_selector` resolves the client certificate per connection, and drops `connection_pool_per_downstream_connection`. Both halves are the same mechanism — the source SPIFFE ID in a downstream-shared filter-state object — so they ship together. ## The filter state Mesh-originating chains now stamp a third object, under the name Envoy's `filter_state_override` upstream certificate mapper hardcodes (`envoy.tls.certificate_mappers.on_demand_secret`) and with the `envoy.hashable_string` factory. That factory is the whole point: `set_filter_state`'s default `envoy.string` builds a `Router::StringAccessorImpl`, which is not `Envoy::Hashable`, and `CommonUpstreamTransportSocketFactory::hashKey` folds a shared filter-state object into the upstream pool key only behind a `dynamic_cast` to `Hashable`. `aether.source.spiffe_id` keeps being stamped for one release: it is what a pre-#842 cluster's matcher reads, so a rollback stays hitless (the dual-key overlap #815 used), and it is the access log's `source_spiffe_id`. ## The cluster custom_tls_certificate_selector: envoy.tls.certificate_selectors.on_demand_secret config_source: ads (the agent's own stream) certificate_mapper: ...upstream_certificate_mappers.filter_state_override default_value: <node SVID> prefetch_secret_names: [<node SVID>] The mapper returns the filter-state string VERBATIM as the SDS secret name, which works only because aether's secret names are SPIFFE IDs. `default_value` is the node SVID — the same identity, for the same connections, that the removed matcher's `on_no_match` presented. Workload identities are deliberately NOT prefetched: listing them would put the node's identity set back into every cluster's bytes. Consequence beyond tidiness: a mesh cluster now has NO workload input at all. #815 release two made cluster bytes invariant under pod churn within a ServiceAccount; the first pod of a new ServiceAccount arriving and the last one leaving still rewrote every mesh cluster on the node, each re-warming for the full 15 s EDS initial_fetch_timeout and draining every upstream pool on the warming→active swap. Those are free now. `max_session_keys: 0` (from #834, for #829) becomes a precondition rather than just a defence: a client context supports a custom certificate selector only with session resumption off. ## What is deliberately unchanged - The `inboundready_<pod>` probe cluster keeps its own statically named certificate and its own `MaxSessionKeys: 0` (#836/#840). A health checker carries no filter state, so a selector there would take `default_value` on every probe — the same node SVID by a longer route — while breaking the #836 boundary that nothing the probe does may be observable by application traffic. - The edge keeps `EdgeUpstreamTransportSocket`: one identity, no source filter state, SDS straight from the SPIRE agent. A selector would add a handshake pause and buy nothing. - The server-identity SAN pin and the SDS-rotated trust bundle. Never per-source. - The proposal 019 waypoint split, which is about SNI, not certificates — but its matcher is now a constant over two fixed sockets (`local`, `waypoint`) instead of a two-level tree over the identity set. ## BREAKS A LIVE ALERT — cross-repo `envoy_cluster_match_count_total{aether_transport_socket_match=...}` does not exist for mesh clusters any more, because they have no transport-socket matches. `AetherClusterIdentityNoMatch` (k8s-talos-main, GitOps #109) therefore matches nothing and evaluates to a clean zero — a vacuous gate, not an error. It must be removed or repointed in the same window this ships. docs/runbook.md, "#842", proposes the replacement: the destination access log's `downstream_peer_uri_san` (already the authoritative check) plus a `-` `source_spiffe_id` on source-reporter lines, which is exactly the condition that makes the mapper fall back to `default_value`. ## Tests `//test/mtlspool` gained a real SDS server (certificate resolution now happens DURING the handshake, so file-backed certs no longer exercise it) and three distinct assertions against the pinned Envoy, plus the negative control: - 11/11 requests from each source verified as that source; - EXACTLY TWO upstream connections, one per identity — the observable that distinguishes #842 from the old flag, which would give 22; - each connection presented the originating pod's own certificate, never `default_value`; - negative control, `envoy.string` instead of `envoy.hashable_string` as the ONLY change: 11/11 of source-B's requests verified as source-A, on ONE shared connection. `//test/envoy_validate` gained a non-vacuity guard, after checking that an empty `default_value` really does make `envoy --mode validate` fail. It also established that the TypedExtensionConfig `name` is informational — a corrupted one validates fine — so the names are pinned in a unit test instead. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…nd put the source identity in the pool key (#842) (#863) Replaces the per-identity `transport_socket_matches` + `transport_socket_matcher` on every mesh cluster with ONE transport socket whose `custom_tls_certificate_selector` resolves the client certificate per connection, and drops `connection_pool_per_downstream_connection`. Both halves are the same mechanism — the source SPIFFE ID in a downstream-shared filter-state object — so they ship together. ## The filter state Mesh-originating chains now stamp a third object, under the name Envoy's `filter_state_override` upstream certificate mapper hardcodes (`envoy.tls.certificate_mappers.on_demand_secret`) and with the `envoy.hashable_string` factory. That factory is the whole point: `set_filter_state`'s default `envoy.string` builds a `Router::StringAccessorImpl`, which is not `Envoy::Hashable`, and `CommonUpstreamTransportSocketFactory::hashKey` folds a shared filter-state object into the upstream pool key only behind a `dynamic_cast` to `Hashable`. `aether.source.spiffe_id` keeps being stamped for one release: it is what a pre-#842 cluster's matcher reads, so a rollback stays hitless (the dual-key overlap #815 used), and it is the access log's `source_spiffe_id`. ## The cluster custom_tls_certificate_selector: envoy.tls.certificate_selectors.on_demand_secret config_source: ads (the agent's own stream) certificate_mapper: ...upstream_certificate_mappers.filter_state_override default_value: <node SVID> prefetch_secret_names: [<node SVID>] The mapper returns the filter-state string VERBATIM as the SDS secret name, which works only because aether's secret names are SPIFFE IDs. `default_value` is the node SVID — the same identity, for the same connections, that the removed matcher's `on_no_match` presented. Workload identities are deliberately NOT prefetched: listing them would put the node's identity set back into every cluster's bytes. Consequence beyond tidiness: a mesh cluster now has NO workload input at all. #815 release two made cluster bytes invariant under pod churn within a ServiceAccount; the first pod of a new ServiceAccount arriving and the last one leaving still rewrote every mesh cluster on the node, each re-warming for the full 15 s EDS initial_fetch_timeout and draining every upstream pool on the warming→active swap. Those are free now. `max_session_keys: 0` (from #834, for #829) becomes a precondition rather than just a defence: a client context supports a custom certificate selector only with session resumption off. ## What is deliberately unchanged - The `inboundready_<pod>` probe cluster keeps its own statically named certificate and its own `MaxSessionKeys: 0` (#836/#840). A health checker carries no filter state, so a selector there would take `default_value` on every probe — the same node SVID by a longer route — while breaking the #836 boundary that nothing the probe does may be observable by application traffic. - The edge keeps `EdgeUpstreamTransportSocket`: one identity, no source filter state, SDS straight from the SPIRE agent. A selector would add a handshake pause and buy nothing. - The server-identity SAN pin and the SDS-rotated trust bundle. Never per-source. - The proposal 019 waypoint split, which is about SNI, not certificates — but its matcher is now a constant over two fixed sockets (`local`, `waypoint`) instead of a two-level tree over the identity set. ## BREAKS A LIVE ALERT — cross-repo `envoy_cluster_match_count_total{aether_transport_socket_match=...}` does not exist for mesh clusters any more, because they have no transport-socket matches. `AetherClusterIdentityNoMatch` (k8s-talos-main, GitOps #109) therefore matches nothing and evaluates to a clean zero — a vacuous gate, not an error. It must be removed or repointed in the same window this ships. docs/runbook.md, "#842", proposes the replacement: the destination access log's `downstream_peer_uri_san` (already the authoritative check) plus a `-` `source_spiffe_id` on source-reporter lines, which is exactly the condition that makes the mapper fall back to `default_value`. ## Tests `//test/mtlspool` gained a real SDS server (certificate resolution now happens DURING the handshake, so file-backed certs no longer exercise it) and three distinct assertions against the pinned Envoy, plus the negative control: - 11/11 requests from each source verified as that source; - EXACTLY TWO upstream connections, one per identity — the observable that distinguishes #842 from the old flag, which would give 22; - each connection presented the originating pod's own certificate, never `default_value`; - negative control, `envoy.string` instead of `envoy.hashable_string` as the ONLY change: 11/11 of source-B's requests verified as source-A, on ONE shared connection. `//test/envoy_validate` gained a non-vacuity guard, after checking that an empty `default_value` really does make `envoy --mode validate` fail. It also established that the TypedExtensionConfig `name` is informational — a corrupted one validates fine — so the names are pinned in a unit test instead. Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr Co-authored-by: Claude Opus 5 <[email protected]>
Fixes the mechanism behind #829: a resumed upstream TLS session carries the peer certificate of the server that created it, and Envoy re-checks that certificate against the current context's
match_typed_subject_alt_names.Why this happens to us
Envoy defaults
max_session_keysto 1 (context_config_impl.cc:404), so every upstream cluster keeps a client-side session cache. On the legacy path the cache is a flat deque of size 1 andsetSessionFromContextCachehands back whatever is in it, regardless of which server produced it. Resume a session made against server A while dialling server B and you get, verbatim:— a peer certificate that never came off this connection.
Upstream already fixed this, and the fix cannot help us. envoy#45982 (
423e157c63) scopes the cache by SNI, with the comment "Reusing sessions across these names can resume the wrong TLS session." It keys on SNI because in a normal deployment SNI is the destination hostname. We repurposed SNI as a destination port selector, so every aether upstream context collapses onto the key"8080"— or""for the TCP floor and the inbound-readiness probe. The discriminator is a constant here; we are effectively still on the unscoped path even with the runtime guard on.Why it explains the observations
#829 saw this twice, on different nodes and days, and the leaked identity was always a workload co-located on the source node, never the destination's:
…/sa/prober(a client identity — no server pod can present it)…/sa/svc-4(a neighbour of the client)The session cache lives on the source proxy's
ClientContextImpl, so the only certificates in it belong to servers that proxy handshook with. Theinboundready_<pod>probe cluster dials each local pod's inbound listener inside that pod's netns, so the node proxy's most frequent TLS peers are its own pods' SVIDs — exactly the population that leaked. It is per-context, not per-source-pod and not per-stream, which is why two different source pods across three clusters failed within 0.6 s. And a fresh Envoy starts with an empty cache, which is why both occurrences landed +7 s and +16 s after a new epoch and nothing reproduced in steady state.It also predates #815 entirely, consistent with that matcher being cleared both by construction and empirically.
The change
One field, on the single helper all five upstream builders funnel through:
client_context_impl.cc:107and:287-290both short-circuit onmax_session_keys_ == 0: no cache, no resumption, no cross-server session. It lands on the east-west HTTP and TCP sockets, both edge sockets, and theinboundready_<pod>probe.The cost is nil. Upstream connections are long-lived pooled h2, so full handshakes are rare and amortised — and the mesh's whole premise is that the SVID on a connection belongs to that connection's peer. This is a correctness field, not a performance knob, and the comment in the code says so, because the port-SNI interaction is not obvious and will otherwise be re-broken.
Verification
//agent/internal/xds/proxy:proxy_test,//agent/internal/xds/...and//test/envoy_validate/...all pass — the last one matters here, since it runs the generated config through a real Envoy config loader and so proves Envoy accepts the field.The new test pins
max_session_keyson every builder and fails if the field is merely unset, since unset means Envoy's default of 1 rather than 0.Confirm-or-kill, running now
envoy_cluster_ssl_session_reusedon a mesh cluster in the first 60 s after a new epoch confirms the mechanism; flat zero across a reproduction kills it. That measurement is instrumented in tonight's 8-hour soak on rev226, which runs the unfixed build — so the soak should produce the confirmation, and this PR should land after it rather than before.Not fixed here
#831 is a separate defect and stands on its own at higher severity: the source SPIFFE ID contributes nothing to the upstream connection-pool hash key, and because the upstream is h2, many source pods multiplex onto one connection whose client certificate was fixed by whichever source created it. That fails open and is invisible; this one failed closed and was visible as errors.
Residual uncertainty
A session cache lives on a
ClientContextImpl, which is per cluster and pertransport_socket_matchentry. Intra-cluster cross-host resumption is clearly reachable. For the 09-18 line whereupstream_clusterwasaether-test/svc-3yet the session appearsinboundready-sourced, the contexts would have to share anSSL_CTX, which was not fully traced.ssl_session_reusedsettles the mechanism regardless of which contexts share, andmax_session_keys: 0fixes it either way.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr