Repository navigation
fix(agent): give the certificate selector its own SDS stream (#842) - #865
Conversation
rev228 took every mesh upstream mTLS connection on talos-main down within
seconds of the new proxies taking the config. The handshakes PAUSE rather than
fail, so nothing you would normally check moved: no ssl_connection_error, no
ssl_fail_verify_san, an empty upstream_transport_failure_reason, and an
upstream_host duly selected on every hung request.
Root cause: the on-demand certificate selector fetched over `ads: {}`.
Envoy keys a secret provider on hash(ConfigSource) + "." + name + warm. The
selector always asks with warm=false; every statically named SDS reference asks
with warm=true. So one secret name gets two independent SdsApi objects with two
independent watches — and on a node proxy that is the normal case: every local
pod's SVID is already named statically by that pod's own inbound listener, and
the node SVID (the selector's default_value AND its prefetch) by every
inboundready_<pod> probe cluster. The selector is always the second subscriber.
On the delta-ADS mux the second watch loses. Envoy's WatchMap deduplicates
subscription interest per (type_url, resource name) across watches, so it
contributes nothing to resource_names_subscribe; no request goes out; the
control plane — correctly, for delta — resends nothing. The watch burns its 15s
initial_fetch_timeout and then does nothing else, because
SdsApi::onConfigUpdateFailed only calls init_target_.ready(): it never notifies
the parked certificate-selection callback. doSelectTlsContext's Pending is
never resolved and the connection hangs until connect_timeout, or until the
downstream gives up first (DC at ~1980ms on the fleet).
The fleet metrics say exactly this, once read correctly:
cert_requested climbed to 196 while cert_updated stayed ABSENT (i.e. zero — the
only thing that increments it is a secret actually arriving), and
envoy_sds_spiffe_<name>_init_fetch_timeout_total climbed for the node SVID and
for workload SVIDs. cert_requested == cert_active is NOT a health signal:
cert_active counts live subscriptions and is incremented on the same line as
cert_requested.
The fix is one config source. The selector gets its own api_config_source to
agent_xds — its own mux, its own watch map — so its subscription can no longer
be deduplicated against a static one. SotW rather than delta on purpose: a SotW
response carries every requested resource and GrpcMuxImpl::addWatch queues a
request unconditionally, so the failure is structurally impossible there even if
a static reference ever lands on it. The agent already serves
SecretDiscoveryService on the same socket as ADS, so no new bootstrap cluster.
Perturbing the ConfigSource hash is not a fix: that changes the provider key
while leaving the mux, and therefore the deduplicating watch map, shared.
Cost, measured: Envoy builds a mux per non-ADS subscription, so this is one gRPC
stream per secret name the selector resolves — per identity actually originating
traffic on the node, lazily on first use, one resource each. The chart's
max_concurrent_streams: 10 does not cap them (on an upstream cluster that field
is what Envoy advertises for peer-initiated streams); the agent's
grpc.MaxConcurrentStreams(1000) does.
The zero-warm property #842 exists for is untouched: the selector's config
source is a constant, so a mesh cluster's bytes still carry no workload input.
Tests:
//test/mtlspool gains the half it shipped without. It proved pool partitioning
against a real Envoy but rewrote every SDS config source to a bespoke
api_config_source, because it had no control plane — which accidentally WAS the
fix, and is why this passed review and CI. It now also runs the pinned proxy
against a real delta-ADS control plane serving CDS/LDS/SDS over a Unix socket,
with the selector's source left exactly as the agent emits it.
TestOnDemandCertificateResolvesWhenAlreadyStaticallyReferenced is the gate: the
source pod's SVID is referenced BOTH ways, as it is on any real node, and the
assertion is completion within a bound rather than the absence of errors — the
absence of errors is the failure mode. Red against the shipped configuration:
[ads-delta] SUBSCRIBE add=[.../node/test-node] remove=[] nonce=""
[ads-delta] RESPOND resources=[.../node/test-node] removed=[]
[ads-delta] SUBSCRIBE add=[.../sa/source-a .../sa/source-b] remove=[]
[ads-delta] RESPOND resources=[.../sa/source-a .../sa/source-b]
[envoy] warning: gRPC config: initial fetch timed out for
type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.Secret
source-a: request did not complete in 2.001705182s: status 503
--- FAIL: TestOnDemandCertificateResolvesWhenAlreadyStaticallyReferenced (17.15s)
Note what is absent from that trace: no third SUBSCRIBE. The selector's request
never reached the wire.
Also added: TestMeshCertSelectorSDSSourceIsNotSharedWithAnyStaticSecret, which
checks the separation from both ends over every builder that names a secret
statically — pointing one at the selector's stream would restore the starvation
silently; and //test/envoy_validate now asserts, over the serialised node
bootstrap, that the selector does not ride ads and that its backing cluster
actually resolves.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…#842) Moving the certificate selector off `ads: {}` fixes the COLD fetch. It says nothing about the second thing that stream has to do: deliver a new version of a secret it has already resolved. That gap is not theoretical and it is badly timed. SPIRE rotates SVIDs on a ~4h TTL, so a 60-75 minute deploy validation crosses no rotation while an 8h soak crosses about two. If rotation were broken here, the first thing to notice would be a soak four hours in — and because this subsystem fails by PAUSING, it would present as the soak going quiet rather than as an error. It is also precisely the shape of mistake that produced rev228: a path nobody exercised, shipped on the strength of reasoning about a path that was. TestRotatedSVIDIsPickedUpOverTheSelectorStream republishes every SVID under a new snapshot version — the same shape as the agent's SetSecrets, secrets only, so the listeners are not withdrawn — and requires that: - the destination verifies a different certificate SERIAL for the same SPIFFE ID (the SAN cannot change; that is what a rotation is); - it happens within a bound, not merely eventually; - cert_updated moves, read as a positive obligation; - every request throughout completes. A rotation that resolved correctly but stalled a request mid-flight is still a data-plane outage, and with this failure mode a stall is what it would look like. The identity is also statically referenced, as in the reproduction, because that is the shape of a real node and rotation has to work in it. Result: the rotated certificate is picked up on the FIRST post-rotation request, 4.7ms after publication, cert_updated 2 -> 4, SAN unchanged and serial changed. pre-rotation: SAN=spiffe://aether.internal/ns/demo/sa/source-a serial=...134652448 [sds-sotw] RESPOND count=1 version="2" rotated: generation 2 of every SVID published at snapshot version 2 post-rotation: SAN=spiffe://aether.internal/ns/demo/sa/source-a serial=...256300227 after 1 request(s) in 4.734934ms cert_updated: 2 -> 4 across the rotation --- PASS: TestRotatedSVIDIsPickedUpOverTheSelectorStream (0.16s) Proven non-vacuous: with the rotation call removed the test polls 78 times over 20s and fails on the serial assertion, so the gate bites rather than passing because nothing was ever checked. Mechanics: the destination now reports the verified leaf's SERIAL alongside its URI SAN, because a rotated SVID carries the same SPIFFE ID and the serial is the only thing that distinguishes "still using the certificate resolved at startup" from "picked up the new one". Secrets are generation-tagged so a re-issue lands on its own files — the resources are file data sources, and re-issuing over the same path would mutate what the previous generation pointed at and pass without anything having been delivered. The mesh cluster takes max_requests_per_connection: 1 in this test only, so the observation is the next request rather than whenever a pooled connection is reclaimed; a pooled connection legitimately keeps its certificate and that is not under test. Also documents in the runbook the hot-restart stat trap that produced the w05 anomaly: two live Envoy epochs both export, and when the parent's series goes away the summed GAUGE (cert_active) drops to the child's alone while the COUNTER (cert_requested) keeps the merged total, since StatMerger transfers gauges absolute and counters as deltas. w05's requested=55/active=28 looked like 27 secret removals and was nothing of the kind — consistent with cert_updated == 0, and no independent defect. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Update: SVID rotation gate added (was the last open gap), and the w05 anomaly is resolvedRotation over the selector's own stream — works, and is now gatedMoving the selector off
Picked up on the first post-rotation request, 4.7 ms after publication. Proven non-vacuous. With the rotation call removed, the test polls 78 times over 20 s and fails on the serial assertion: The identity is statically referenced here too, as in the reproduction, because that is the shape of a real node and rotation has to work in it. Three mechanics worth knowing, all commented at their call sites:
The w05 anomaly is resolved — and it is not an independent finding
with Corollary, now in the runbook: Record correctedThe Remaining unverifiedDown to one: stream count at fleet density. One SDS stream per originating identity is measured in a two-or-three-identity harness, not at talos-main's density, and neither is its Envoy RSS cost. Everything else in the earlier "before redeploying" list is now covered by a test. Verification re-run after these changes: |
…not the originator SDS version gauges (#992) (#1010) The per-connection cert selector's own SotW SDS stream (#865) re-serves an originating identity's secret on every snapshot bump, and Envoy keys SDS stats by secret name, so envoy_sds_*_version over-reads rotations ~50x for those identities. Name aether_agent_spire_svid_updates_total{update="rotated"} as the signal in the soak README and runbook, with the PromQL and the why. Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr Co-authored-by: Claude Fable 5.1 <[email protected]>
Reopens and fixes #842. Do not merge without a validation pass — see Before redeploying.
rev228 (
0.93.0-297db48) stopped every mesh upstream mTLS connection on talos-main within seconds of the new proxies taking the config, and rolled back at 16:13Z. This is the root cause, the fix, and the test that would have caught it.Root cause: the certificate selector fetched over
ads: {}agent/internal/xds/proxy/transportsocket.go:252,272(at297db48) passed the sameconfig.XDSConfigSourceADS()to both the transport socket andupstreamCertSelector.Envoy keys a secret provider on
hash(ConfigSource) + "." + name + warm(secret_manager_impl.h:90-91). The on-demand selector always asks withwarm=false(cert_selectors/on_demand/config.cc:15-26); every statically named SDS reference asks withwarm=true. One secret name therefore gets two independentSdsApiobjects with two independent watches — and on a node proxy that is the invariant case, not an edge case:DownstreamTransportSocket), anddefault_valueand itsprefetch_secret_names— by everyinboundready_<pod>probe cluster.The selector is always the second subscriber. On the delta-ADS mux the second watch loses: Envoy's
WatchMapdeduplicates subscription interest per(type_url, resource name)across watches, so it contributes nothing toresource_names_subscribe, no request goes out, and the control plane — correctly, for delta — resends nothing. The watch burns its 15 sinitial_fetch_timeout, and then nothing else happens:SdsApi::onConfigUpdateFailed(sds_api.cc:183-188) only callsinit_target_.ready(); it never notifies the parked certificate-selection callback.doSelectTlsContext'sPendingis never resolved.So the handshake is suspended, not failed — no
ssl_connection_error, nossl_fail_verify_san, an emptyupstream_transport_failure_reason,upstream_hostselected — until the clusterconnect_timeout, or until the downstream gives up first (DCat ~1980 ms).The fleet metrics said this, once read correctly
Queried over 16:00–16:20Z:
envoy_cluster_on_demand_secret_cert_requested_totalenvoy_cluster_on_demand_secret_cert_updated_totalenvoy_sds_spiffe_..._sa_aether_agent_init_fetch_timeout_total..._sa_prober_init_fetch_timeout_total..._sa_authz_canary_/..._sa_uds_client_init_fetch_timeout_totalTwo corrections to the issue's own framing:
cert_updateddoes exist. The deploy record concluded it did not; it was zero, and Envoy does not export a counter that never incremented. It is bumped only by the completion callback of the selector'ssetContext, reachable only from a secret actually arriving — so zero proves no SDS payload ever reached the selector. It is the only success signal the selector has.cert_requested == cert_activeis not a health signal.cert_activecounts live secret subscriptions and is incremented on the same line ascert_requested(config.cc:105-106); equality only means nothing was removed. It read equal on four of five nodes while the mesh was entirely down.The fix
One config source. The selector gets its own
api_config_sourcetoagent_xds— its own mux, its own watch map — so its subscription can no longer be deduplicated against a static one.SotW rather than delta on purpose: a SotW response carries every requested resource and
GrpcMuxImpl::addWatchqueues a request unconditionally, so the failure is structurally impossible on that stream even if a static reference ever lands on it. The agent already servesSecretDiscoveryServiceon the same socket as ADS (common/xds/xds.go:68), so there is no new bootstrap cluster and no new listener.Cost, measured rather than reasoned: Envoy builds a mux per non-ADS subscription, so this is one gRPC stream per secret name the selector resolves — per identity actually originating traffic on the node, lazily on first use, one resource each. Confirmed in the harness (streams 1, 2, 3, each with its own version/nonce sequence). The chart's
max_concurrent_streams: 10does not cap them: on an upstream cluster that field is what Envoy advertises for peer-initiated streams. The governing limit is the agent'sgrpc.MaxConcurrentStreams(1000).The zero-warm property is preserved
The thing #842 exists for, and the one measurement that passed on rev228 (a brand-new-ServiceAccount pod ADD warmed zero clusters, 120/120 samples across five nodes), is untouched. The selector's config source is a constant, so a mesh cluster's bytes still carry no workload input at all.
TestServiceClusterBytesChangeOnFirstAndLastPodOfServiceAccount,TestCachedMTLSClusterInvalidatedOnWorkloadChangeandTestNoNetnsPathInServiceClusterBytes— the inverted tests that pin it — are unchanged and green.The test that would have caught it
//test/mtlspoolproved pool partitioning against a real Envoy, but rewrote every SDS config source to a bespokeapi_config_sourcebecause it had no control plane. That substitution, documented as "the ONLY place the harness diverges from the config the agent emits", accidentally was the fix — which is why this passed review and CI.The harness now also runs the pinned proxy against a real delta-ADS control plane (go-control-plane over a Unix socket, serving CDS/LDS/SDS,
api_type: DELTA_GRPC,cds_config/lds_configads: {}), with the selector's config source left exactly as the agent emits it.TestOnDemandCertificateResolvesWhenAlreadyStaticallyReferencedadds the one ingredient the harness could not express: the source pod's SVID is referenced both ways, as on any real node. The assertion is completion within a bound, not the absence of errors — the absence of errors is the failure mode.Red against
297db48:Note what is absent: there is no third
SUBSCRIBE. The selector's request never reached the wire — which is the whole defect, and which no amount of control-plane-side logging would have revealed.Green with the fix, on a separate stream, in 10 ms:
Also added:
TestMeshCertSelectorSDSSourceIsNotSharedWithAnyStaticSecret(agent/internal/xds/proxy) — the separation checked from both ends, over every builder that names a secret statically. Pointing one at the selector's stream would put awarm=trueand awarm=falseprovider back on one mux and restore the starvation, silently.//test/envoy_validateasserts over the serialised node bootstrap that the selector does not rideads, that it names exactly one explicit gRPC source, and that the backing cluster resolves against a cluster the bootstrap defines — a dangling-reference check that the lazy on-demand subscription would otherwise hide fromenvoy --mode validate.SecretDiscoveryServicealongside ADS, as the agent does; andxdsTracelogs subscribe/respond on both transports, which is what distinguishes "Envoy never asked" from "the control plane never answered".docs/runbook.mdgains a "The rev228 outage" section under "#842" with the diagnosis order:cert_updatedflat whilecert_requestedclimbs →sds.<name>.init_fetch_timeout→/config_dump?resource=dynamic_warming_secrets.Verification
bazel test //...— 107/107 pass.bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...— clean.make deps-audit— OK, no new modules.make format,make gazelle— clean.0.93.0→0.93.1(theagent_xdscomment now documents both stream kinds and corrects themax_concurrent_streamsreading).Before redeploying
This has not been on a cluster; talos-main is on the rolled-back build with a soak pending. The harness reproduces the exact failure and the fix clears it against the pinned proxy, but two things are unverified on real hardware:
Suggested gate on redeploy: watch
envoy_cluster_on_demand_secret_cert_updated_totalbecome non-zero (that is the signal whose absence was the outage),envoy_sds_spiffe_*_init_fetch_timeout_totalstay flat, and re-run the new-ServiceAccount zero-warm sample to confirm the property survives.Finally:
AetherClusterIdentityNoMatch(k8s-talos-main GitOps #109) is still a vacuous gate from #863 and still needs repointing — unchanged by this PR.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Co-Authored-By: Claude Opus 5 [email protected]