Skip to content

feat(agent): add the inbound identity-binding discriminator (#638) - #715

Merged
bpalermo merged 2 commits into
mainfrom
feat/638-inbound-identity-discriminator
Sep 5, 2026
Merged

bpalermo merged 2 commits into
mainfrom
feat/638-inbound-identity-discriminator

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 5, 2026

Copy link
Copy Markdown
Owner

The inversion, in three lines

Envoy's default_validator.cc:332 prints verify cert failed: SAN matcher, certificate SANs are [...] for the certificate it is validating — the one the peer presented.
So envoy_cluster_ssl_fail_verify_san_total is a client-side counter about the server's certificate, and every #638 ledger join read it backwards.
The mis-bound identity is therefore a server cert: the inbound filter chain → SDS server-secret binding of whichever proxy terminated the connection (for same-node traffic, the restarting proxy itself) — which is exactly the observed "node-wide constant per time slice" shape, and which #686's client-side check structurally cannot see.

What lands

agent/internal/xds/cache/inboundidentitybinding.go, called from generateSnapshot after a successful SetSnapshot, so a logged binding is one Envoy actually received. Per snapshot it reads each local pod's inbound listener back out of the proto, pulls each chain's DownstreamTlsContext.tls_certificate_sds_secret_configs[0].name, and compares it with proxy.SpiffeIDFromPod over the CNIPod that listener entry belongs to:

  • INFO inbound identity binding — chain (<listener>/<chain>), pod, pod_spiffe_id, secret (what the chain will present), previous_secret (empty on a first bind), secret_served, snapshot_version. Edge-triggered: first bind or change only, steady state is silent.
  • WARN inbound chain bound to a foreign identity + the new nil-safe counter aether.agent.identity.inbound_binding_mismatch (exported as aether_agent_identity_inbound_binding_mismatch_total) — the node would terminate mesh mTLS for this pod while presenting a co-located workload's SVID. Reported on the edge, so a persistent mismatch is counted once per state.
  • WARN inbound chain references a secret absent from the snapshot — the chain reached Envoy before its own SVID did. That is the other candidate mechanism named in the issue ("a chain that exists before its own secret has landed may fall back to the default/first secret"). Reported, not counted: it is not a foreign bind.
  • Rate guard — above 200 changed chains in one snapshot a single inbound identity bindings changed summary carries the distinct pod→identity transitions instead.

Cleartext (SPIRE off) chains carry no transport socket and are skipped — no certificate to bind or mis-bind. Fail-open throughout: it observes the snapshot and never blocks, alters or delays it.

Does the invariant hold by construction?

Yes, inside one build. proxy.NewInboundListener (ingress.go) derives the chain's server-cert SDS name from the same *cniv1.CNIPod it names the listener and chains after, so a Go-level mismatch cannot be constructed there.

The check is still worth having, and is stated that way in the code, because it does not read that Go string — it reads the emitted proto and joins it against the pod recorded as owning the entry. That catches what construction cannot rule out: a listener entry rebuilt from, or left behind by, a different pod than the one now owning the netns (netns reuse after a missed CNI DEL — the same substrate #686 documents for the outbound index), a rebuild path (gamma.go, l4route.go, capture.go, udspolicy.go) re-generating from the wrong entry, and the unserved-secret window above.

What it proves either way

  • Counter increments during a Transient cross-service mTLS identity mis-binding during concurrent proxy-restart + service roll (failed closed) #638 event → the mis-binding is in the agent's snapshot; the WARN names the pod, both identities and the snapshot_version.
  • Counter stays 0 across an event while the INFO lines show the chains re-binding correctly → the agent's snapshot was right, and the defect is in Envoy's SDS/secret lifecycle across the hot restart. That is a decisive negative: it closes the agent-side line of enquiry, which is what the last four ledger joins could not do.
  • inbound chain references a secret absent from the snapshot in the burst window → the chain-before-its-SVID ordering is real and is the first thing to fix.

Attribution recipe

docs/runbook.md gains a section next to the existing #638/outbound material: the LogsQL to pull the events (_stream:{service.name="aether-proxy"} + log_name:aether_access_logs AND upstream_transport_failure_reason:"CERTIFICATE_VERIFY_FAILED", field syntax only), the upstream_host → pod → node join that produces the terminating-node column the issue asks for, and the comparison against envoy_server_hot_restart_epoch for the node whose proxy was restarting — with the documented false-zero traps called out (never | stats, never an instant query on a series that ages out with the proxy generation, max_over_time mandatory, control-test every negative).

Validated

  • New unit tests in agent/internal/xds/cache/inboundidentitybinding_test.go: first sight names every chain then goes silent; a legitimate re-bind logs the transition and is not a mismatch; a listener built for a co-located workload while the entry belongs to another pod WARNs and increments the counter (and is not re-counted while it persists); an unserved secret WARNs but is not counted, and clears when the SVID lands; cleartext emits nothing; the rate guard summarises.
  • bazel test --test_arg=-test.short //agent/... — 34/34 pass.
  • make gazelle, make format-check, bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation on the touched packages — clean (gocognit gate included).
  • No chart change: no new flag, the discriminator is unconditional.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits September 5, 2026 18:26
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).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 7a19ebf into main Sep 5, 2026
16 checks passed
@bpalermo
bpalermo deleted the feat/638-inbound-identity-discriminator branch September 5, 2026 21:33
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 7, 2026
) (#741)

Agent startup no longer exits when SPIRE is not serving yet. The one-shot,
fatal `commonspire.NewSource` (25s bound, #668) is replaced by a
`WaitingSource` runnable that retries forever with bounded, jittered backoff,
serves `ErrNoSVIDYet` meanwhile, and announces the wait at INFO with
attempt/elapsed — escalating to WARN after `--spire-wait-warn-after` (2m).

Everything downstream already tolerated a late identity: the SDS bridge dials
lazily and now also serves the node SVID on the source's `Updated()` wake
rather than the next 30s tick; the registrar watch loop defers (INFO, no
`watch_errors`, no backoff escalation) while the SVID is pending; the xDS cache
omits upstream mTLS until `SetNodeIdentity` lands and Envoy tolerates the absent
secret (#715). The trust domain is seeded with the mesh domain through a small
atomic holder and reconciled against the real SVID when it arrives.

Readiness gains a `spire-svid` check beside `cni-chained`, with a 2m dwell equal
to the warn threshold: the controller's node-taint guard re-arms
`aether.io/agent-not-ready:NoSchedule` after 30s of NotReady and spire-server
does not tolerate that taint, so a hard-from-t=0 gate would fence the cluster
against spire-server's own rescheduling.

New metrics: `aether.agent.spire.wait_seconds` (seconds-oriented buckets, #732),
`aether.agent.spire.source_restarts` (expected 0), `aether.agent.spire.svid_ready`.
Chart: `spire.waitWarnAfter: 2m` threaded to all four components. Runbook: "The
agent is stuck waiting for SPIRE".

The `--spire-enabled=false` path (#421) is unchanged, and nothing in `runAgent`
or `PreListen` is reordered (#700/#712). The controller/registrar/edge sources
still create synchronously; PR 2 moves them.


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