Skip to content

feat(agent): log outbound identity bindings on change and flag foreign-identity binds (#638) - #686

Merged
bpalermo merged 2 commits into
mainfrom
fix/638-outbound-binding-discriminator
Sep 5, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/638-outbound-binding-discriminator

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Discriminator 1 from #638: make the source-side identity binding observable, so the next soak can confirm or kill the hypothesis rather than reasoning about it after the fact.

The hypothesis under test

During proxy startup an outbound cluster serving requests from pod A is briefly handed the client-cert SDS secret of co-located pod B, until the next snapshot push re-binds it. The 4.25s / 14.7s / 5.29s burst durations are the time-to-next-push, not a timeout.

What reading the generator already settles

The binding is not per-cluster, and the secret name is not independently chosen.

Every mTLS-injected outbound cluster gets the same two pieces of config from proxy.InjectUpstreamMTLS:

  1. transport_socket_matches — one entry per unique local SPIFFE ID (plus the node identity), named by that SPIFFE ID, whose transport socket fetches the SDS secret of the same name (upstreamTransportSocketMatchesNamed passes id as both the match name and tlsCertificateSecretName).
  2. transport_socket_matcher — an exact_match_map from the source pod's netns (the aether.network.network_namespace filter state, SharedWithUpstream: ONCE) to one of those names, built from c.localWorkloads.

So:

  • "A cluster's match presents a secret it is not named for" is structurally impossible — the socket name and the SDS name are the same Go string. The literal mismatch the issue asked for cannot be constructed at transportsocketmatch.go:89.
  • The whole (source pod → cluster → secret) binding collapses to one node-wide index: localWorkloads[netns] → SPIFFE ID. It is byte-identical on every outbound cluster on the node.

That second point is itself evidence: it is exactly the field fingerprint. One wrong identity presented toward five distinct clusters within one time slice, "a node-wide constant per time slice, not per-endpoint", is what a wrong entry in this single index looks like. A per-cluster or per-endpoint SDS bug could not produce it.

Where the defect can therefore actually live

The index, not the naming:

  • c.localWorkloads (guarded by localMu) and c.listeners (guarded by listenerMu) are written non-atomically on the add path (AddPod: listener entry, then setLocalWorkload), on the remove path (RemovePod: delete listener, then removeLocalWorkload), and are merged separately again by LoadListenersFromStorage at agent start — the startup window this defect fires in.
  • The key is the pod's network-namespace path, which the kubelet/CNI reuses. A missed or late CNI DEL leaves a departed pod's identity bound to a netns path a new pod may already be stamping onto its connections. The new pod then presents the departed, co-located workload's SVID until the next write lands — which is precisely "duration = time to next push", and precisely "the wrong identity is always a real, co-located workload's SVID, never garbage".

The log line goes at that seam.

What lands

agent/internal/xds/cache/identitybinding.go, called from generateSnapshot after a successful SetSnapshot, so a logged binding is one Envoy actually received:

  • INFO outbound identity binding — source_pod, source_netns, source_spiffe_id (the identity the cluster will present), pod_spiffe_id (what the owning pod is entitled to, so one line is self-diagnosing), cluster, secret, snapshot_version. Emitted only when that (source pod, cluster) pair changed since the previous snapshot, or on first sight. Steady state is completely silent; the diff is O(pods + clusters) with no cross product unless something moved.
  • WARN outbound cluster bound to a foreign identity + the new nil-safe OTel counter aether.agent.identity.outbound_binding_mismatch — when the bound secret is not the SPIFFE ID derived from the pod that owns that netns (proxy.SpiffeIDFromPod over the listener entry's own CNIPod, the API-server-derived truth per security: aether.io/spiffe-id pod annotation is an unvalidated mesh-identity override #669). Fires on the edge only: mismatch status is a function of the binding, so it is reported once per state, never once per snapshot.
  • WARN outbound identity mapping has no owning pod — the other index failure: an identity mapping whose netns no listener entry owns any more, still selectable by whatever stamps that netns next. Not counted as a foreign bind (there is no owning pod to compare against).
  • Rate guard — above 200 changed pairs in one snapshot (a cold start binds every pod × every cluster) a single INFO outbound identity bindings changed carries the count and the distinct source→identity transitions instead. Only the per-cluster repetition is dropped, and that repetition is redundant by construction.

What the line proves or refutes

  • A WARN at 06:07:0x, seconds before or inside the ssl_fail_verify_san burst, naming a co-located workload's SVID against a source pod: the hypothesis is confirmed and the bug is the agent-side netns→identity index, with the offending snapshot_version and the exact pod pair in hand.
  • INFO change lines but no WARN in that window: the index was consistent while it re-bound; the burst is a plain re-bind of a legitimate identity (e.g. the source pod's own SVID arriving late), which points at the ordering of the secret push versus the cluster push, not at cross-wiring.
  • Nothing at all across a window that did produce SAN failures: the agent's outbound binding was static and correct throughout. That falsifies the source-side hypothesis and moves the search to the destination proxy's inbound chain selection — worth stating plainly, because cluster.ssl.fail_verify_san is a client-side counter about the server's certificate, and upstream_transport_failure_reason=CERTIFICATE_VERIFY_FAILED is the client rejecting the peer. The inbound path picks its cert directly off each pod's own CNIPod (ingress.go:75) with no index in between, so if the next run shows no agent-side WARN, the remaining candidate is which pod's inbound filter chain a connection lands on during the startup window.

Grep recipe

# Every re-bind on one node around the roll.
kubectl -n aether-system logs ds/aether-agent --since=10m \
  | grep -E 'outbound identity (binding|bindings changed|mapping)|foreign identity'

# The alarm, in VictoriaLogs (field syntax; never `| stats`, it false-zeroes).
_stream:{k8s_container_name="agent"} AND "outbound cluster bound to a foreign identity"

# As a counter: zero at steady state, any increase is the defect.
sum by (k8s_node_name) (aether_agent_identity_outbound_binding_mismatch_total)

Then join the WARN's snapshot_version against the first envoy_cluster_ssl_fail_verify_san_total sample of that proxy generation (max_over_time[6h] on a 60s step — an instant query ages the series out).

Also documented in docs/runbook.md § 8.

Tests

agent/internal/xds/cache/identitybinding_test.go (5 cases): first sight emits exactly one line then repeated snapshots emit nothing; a legitimate re-bind emits exactly one change line and no WARN or counter; a constructed foreign binding emits the WARN with both identities and increments the counter exactly once, staying quiet while the mismatch persists; an orphaned mapping WARNs without counting; and 201 pairs collapse to one summary carrying the transitions.

//agent/internal/xds/ack:ack_test                         PASSED
//agent/internal/xds/cache:cache_test                     PASSED
//agent/internal/xds/cache/cachemetrics:cachemetrics_test PASSED
//agent/internal/xds/cache/snapversion:snapversion_test   PASSED
//agent/internal/xds/config:config_test                   PASSED
//agent/internal/xds/proxy:proxy_test                     PASSED
//agent/internal/xds/server:server_integration_test       PASSED
//agent/internal/xds/server:server_test                   PASSED

bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //agent/internal/xds/... clean (gocognit included). No charts/ change, so no chart bump.

Refs #638

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits September 5, 2026 09:53
…n-identity binds (#638)

The #638 discriminator: make the source-side (source pod -> outbound cluster
-> SDS client-cert secret) binding observable, so the next soak can confirm or
kill the "a fresh proxy briefly presents a co-located pod's SVID" hypothesis.

Reading the generator settles part of the question up front. Every mTLS-injected
outbound cluster carries the SAME two things (proxy.InjectUpstreamMTLS): one
transport_socket_match per unique local SPIFFE ID, NAMED by that SPIFFE ID and
fetching the SDS secret of the same name, and a matcher from the source pod's
netns to one of those names built from c.localWorkloads. Socket name and secret
name are literally the same string, so "this match presents a secret it is not
named for" is structurally impossible, and the binding is node-wide identical
across clusters -- exactly the shape the field data shows.

What CAN go wrong is the netns -> SPIFFE ID index itself: localWorkloads
(localMu) and listeners (listenerMu) are written non-atomically on the add path,
the remove path and the storage merge, and the key is a netns PATH the CNI
reuses. So the log line goes at that seam, cross-checked against the pod that
actually owns the netns (proxy.SpiffeIDFromPod over the listener's own CNIPod).

- INFO "outbound identity binding" per (source pod, cluster), emitted only on a
  change or first sight, so steady state is silent; above 200 changed pairs in
  one snapshot a single summary keeps the distinct source->identity transitions.
- WARN "outbound cluster bound to a foreign identity" + the new counter
  aether.agent.identity.outbound_binding_mismatch when the bound secret is not
  the owning pod's own SPIFFE ID; WARN "outbound identity mapping has no owning
  pod" for an orphaned mapping (missed CNI DEL).
- Runbook section with the grep/LogsQL/PromQL recipe for a soak window.

Refs #638

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit e477759 into main Sep 5, 2026
16 checks passed
@bpalermo
bpalermo deleted the fix/638-outbound-binding-discriminator branch September 5, 2026 13:01
bpalermo added a commit that referenced this pull request Sep 5, 2026
… zero) (#693)

The § 8 recipe selected `_stream:{k8s_container_name="agent"}`, which matches
no stream on this cluster: the stream labels are the dotted OTel resource
fields (service.name, k8s.pod.name, k8s.namespace.name). As written, the
foreign-identity alarm query returned zero rows on a run where the lines
existed. Found by the rev193 validation of #686.


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 5, 2026
)

Envoy's SAN-matcher failure prints the SANs of the certificate being
VALIDATED — the PEER's — so ssl_fail_verify_san is a CLIENT-side counter
about the SERVER's certificate. Inverted, the wrong identity in a #638
event belongs to a server cert: the inbound filter chain → SDS
server-secret binding of the proxy that TERMINATED the connection.
#686's outbound check watches the client side and cannot fire for it.

On every snapshot the agent now reads each local pod's inbound listener
back out of the snapshot it just handed Envoy, extracts each chain's
DownstreamTlsContext server-cert secret name, and compares it with the
SPIFFE ID of the pod that listener entry belongs to:

  - INFO  "inbound identity binding" on a first bind or a change
  - WARN  "inbound chain bound to a foreign identity" + the counter
          aether.agent.identity.inbound_binding_mismatch
  - WARN  "inbound chain references a secret absent from the snapshot"
          (the chain reached Envoy before its own SVID)
  - a summary line above 200 changed chains in one snapshot

The binding holds by construction inside proxy.NewInboundListener, which
is the point: a counter that stays 0 through a #638 event, with INFO
lines showing correct re-binds, moves the defect out of the agent's
snapshot and into Envoy's SDS/secret lifecycle across the hot restart.

Fail-open: observes after SetSnapshot, never blocks or alters it.

docs/runbook.md gains the attribution recipe for the ledger join —
upstream_host → pod → node vs. the node whose proxy was restarting, with
the documented false-zero traps (LogsQL field syntax, max_over_time).


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 5, 2026
… absence is not a false zero (#638) (#717)

The OTel SDK exports a counter only after its first Add. Both discriminator
counters (outbound #686, inbound #715) are never incremented in the healthy
case, so neither series existed in Prometheus on talos-main rev200 and a
grading increase() would return no data, indistinguishable from zero. Seed
both at process start; test pins it.


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
…on on inbound mTLS readiness (#815)

Release ONE of the two-release fix for #815. Listeners change; clusters do not.

Part A — every chain that can originate mesh traffic now sets a SECOND
filter-state object, `aether.source.spiffe_id`, carrying the source pod's
SPIFFE ID as a literal, alongside the existing `aether.network.network_namespace`
key. Same `shared_with_upstream: ONCE` semantics, because it is destined for the
same consumer: the cluster transport-socket matcher reads both through
`TransportSocketOptions::downstreamSharedFilterStateObjects()`.

The matcher is NOT changed — clusters stay byte-identical, asserted by
TestClusterMatcherStillKeyedOnNetns and the per-pod half of
TestLocalPodChurnRewritesEveryServiceCluster. Release two flips the matcher's
FilterStateInput to the new key, which makes the Cluster proto byte-stable
across pod churn and ends the 15s node-wide EDS re-warm + pool drain that one
CNI ADD currently costs. Doing both in one step would leave a cluster with the
new input facing a listener with only the old key falling to OnNoMatch = the
node identity = the wrong client certificate (#686). The old key can only be
removed in a THIRD release, for the mirror-image reason. Contract documented at
the constant.

Chains stamping both keys: per-pod outbound HTTP, capture HCM, capture TCP
floor, capture TCPRoute weighted floor, capture TLSRoute SNI. The ORIGINAL_DST
passthrough chain stamps neither (plaintext, selects no certificate) and the UDP
capture listener has no filter chains at all.

Part B — a second per-pod probe cluster, `inboundready_<pod>`, closes the
promotion hole. `health_<pod>` dials the application in cleartext and has no SDS
dependency, while the pod's inbound listener does not listen() until its SVID
arrives, so an endpoint could be advertised HEALTHY while its mesh port refused
connections (promotion p50 5.8s vs SVID 6.1-8.4s; one pod promoted in <=0.5s).

The new cluster runs a connect-only TCP health check over an mTLS
UpstreamTlsContext against the pod's own 127.0.0.1:18008 in its netns, ALPN h2 /
no SNI so it lands on the always-present no-SNI inbound chain, client cert = the
node SVID, peer pinned to exactly the pod's SPIFFE ID. Envoy raises Connected
only after the TLS handshake, so a pass means "listening, has this pod's
certificate, and it verifies as this pod". Inbound validation is untouched: it
already requires a client certificate and validates the trust-domain bundle with
no SAN restriction, so the node identity is accepted as-is.

The gateway filter for the pod requires both clusters; the gateway PATH is
unchanged, so the liveness loop and health client are untouched. The probe is
not emitted with SPIRE off (cleartext inbound: nothing to prove) or before the
node SVID lands (no client certificate) — those pods keep exactly the previous
single-cluster gate, so SPIRE-off snapshots are unchanged.

The main risk is the other direction: a new Envoy epoch starts every host failed
and must re-fetch each pod's SDS secret, so a proxy roll would otherwise demote
every pod on the node. The existing warm-up grace does not cover it (it only
applies to pods that never served). Two guards: a previously-serving pod is
demoted only after 3 consecutive failing observations (15s), and any tick that
could not reach the gateway re-arms the full warm-up grace on the next tick that
can. Cost: a genuinely dead app is demoted ~10s later; fast local detection is
outlier detection, which is unaffected.

Per-pod probe clusters use a plain UpstreamTlsContext, never the per-source
matcher, so adding one does not perturb any other cluster's bytes.

Also: extend the chart's stats exclusions to the new prefix while keeping
membership_* (the health_check filter READS those gauges) and ssl.* (the direct
read-out of why a pod is stuck un-promoted) readable; runbook section on what
HEALTHY now means and how to read a stuck pod; amendment on proposal 004.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
bpalermo added a commit that referenced this pull request Sep 19, 2026
…ires an mTLS handshake with the pod's inbound listener (#815, release 1/3) (#819)

* test(xds/cache): pin the delta-xDS no-op push, characterise pod-churn CDS blast radius

Two tests, no production change, written while investigating the suspected
"inbound listener published before its SDS secret" ordering defect.

TestSnapshotRegenerationIsANoOpPush pins the steady-state half of the #135
invariant that determinism_test.go only covers across independent builds:
regenerating with unchanged inputs must be byte-identical, because the agent
pushes a full snapshot per event (~9/node/minute measured during a soak
scale-up) and every one of those is free only while unchanged config hashes
unchanged.

TestLocalPodChurnRewritesEveryServiceCluster records what one pod's lifecycle
actually costs the node's CDS set. Every mesh service cluster carries a
per-source upstream-mTLS matcher whose exact_match_map is keyed by the source
pod's netns path, so one pod arriving or leaving rewrites EVERY service cluster
the node holds - measured here as 9 of 9, independent of any routing
relationship to that pod. The DEL restores the pre-ADD bytes exactly, so
create/destroy is a round trip rather than a ratchet; both halves are asserted.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

* feat(agent): stamp the source SPIFFE ID in filter state, gate promotion on inbound mTLS readiness (#815)

Release ONE of the two-release fix for #815. Listeners change; clusters do not.

Part A — every chain that can originate mesh traffic now sets a SECOND
filter-state object, `aether.source.spiffe_id`, carrying the source pod's
SPIFFE ID as a literal, alongside the existing `aether.network.network_namespace`
key. Same `shared_with_upstream: ONCE` semantics, because it is destined for the
same consumer: the cluster transport-socket matcher reads both through
`TransportSocketOptions::downstreamSharedFilterStateObjects()`.

The matcher is NOT changed — clusters stay byte-identical, asserted by
TestClusterMatcherStillKeyedOnNetns and the per-pod half of
TestLocalPodChurnRewritesEveryServiceCluster. Release two flips the matcher's
FilterStateInput to the new key, which makes the Cluster proto byte-stable
across pod churn and ends the 15s node-wide EDS re-warm + pool drain that one
CNI ADD currently costs. Doing both in one step would leave a cluster with the
new input facing a listener with only the old key falling to OnNoMatch = the
node identity = the wrong client certificate (#686). The old key can only be
removed in a THIRD release, for the mirror-image reason. Contract documented at
the constant.

Chains stamping both keys: per-pod outbound HTTP, capture HCM, capture TCP
floor, capture TCPRoute weighted floor, capture TLSRoute SNI. The ORIGINAL_DST
passthrough chain stamps neither (plaintext, selects no certificate) and the UDP
capture listener has no filter chains at all.

Part B — a second per-pod probe cluster, `inboundready_<pod>`, closes the
promotion hole. `health_<pod>` dials the application in cleartext and has no SDS
dependency, while the pod's inbound listener does not listen() until its SVID
arrives, so an endpoint could be advertised HEALTHY while its mesh port refused
connections (promotion p50 5.8s vs SVID 6.1-8.4s; one pod promoted in <=0.5s).

The new cluster runs a connect-only TCP health check over an mTLS
UpstreamTlsContext against the pod's own 127.0.0.1:18008 in its netns, ALPN h2 /
no SNI so it lands on the always-present no-SNI inbound chain, client cert = the
node SVID, peer pinned to exactly the pod's SPIFFE ID. Envoy raises Connected
only after the TLS handshake, so a pass means "listening, has this pod's
certificate, and it verifies as this pod". Inbound validation is untouched: it
already requires a client certificate and validates the trust-domain bundle with
no SAN restriction, so the node identity is accepted as-is.

The gateway filter for the pod requires both clusters; the gateway PATH is
unchanged, so the liveness loop and health client are untouched. The probe is
not emitted with SPIRE off (cleartext inbound: nothing to prove) or before the
node SVID lands (no client certificate) — those pods keep exactly the previous
single-cluster gate, so SPIRE-off snapshots are unchanged.

The main risk is the other direction: a new Envoy epoch starts every host failed
and must re-fetch each pod's SDS secret, so a proxy roll would otherwise demote
every pod on the node. The existing warm-up grace does not cover it (it only
applies to pods that never served). Two guards: a previously-serving pod is
demoted only after 3 consecutive failing observations (15s), and any tick that
could not reach the gateway re-arms the full warm-up grace on the next tick that
can. Cost: a genuinely dead app is demoted ~10s later; fast local detection is
outlier detection, which is unaffected.

Per-pod probe clusters use a plain UpstreamTlsContext, never the per-source
matcher, so adding one does not perturb any other cluster's bytes.

Also: extend the chart's stats exclusions to the new prefix while keeping
membership_* (the health_check filter READS those gauges) and ssl.* (the direct
read-out of why a pod is stuck un-promoted) readable; runbook section on what
HEALTHY now means and how to read a stuck pod; amendment on proposal 004.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

---------

Co-authored-by: Claude Fable 5.1 <[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