Repository navigation
feat(agent): select the upstream client certificate per connection, and put the source identity in the pool key (#842) - #863
Merged
Conversation
bpalermo
force-pushed
the
feat/842-hashable-source-identity
branch
2 times, most recently
from
September 20, 2026 14:55
3f32dca to
43f4b87
Compare
…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
bpalermo
force-pushed
the
feat/842-hashable-source-identity
branch
from
September 20, 2026 14:56
43f4b87 to
239e5ea
Compare
This was referenced Sep 20, 2026
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 #842.
Replaces the per-identity
transport_socket_matches+transport_socket_matcheron every mesh cluster with one transport socket whosecustom_tls_certificate_selectorresolves the client certificate per connection, and dropsconnection_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. Removing the flag without the hashable key re-opens the #831 leak, and it fails open.
The filter state
Mesh-originating chains stamp a third object, under the name Envoy's
filter_state_overrideupstream certificate mapper hardcodes (envoy.tls.certificate_mappers.on_demand_secret), with theenvoy.hashable_stringfactory.That factory is the whole point:
set_filter_state's defaultenvoy.stringbuilds aRouter::StringAccessorImpl, which is notEnvoy::Hashable, andCommonUpstreamTransportSocketFactory::hashKeyfolds a shared filter-state object into the upstream pool key only behind adynamic_casttoHashable.aether.source.spiffe_idkeeps being stamped for one release: it is what a pre-#842 cluster's matcher reads, so rollback stays hitless (the dual-key overlap #815 used), and it is the access log'ssource_spiffe_id. Retiring it and the netns copy together is a follow-up.The cluster
The mapper returns the filter-state string verbatim as the SDS secret name — which works only because aether's secret names are SPIFFE IDs (
SpiffeIDFromPodfeeds both ends).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_timeoutand 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.Decisions called out in the issue
default_value= the node SVID (spiffe://<td>/ns/aether-system/sa/aether-agent, the agent's own workload ID — not a/node/ID, per #825). It is what a connection with no source filter state gets, which is exactly the set of connections the removed matcher'son_no_matchserved, and the same identity it presented. Same behaviour, same failure signature to watch, no new semantics.min_len: 1is satisfied structurally: the cache emits no socket at all before the node SVID is served.The
inboundready_<pod>probe cluster is untouched. It has no selector — it keeps its statically named node-SVID certificate and its ownMaxSessionKeys: 0(#836/#840). A health checker carries no filter state, so had it used the selector it would have takendefault_valueon every probe: the same certificate, by a longer route, while breaking the #836 boundary that nothing the probe does may be observable by application traffic.The edge is untouched. One identity, no source filter state, and SDS comes straight from the SPIRE agent rather than the agent's ADS stream. A selector would add a first-connection handshake pause and buy nothing.
The waypoint split survives, as a constant. SNI is a property of the transport socket, not of the certificate, so a waypoint-enabled cluster still needs two sockets — but they are now a fixed two (
local,waypoint) selected by endpoint metadata, independent of the node's identity set, with bounded match names instead of SPIFFE IDs.⚠ BREAKS A LIVE ALERT — cross-repo, needs a k8s-talos-main change
envoy_cluster_match_count_total{aether_transport_socket_match=...}no longer exists for mesh clusters, 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, so nothing surfaces the loss.It must be removed or repointed in the same window this ships.
docs/runbook.md, "#842", proposes the replacement, in order of strength:downstream_peer_uri_san— already documented as the authoritative cross-check, now the primary;-source_spiffe_idon source-reporter lines, which is precisely the condition that makes the mapper fall back todefault_value(and is per request, not per connection);cluster.<c>.on_demand_secret.{cert_requested,cert_updated,cert_active}— the selector's own stats. A liveness signal for the mechanism; they do not identify which identity.Handshake-pause cost
On-demand SDS pauses the handshake on the first connection per (secret name, worker, cluster). The fetch is a local round trip to the node agent over its ADS UDS, with the secret already in the snapshot.
The cluster itself does not warm on any of it, and that is a change in the other direction: a statically referenced SDS certificate is fetched through a warming provider, so a client certificate the agent failed to serve used to hold its cluster in warming for
initial_fetch_timeoutand then bring it up withupstream_context_secrets_not_ready. The on-demand path creates its providers withwarm=false(SecretManagerImpl::DynamicSecretProviders::findOrCreate), so no mesh cluster blocks on a client-certificate secret any more — including the prefetched node SVID. The cost moves from cluster warming, which is node-wide, to one paused handshake, which is not.prefetch_secret_namescarries the node SVID, so the no-filter-state path never pauses at all. Workload identities are deliberately not prefetched — listing them would put the node's identity set back into every cluster's bytes, the exact churn #815 and this change remove.Net: strictly cheaper than what it replaces.
connection_pool_per_downstream_connectionforced a full mTLS handshake on every downstream connection, measured at ~25 ms of a 29 ms p50 hop (#735).Tests
//test/mtlspoolgained 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. The single variable between the positive and negative runs is the object factory, applied by rewriting production's own output.total=2is the observable that distinguishes #842 from the old flag: 1 would be the leak, 22 would be per-downstream-connection pooling.--concurrency 1is what makes the exact number meaningful.//test/envoy_validategained a non-vacuity guard — after checking that an emptydefault_valuereally does makeenvoy --mode validatefail:That probe also established that the
TypedExtensionConfignameis informational — a corrupted one validates fine, since resolution is by type URL — so the names are pinned in a unit test instead, and the comments that claimed otherwise were corrected.Inverted rather than deleted, each with the issue number on it:
TestServiceClusterBytesChangeOnFirstAndLastPodOfServiceAccount→ must now be unchanged;TestCachedMTLSClusterInvalidatedOnWorkloadChange→ byte-identity across a new-ServiceAccount ADD/DEL;TestNodeProxyPerSourceClustersPoolPerDownstreamConnection→ asserts the flag is off andmax_session_keysis 0, together;TestNoNetnsPathInServiceClusterBytes→ now also forbids any workload SPIFFE ID in a cluster's bytes.bazel test //...— 107/107 pass. Lint clean.make deps-auditOK (no new modules; the bindings already ship ingo-control-plane/envoy v1.39.0, and both extensions are present in the pinned proxy binary).Not established
cert_requestedclimbing withoutcert_updatedfollowing is the shape to watch.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr