Skip to content

fix(agent): give the readiness probe its own TLS context, and make an unpinned cluster loud (#836, #832) - #840

Merged
bpalermo merged 2 commits into
mainfrom
fix/836-832-probe-tls-boundary-and-unpinned-clusters
Sep 20, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/836-832-probe-tls-boundary-and-unpinned-clusters

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Fixes #836. Fixes #832.

Both were found while investigating #829, both live in the upstream-TLS /
server-identity-pinning path, and both touch the same two files
(agent/internal/xds/proxy/transportsocket.go, agent/internal/xds/cache/mtls.go)
plus the same test harness — so they ship together rather than as two PRs that
would conflict with each other.

#836 — the readiness probe gets its own TLS context

inboundready_<pod> built its transport socket with UpstreamTransportSocket,
the same helper every mesh cluster uses. That probe dials each local pod's mesh
inbound inside that pod's netns every 5 s, so its TLS peer is always a pod
on this node presenting that pod's SVID — the one certificate that must never
turn up in an unrelated cluster's handshake. In #829 it did: mesh clusters
resumed from a session the probe had created and were handed a local pod's
certificate, which is exactly why the leaked identity was always a source-node
neighbour.

The probe now builds its own UpstreamTlsContext
(proxy.InboundReadyProbeTransportSocket) carrying its own
max_session_keys: 0.

Why #834 does not make this redundant. #834 set max_session_keys: 0 on the
shared mesh builder, which removes the slot everywhere — correct, and it should
stay. But it is a global switch, and it is one someone may legitimately
reverse: upstream envoy#45982 scopes the upstream session cache by SNI, and once
that is in force for our config, resumption for mesh traffic becomes defensible
again. The moment that happens, the probe would silently be back inside the same
cache as application traffic. What this change adds is the boundary: the
probe's TLS state is not reachable by application traffic regardless of what the
mesh path does. The two changes have different lifetimes.

The SAN pin ([]string{podSpiffeID}) and the empty SNI are unchanged — both are
load-bearing and the reasons are restated at the new function.

#832 — an unpinned cluster is no longer silent

When the SAN pin cannot be rendered, the upstream validation context goes out
with no match_typed_subject_alt_names, so the handshake proves only
trust-domain membership: any mesh workload satisfies it. Emitting that rather
than spiffe:///ns/… (unservable, four permanently-demoted endpoints on rev222,
#815/#819) is the right call. Shipping it silently is not — it is the fail-open
direction, and the pin is what made #829 loud in the first place.

Each snapshot now:

The check reads clusterEntry.sanURIs, the single cached render of the pin that
every emission path consumes (the HTTP/edge mTLS cluster, and the TCP floor's
tcp:<svc> cluster), so it covers all of them without re-walking emitted protos
on the snapshot hot path.

It reports two reasons, because the pin has two ways to come out empty:

One thing worth flagging for review: today an empty trust domain also makes
refreshEntryMTLSLocked return before injecting mTLS at all (and
captureTCPClusters skips on the empty validation-context name), so in that
window the cluster goes out with no transport socket, not with an unpinned
one. The literal unpinned-UpstreamTlsContext wire shape is reached via the
second reason. Keying the report on the cached pin covers both without
depending on which guard fires first.

Runbook: new "The unpinned-cluster signal (#832)" subsection next to the two
#638 discriminators, with the PromQL and what each reason means.

Config-shape gate

//test/envoy_validate now asserts that every upstream TLS context in each
generated bootstrap carries a non-empty match_typed_subject_alt_names, over
the exact bytes handed to envoy --mode validate. Nothing is allow-listed by
name: a cluster is checked precisely when it has an UpstreamTlsContext, so the
passthrough / app / health / xds / spire_agent / waypoint-ingress clusters (no
TLS) are out of scope automatically and a new mesh cluster is in scope the
moment it grows one. Both carriers are covered — the plain transport_socket
and each transport_socket_matches entry (the per-source mTLS shape, where the
pin must be on every match including the node-identity on_no_match one).

Test evidence

bazel test //agent/internal/xds/... //test/envoy_validate/...   # 8 targets, all pass
bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation \
    //agent/internal/xds/... //test/envoy_validate/...          # clean
bazel test --config=race //agent/internal/xds/cache:all          # pass

Non-vacuity, proved by mutation (each break applied, observed, reverted):

  1. newServiceCluster → sanURIs = nil:
    node_bootstrap.json / node_cleartext / node_uds / capture / capture_route_target: upstream TLS contexts with no match_typed_subject_alt_names: [echo.mesh.local …]
  2. newPerSourceServiceCluster → InjectUpstreamMTLS(..., nil, ...):
    per-source-echo.mesh.local/spiffe://aether.internal/node/test-node +
    both source-identity matches — the matches branch is live too.
    In both mutations envoy --mode validate still exited 0 on every
    bootstrap. That is the point of the gate: Envoy accepts an unpinned context,
    so a passing validate says nothing about it.
  3. reportUnpinnedClusters call removed from generateSnapshot:
    TestEmptyTrustDomainReportsUnpinnedClusters and
    TestUnpinnedClusterReportNamesTheOtherCause both fail
    ("should have 1 item(s), but has 0").
  4. MaxSessionKeys dropped from InboundReadyProbeTransportSocket:
    TestInboundReadyProbeHasItsOwnTLSSessionState fails on the
    "must be SET, not left to Envoy's default of 1" assertion.

New/extended tests: TestEmptyTrustDomainReportsUnpinnedClusters (WARN text,
level, named cluster, count, reason, counter, the seeded zero being a real
series, per-snapshot re-reporting, and recovery when the trust domain returns),
TestUnpinnedClusterReportNamesTheOtherCause,
TestInboundReadyProbeHasItsOwnTLSSessionState, and the counter added to
TestCacheMetrics_IdentityCountersSeededAtZero.

Pre-existing failures, unrelated and confirmed on the base commit c8f3d91:
//agent/internal/proxy/hotrestart:hotrestart_test
(TestAdminWatchdogFiresWhenAdminHangsAfterLive, TestWriteReadStateRoundTrip)
fails identically without this change. TestObservedUpstreamsStore_ShrinkRemovesTheEntry
(30 ms TTL) flakes under --config=race on a loaded machine and passes
repeatedly on an idle one, on this branch.

No cluster was touched: this is code only.

Co-Authored-By: Claude Opus 5 [email protected]
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits September 20, 2026 07:56
… unpinned cluster loud (#836, #832)

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.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit bdccd78 into main Sep 20, 2026
20 checks passed
@bpalermo
bpalermo deleted the fix/836-832-probe-tls-boundary-and-unpinned-clusters branch September 20, 2026 11:28
bpalermo added a commit that referenced this pull request Sep 20, 2026
) (#850)

proxy.DownstreamTransportSocket set RequireClientCertificate: true with a
validation context carrying no SAN matchers at all, so the inbound handshake
proved only trust-bundle membership — any certificate that bundle signs,
including identities that are not workload SVIDs. The inbound HCM then stamps
that certificate's URI SAN into XFCC with SANITIZE_SET (ingress.go), and
RBAC/ext_authz decisions key on that value, so the property every XFCC-derived
rule assumes was never actually established.

The destination cannot pin a specific ServiceAccount — in a mesh any workload
may legitimately call — but it can require the certificate to be STRUCTURALLY a
workload SVID. Each mTLS inbound chain now carries a combined validation
context with one match_typed_subject_alt_names entry: san_type URI, prefix
"spiffe://<trust-domain>/ns/". Envoy builds StringSanMatcher(GEN_URI, matcher)
for URI SANs (source/common/tls/cert_validator/san_matcher.cc), so the full
StringMatcher surface applies; only DNS gets the RFC 6125 special case.

The TCP floor gets the same pin and needs it most: it is the listener's DEFAULT
chain and tcp_proxy forwards raw bytes to the application, so there is no XFCC
and no HTTP-level authorization behind it at all.

Empty trust domain emits NO matcher, never "spiffe:///ns/". A prefix built from
an empty trust domain matches no certificate any CA in this mesh has issued, so
it would fail every inbound handshake on that pod — #815/#819 with a node's
blast radius. That branch is defence in depth rather than a live path:
NewInboundListener already returns ErrNoTrustDomain first, so the reachable
outcome is a skipped pod with a WARN naming it.

No new counter for an unpinned inbound, deliberately, unlike #840's
cluster_unpinned: that counter exists because the cluster path deliberately
SHIPS the unpinned form as the lesser evil and did so silently. Here the lesser
evil is refusing to build the listener, which is already loud. The gate is a
build-time config-shape assertion instead — UnpinnedInboundChains over the
generated bootstrap bytes — which also covers a future caller that bypasses the
ErrNoTrustDomain guard, something a runtime counter could not.

envoy --mode validate ACCEPTS an unpinned downstream context, the same
fail-open direction #832 found upstream. Proved non-vacuous by forcing
WorkloadSANPrefix to "": the assertion named every affected chain
(inbound_test-pod/in_tcp_test-pod, /in_test-pod, /in_test-pod_8080) while all
seven bootstraps still reported "configuration ... OK".

The node identity satisfies the pin: the agent is an ordinary pod, so SPIRE's
fallback ClusterSPIFFEID issues it spiffe://<td>/ns/aether-system/sa/aether-agent
(#825). That matters because the inboundready_<pod> probe dials every local pod
presenting it — a rejection there would demote endpoints, the rev222 failure
mode. //test/envoy_validate's fixtures still spelled the node identity as
spiffe://<td>/node/test-node, which the new pin would REJECT; they now use the
production shape, and a proxy-package test asserts the probe's certificate
satisfies the pin directly.

Scope note: the prefix names the LOCAL trust domain, which makes it exactly as
restrictive as the upstream pin already shipped (cache/mtls.go renders exact
spiffe://<local-td>/ns/<ns>/sa/<svc> matchers). Cross-trust-domain traffic is
therefore already impossible in the client direction, and proposal 019 states a
shared trust domain as a precondition with SPIRE federation deferred. If
federation is ever enabled both pins must widen together.

This changes the inbound filter chains' bytes, so Envoy replaces and drains
every mesh pod's inbound chains once on rollout (--drain-time-s, 10s here).


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Opus 5 <[email protected]>
bpalermo added a commit that referenced this pull request Sep 20, 2026
…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 added a commit that referenced this pull request Sep 20, 2026
…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 added a commit that referenced this pull request Sep 20, 2026
…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 added a commit that referenced this pull request Sep 20, 2026
…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 added a commit that referenced this pull request Sep 20, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant