Skip to content

fix(agent): key the per-source mTLS matcher by source SPIFFE ID, not netns path (#815, release 2/3) - #822

Merged
bpalermo merged 1 commit into
mainfrom
fix/815-release-two
Sep 19, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/815-release-two

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Release two of three for #815. Release one (#819 + #821) is live and validated on talos-main (helm rev224, 0.92.27-0f2b6c4). Deploy only on top of release one, with the live validation at the bottom.

The defect

Every local pod ADD/DEL rewrote every mesh cluster on the node: the per-source upstream-mTLS transport_socket_matcher keyed its exact_match_map on the source pod's netns path, unique per pod. Under delta xDS each rewritten EDS cluster re-warmed for the full 15 s EDS initial_fetch_timeout, and the warming→active swap destroyed the old ClusterEntry on every worker, draining every upstream connection pool on the node. Measured on talos-main rev224 (5 s resolution): one new pod → 20–24 clusters warming for 15 s; two on one node → 30 for 30 s; nodes with no new pod → 0. That handshake storm is the latency after a service roll and the 8-hour soak's largest error episode.

The change

The matcher always selected per ServiceAccount — the transport_socket_matches entry name is the SPIFFE ID — so keying the map by identity loses nothing and makes the Cluster proto byte-stable across pod churn within a ServiceAccount. Release one made every mesh-originating chain stamp aether.source.spiffe_id (shared_with_upstream: ONCE); this reads it. The FilterStateInput key becomes aether.source.spiffe_id, the map is keyed by source SPIFFE ID (sorted, de-duplicated), on_no_match stays the node identity. The listeners keep stamping BOTH keys — dropping the netns key is release three.

event before after
pod ADD/DEL, ServiceAccount already on the node every cluster re-warms 15 s nothing
rolling update, replacement lands on the same node every cluster, twice nothing
FIRST pod of a ServiceAccount arriving on a node / LAST one leaving every cluster every cluster, once
registry change to a cluster that cluster that cluster

So the svc-4 4 → 8 burst that measured 30 clusters for 30 s becomes zero; the soak's SHRINK (svc-5 to zero and back) still costs one re-warm per direction per node that held a pod, instead of one per pod.

Also fixed on the way: append(spiffeIDs, nodeSpiffeID) on a slice shared across every cluster on the node (a latent aliasing bug, safe only because len == cap in both callers) → withNodeIdentity() copies.

Upgrade order — read before deploying

Do not upgrade from a chart older than 0.92.27 straight to 0.92.28. LDS and CDS are separate delta-xDS responses with no ordering guarantee (the xDS server does not use ordered ADS), so a release-two cluster can briefly face a pre-release-one listener; that connection matches nothing, takes on_no_match and presents the node identity instead of the pod's — not a drop, but visible to inbound RBAC / ext_authz / peer-identity checks. talos-main is on release one, so it is safe; fresh installs are unaffected. Recorded in the chart NOTES.txt, docs/runbook.md and the contract comment on the constants. Long-lived connections accepted before the key existed cannot survive: release one changed every originating filter chain (Envoy replaces and drains them within --drain-time-s = 10 s here), and talos-main has since done a full proxy roll.

Safety also rests on connection_pool_per_downstream_connection: true on node service clusters (already the case for the netns key): set_filter_state's envoy.string object is not Hashable, so it is not part of the upstream pool key — with shared pools a second downstream connection could inherit the first one's client certificate. Now documented as an invariant.

Observability (chart 0.92.28)

A stats_tags entry lifts the per-match counter's SPIFFE ID into aether.transport_socket_match, so it exports as one envoy_cluster_total_match_count{aether_cluster, aether_transport_socket_match} family instead of one metric name per ServiceAccount. on_no_match increments the named socket's counter (never default), and the node identity is reachable only through on_no_match, so aether_transport_socket_match=~"spiffe://[^/]+/node/.*" rising with the connection rate on a mesh service cluster is the "connection did not carry the key" signal (it has a small EDS-driven floor: host construction resolves once with no options). Also fixes a dead exclusion alternative (default_total_match → default\.total_match) in the per-pod probe-cluster patterns.

Rejected: keeping a departed ServiceAccount's entry for a grace period

It would spare scale-to-zero-and-back, but the entry names an SDS secret the agent stops serving. Delta SDS keeps the last secret on removal; a new Envoy epoch after a hot restart would not, so every service cluster would warm to its SDS initial_fetch_timeout on every proxy roll and come up upstream_context_secrets_not_ready — the same defect on a worse path, and serving a departed workload's key is a security regression.

Tests

TestLocalPodChurnRewritesEveryServiceCluster is replaced by its inverse TestServiceClusterBytesStableWithinServiceAccount (sha256 over the exact bytes go-control-plane hashes), plus TestServiceClusterBytesChangeOnFirstAndLastPodOfServiceAccount (non-vacuity), TestNoNetnsPathInServiceClusterBytes (wire-bytes scan, reaches inside typed_config Anys), TestServiceClusterBytesUnaffectedByPodChurnWithSpireOff, TestClusterMatcherKeyedOnSourceIdentity, TestClusterMatcherIsOrderIndependent. The stock-Envoy gate now validates a service cluster with the one-level matcher and two local ServiceAccounts; the chart's rendered bootstrap was validated by hand with the pinned Envoy. 17/17 targets, --config=race ×3 clean, lint clean.

Not covered by any test: envoy --mode validate does not check stats_tags regexes (a deliberately broken one still validated), and total_match_count has never been observed in this mesh — both are live-validation items.

Live validation required

  1. Same-ServiceAccount pod ADD: envoy_cluster_manager_warming_clusters at a 5 s step stays 0 on every node (release one: 20–30 for 15 s).
  2. First pod of a brand-new ServiceAccount on a node: exactly one re-warm wave on that node; removal: one more; nothing elsewhere.
  3. The no-match series EXISTS and stays at its floor; pod→pod traffic arrives with spiffe://…/ns/<ns>/sa/<sa> on the destination side — a single workload request carrying the NODE identity is a STOP.
  4. Prober perfect zero across an agent roll, a proxy roll and a service Deployment roll (the one that used to show the excursion 15 s later).
  5. The SHRINK scenario re-measured (svc-5 → 0 → 4).
  6. No CDS/LDS NACK, no proxy restart, and the new stats_tags regex behaves on the first proxy.

Refs #815.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…netns path (#815, release 2/3)

Every local pod ADD/DEL rewrote EVERY mesh cluster on the node. The per-source
upstream-mTLS transport_socket_matcher keyed its exact_match_map on the source
pod's netns path, which is unique per pod, so one unrelated CNI ADD changed a
field of every service cluster. Under delta-xDS each rewritten EDS cluster then
re-warmed for the full 15 s EDS initial_fetch_timeout (delta sends no EDS
request for a name the old cluster already watches), and the warming->active
swap destroyed the old ClusterEntry on every worker, draining every upstream
connection pool on the node. Measured on talos-main rev224: one new pod -> 20-24
clusters warming for 15 s, two -> 30 for 30 s, nodes with no new pod -> 0. That
handshake storm is the latency after a service roll and cost an 8 h soak its
largest error episode.

The matcher always SELECTED per-ServiceAccount -- the transport_socket_matches
entry name is the SPIFFE ID -- so keying the map by identity loses nothing and
makes the Cluster proto byte-stable across pod churn within a ServiceAccount.
Release one (#819/#821) made every mesh-originating chain stamp
aether.source.spiffe_id; this reads it. Only the first pod of a ServiceAccount
arriving on a node, or the last one leaving, changes a cluster now.

The matcher, the matches and the identity set all derive from one sorted,
deduplicated identity list, so nothing is a function of map-iteration order.
The netns->identity index stays in c.localWorkloads for the #638 discriminator;
nothing in the Cluster proto is keyed by netns any more.

UPGRADE ORDER: a proxy must run release-one listeners before it is handed
release-two clusters. LDS and CDS are separate xDS responses with no ordering
guarantee, so a release-two cluster facing a pre-#819 listener matches nothing,
takes on_no_match and presents the node identity. Going from a chart older than
0.92.27 straight to 0.92.28 is therefore unsupported. Recorded in the chart
NOTES, docs/runbook.md section 7, and the constants' contract comment.

SA-entry stickiness (keeping a departed ServiceAccount's entry for a grace
period, to spare the scale-to-zero case) was evaluated and rejected: the
retained entry would name an SDS secret the agent stops serving, which a NEW
Envoy epoch would warm on until initial_fetch_timeout and then come up with
upstream_context_secrets_not_ready -- the same defect on the proxy-roll path.
The entry is also unreachable while retained, since no listener stamps a
departed pod's identity. Reasoning is in the runbook.

Observability: the chart lifts the per-match counter's SPIFFE ID into the
aether.transport_socket_match tag, so it exports as one
envoy_cluster_total_match_count family instead of one metric NAME per
ServiceAccount. on_no_match increments the NAMED socket's counter, never
`default`, so a rising spiffe://<td>/node/... on a service cluster is the
"connection did not carry the key" signal. Also fixes the health_/inboundready_
exclusion alternative, which said default_total_match and therefore matched
nothing -- the stat is default.total_match_count.

Tests: TestLocalPodChurnRewritesEveryServiceCluster is replaced by its inverse,
TestServiceClusterBytesStableWithinServiceAccount, plus
TestServiceClusterBytesChangeOnFirstAndLastPodOfServiceAccount (the events that
still cost a re-warm, reversibly), TestNoNetnsPathInServiceClusterBytes (a wire
scan of the serialized cluster, which reaches inside typed_config Anys),
TestServiceClusterBytesUnaffectedByPodChurnWithSpireOff, and in the proxy
package TestClusterMatcherKeyedOnSourceIdentity and
TestClusterMatcherIsOrderIndependent. The stock-Envoy gate now validates a
service cluster carrying the one-level matcher with two local ServiceAccounts.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit e4af095 into main Sep 19, 2026
20 checks passed
@bpalermo
bpalermo deleted the fix/815-release-two branch September 19, 2026 20:25
bpalermo added a commit that referenced this pull request Sep 19, 2026
…d the wrong node identity (#815) (#825)

The query shipped with #822 returns a FALSE ZERO on a live cluster, twice over
(caught during the rev225 validation by a Prometheus check from the platform side):

- the family is `envoy_cluster_match_count_total` — Prometheus' OTLP ingest moves
  "total" to the end; `envoy_cluster_total_match_count` does not exist;
- on a node agent the matcher's `on_no_match` identity is the AGENT'S OWN SVID
  (`spiffe://<td>/ns/aether-system/sa/aether-agent`), not
  `spiffe://<td>/node/<node>`, so the `/node/` selector matches nothing.

Runbook: corrected query (by node and cluster), what healthy looks like (0 over a
quiet window; during a pod ADD the increments sit entirely on that service's own
cluster), and where to read the identity from (`served node SVID`). It also claimed
a destination-side access-log cross-check that does not exist — the OTLP access log
has no peer-identity field (#824); say so and name the weaker substitutes.
Chart 0.92.29: the same two facts in the stats_tags comment (comment only).


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

Co-authored-by: Claude Fable 5.1 <[email protected]>
bpalermo added a commit that referenced this pull request Sep 19, 2026
…n the listeners (#826)

Release three was planned as "drop aether.network.network_namespace from the
listeners". Evaluated against the code and against Envoy 1.40.0-dev, it is a net
loss, so this closes it as a decision rather than implementing it.

Why it buys almost nothing. On a LISTENER the netns entry carries no per-pod
state — its value is the constant format string
%FILTER_STATE(envoy.network.network_namespace:PLAIN)%, byte-identical on every
chain of every pod. The churn #815 was about lived entirely in the CLUSTER
matcher, which release two (#822) already fixed. Deleting the entry saves one
set_filter_state filter, ~240 bytes per mesh-originating filter chain (~0.5-1 KB
per pod), plus one format-string evaluation per new downstream connection.

Why it costs more than that:

  - Rollback, permanently. While the listeners stamp BOTH keys a proxy matches
    correctly against clusters from either side of release two, so a downgrade
    below 0.92.28 is hitless — which this issue needed once already (release one
    was rolled back on talos-main on 2026-09-19). Stamping only the SPIFFE ID
    would make 0.92.28 a permanent floor: a release-three listener facing a
    pre-release-two netns-keyed cluster matches nothing, takes on_no_match, and
    presents the agent's own SVID (spiffe://<td>/ns/aether-system/sa/aether-agent
    — not spiffe://<td>/node/<node>, see #825).
  - Another deploy that re-keys every per-pod filter chain, draining every mesh
    pod's chains a second time.
  - An access-log migration. accesslog.go's source_netns is the netns copy's only
    remaining reader.

The Envoy facts, read from source at 13144fb (1.40.0-dev): the native object
envoy.network.network_namespace does exist, is set in the ActiveTcpSocket
constructor at accept time for any listener whose address carries a
network_namespace_filepath (all per-pod listeners here do), is
LifeSpan::Connection, and is PLAIN-formattable — so an HCM access log can read
it directly and the aether copy is not needed for logging. It is
StreamSharing::None, which is why the copy existed at all: only a
shared_with_upstream copy could reach the cluster transport-socket matcher. The
catch for a future migration is that the native object is the netns the LISTENER
is bound in, so on the inbound listener it is the DESTINATION pod's netns; a
field still called source_netns would be wrong and should be renamed.

Recorded in the two places that carry the contract: the comment on
sourceIdentityFilterStateKey and docs/runbook.md's version-ordering section. The
chart NOTES.txt needs no change — it never promised a release three — so no
chart version bump.

If a later change is already re-keying these chains (#824's source-side
peer-identity field is the obvious candidate), fold the removal into it then.

Refs #815, #824.


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

Development

Successfully merging this pull request may close these issues.

1 participant