Skip to content

fix(security): stop trusting the aether.io/spiffe-id pod annotation as a mesh-identity override (#669) - #671

Merged
bpalermo merged 1 commit into
mainfrom
fix/669-spiffe-id-override
Sep 3, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/669-spiffe-id-override

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Fixes #669.

What the annotation actually controlled (call-site analysis)

SpiffeIDFromPod had five call sites; the value is trusted input to the data plane at four of them:

Call site What the returned ID becomes
proxy/ingress.go:75 (NewInboundListener) tlsCertificateSecretName — the SDS secret every inbound mTLS chain presents (TCP floor + no-SNI h2 chain + one per served port). The validation context is separate and derived from the trust domain flag, so the annotation could not widen who is accepted.
xds/cache/listener.go:141 / :413 localWorkloads[netns] — consumed by cache/mtls.go → proxy.InjectUpstreamMTLS, which builds the per-netns TransportSocketMatcher and one TransportSocketMatch per local ID. That names the client certificate the pod's egress presents (capture + outbound), for both HTTP and TCP-floor clusters.
cni/server/pod.go:123, cni/server/resubscribe.go:58 The spiffeID argument to spire.Bridge.SubscribePod. Bookkeeping only for issuance (selectors are the real ones), but it is also the key UnsubscribePod deletes from the node-wide secret map and the key its shared-identity refcount compares.
proxy/authz.go:70 spiffeId in the aether.source dynamic-metadata namespace, forwarded to the ext_authz sidecar as the calling workload's identity (027).

Real blast radius, as traced (not as assumed)

The SVID material does come from SPIRE, and SubscribePod passes the pod's real k8s selectors (spire.PodSelectors(ns, sa, name, uid)), so SPIRE never mints a forged identity. But the annotation does not have to make SPIRE issue anything — it only has to name a secret that already exists in the snapshot:

  • spire/converter.go names each SDS secret from the SPIFFE ID of the SVID SPIRE actually returned (spiffe://<td><path>), and bridge.handleSVIDUpdate stores it as b.secrets[secret.Name].
  • bridge.pushSecrets pushes every secret in that map into the single snapshot served to the node proxy. Secrets are node-wide, not scoped per pod or per netns.

So:

  1. Co-located victim → real impersonation, fails OPEN. A pod annotated with the SPIFFE ID of any workload that happens to run on the same node gets that identity's SDS secret name in its own inbound listener and in its egress transport-socket match. Its egress then presents the victim's SVID; peers' SAN pinning (cache/mtls.go), inbound RBAC, and the XFCC/aether.source caller identity (025/027, feat(authz): RBAC local authorization with audit mode #476/fix(authz): INBOUND filters bring their own chain entry into the union #477) all see the victim. This is cross-namespace impersonation obtainable with "create a pod in my own namespace" — the weakest common Kubernetes permission.
  2. No co-located holder → fails CLOSED, noisily-ish. The listener/cluster references an SDS secret that is never served, so those chains never warm; the effect is a self-inflicted outage for that pod, not an identity gain.
  3. Client side / EDS: unaffected. What peers pin is derived in cache/mtls.go from the registry service name (spiffe://<td>/ns/<ns>/sa/<service>), never from the annotation. The annotation changed only what the annotated pod's own config presents — which is exactly what makes case 1 exploitable rather than self-defeating.
  4. Secondary, same mechanism: UnsubscribePod deletes b.secrets[sub.spiffeID] using the annotated key, and its "another pod still uses this identity" refcount compares annotated keys. An attacker pod that borrowed a co-located identity could, on its own deletion, evict the victim's SVID from the node snapshot — a co-tenant data-plane outage — and conversely leak its own.

So the honest summary is: not uniformly fail-closed. Fail-closed on an unpopulated identity, fail-open (full impersonation, both directions) on any identity already present on the node — which an attacker can arrange by scheduling next to the target.

Fix chosen

Removal, per the issue's preference — validation could only ever permit the annotation to restate the derived value.

  • proxy.SpiffeIDFromPod now always returns spiffe://<trust-domain>/ns/<namespace>/sa/<service-account> (moved to a new proxy/spiffe.go next to its test).
  • proxy.SpiffeIDOverrideAnnotation reports the annotation so its presence is observable.
  • CNIServer.reportRejectedSpiffeIDOverride logs WARN (annotation, requestedSpiffeID, the spiffeID actually used) and increments aether.agent.identity.spiffe_id_override_rejected. Called on the CNI ADD path and again from the restart resubscribe replay, so a pod that still carries the annotation is re-reported after an agent restart rather than going quiet.
  • xdsconst.AnnotationSpiffeID is kept, documented as rejected — it is now only a detection key.
  • A genuine cross-identity need, should one appear, belongs behind a cluster-scoped object a namespace user cannot create (as security: aether.io/spiffe-id pod annotation is an unvalidated mesh-identity override #669 says), not this annotation.

Also in scope: endpoint metadata ordering

ServiceLocalityLbEndpointFromRegistryEndpoint applied pod-supplied metadata.endpoint.aether.io/* keys after the built-in envoy.lb keys. Those built-ins are not decoration: ip/pod back the NO_FALLBACK x-aether-ip / x-aether-pod pinning selectors, and waypoint steers the cluster's transport-socket matcher onto the structured waypoint SNI (019). A pod could therefore claim another pod's name/IP for pinned traffic, or forge the waypoint tag. Pod metadata is now applied first and filtered against the reserved key set, with the control-plane facts written last. waypoint was additionally added to reservedSubsetKeys (it passed ValidSubsetKey's pattern, so it was also usable as a provider subset key).

Test evidence

bazel test //agent/... //common/... //registry/... //controller/... //registrar/... //cni/... --test_output=errors → all green (68 targets). bazel build --config=ci //agent/... green (gocognit 15). make gazelle, make format run.

New/changed tests, none weakened:

  • proxy.TestSpiffeIDFromPod — table-driven over: no annotation, no annotations map, empty string, annotation restating the derived value, wrong ServiceAccount, wrong namespace, wrong trust domain, malformed URI, control-plane-identity shape. Every case must equal the derived ID.
  • proxy.TestSpiffeIDOverrideAnnotation — the detection hook (absent / unrelated / empty / present).
  • proxy.TestNewInboundListener_IgnoresSpiffeIDAnnotation — config-level regression: for every filter chain of an annotated pod's inbound listener, the DownstreamTlsContext cert SDS name is the derived ID and the validation context is the trust domain.
  • server.TestReportRejectedSpiffeIDOverride — asserts the WARN record carries the requested and the used identity and that the counter increments exactly once; asserts no log and no counter touch when the annotation is absent or empty. Plus a nil-metrics (telemetry-off) case.
  • proxy.TestServiceLocalityLbEndpointFromRegistryEndpoint_MetadataCannotForgeBuiltins — forged ip/pod/namespace/cluster/waypoint metadata is dropped, non-reserved keys still travel, and the control plane's own waypoint tag is still stamped when it decides the endpoint is remote.
  • proxy.TestValidSubsetKey — waypoint now rejected as a provider subset key.

Operator-visible behaviour change

  • aether.io/spiffe-id no longer does anything. Any workload that relied on it to present a non-derived identity will now present spiffe://<td>/ns/<ns>/sa/<sa>; if a peer pins the old value, that hop breaks. Nothing in this repo (charts, e2e, conformance, proposals) set the annotation — only docs/configuration.md, updated here — so no in-tree consumer changes.
  • Watch aether.agent.identity.spiffe_id_override_rejected after rollout: any nonzero value is a pod trying to choose its own identity and is worth investigating, benign or not.
  • Endpoint metadata annotations named ip, pod, namespace, cluster or waypoint are now dropped from the endpoint's envoy.lb metadata (they were already excluded from subset selectors). Subset routing on such a key was never functional; the only change is that the forged value no longer lands in the endpoint metadata.

Not fixed here

The other identity-enforcement gap #669 mentions — proxy/transportsocket.go silently omitting SAN pinning when sanURIs is empty, leaving the handshake proving only trust-domain membership — is untouched. It is a distinct fail-open path (empty sanNamespaces on a service entry) and deserves its own change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…s a mesh-identity override (#669)

A pod's mesh SPIFFE ID is now derived only from the mesh trust domain and the
pod's own namespace/ServiceAccount. The aether.io/spiffe-id annotation, which
reached the agent verbatim over the CNI ADD path, is rejected: it is logged at
WARN and counted by aether.agent.identity.spiffe_id_override_rejected on both
the CNI ADD path and the agent-restart resubscribe replay.

The override was not merely cosmetic. The SPIRE bridge keys its SDS secrets by
the SPIFFE ID of the SVID SPIRE actually issues, and pushes ALL of them into the
one snapshot served to the node proxy. The annotation named the SDS secret the
pod's inbound listener presents AND (via localWorkloads and the per-netns
transport-socket matcher) the client certificate its egress presents, so a pod
naming a co-located workload's identity had that workload's SVID presented on
its behalf in both directions.

Also reorders the endpoint envoy.lb metadata build so pod-supplied
metadata.endpoint.aether.io/* keys can no longer overwrite the control plane's
ip/pod/namespace/cluster/waypoint facts, and adds waypoint to the reserved
subset keys.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 763f5b3 into main Sep 3, 2026
16 checks passed
@bpalermo
bpalermo deleted the fix/669-spiffe-id-override branch September 3, 2026 15:53
bpalermo added a commit that referenced this pull request Sep 4, 2026
newCNIMetrics is at cognitive complexity 16 against the lint limit of 15 on
main, and no PR ever failed CI for it. #671 (763f5b3) added the fifteenth
registration; #672 was branched before #671 merged, added two more to a file
it saw at 13, and its CI head (f5d540a) honestly measured 15 and passed. The
squash of #672 onto main produced the sixteenth. Nothing lints main after a
merge, so the violation surfaced only when #676 and the #667 branch put
//agent/internal/cni/server back into a PR's bazel-diff impact set.

Pure mechanical extraction into registerSweepInstruments (ghost-sweep counters
and the prune-breaker gauge) and registerLifecycleInstruments (the unmeshed and
storage gauges, liveness instruments, identity-override counter). No metric
names, descriptions, units or registration order change.

Verified with fail_on_violation on //agent/internal/cni/server/... and the
package tests.

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 4, 2026
#678)

newCNIMetrics is at cognitive complexity 16 against the lint limit of 15 on
main, and no PR ever failed CI for it. #671 (763f5b3) added the fifteenth
registration; #672 was branched before #671 merged, added two more to a file
it saw at 13, and its CI head (f5d540a) honestly measured 15 and passed. The
squash of #672 onto main produced the sixteenth. Nothing lints main after a
merge, so the violation surfaced only when #676 and the #667 branch put
//agent/internal/cni/server back into a PR's bazel-diff impact set.

Pure mechanical extraction into registerSweepInstruments (ghost-sweep counters
and the prune-breaker gauge) and registerLifecycleInstruments (the unmeshed and
storage gauges, liveness instruments, identity-override counter). No metric
names, descriptions, units or registration order change.

Verified with fail_on_violation on //agent/internal/cni/server/... and the
package tests.


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
…efore merging (#679) (#685)

PR CI validates a PR head against that PR's merge-base, and nothing validated
main after a merge. Two PRs that each pass against their own base can combine
into a state neither was ever tested in — #671 and #672 each added CNI metric
registrations against a base without the other, and the second squash put
newCNIMetrics at gocognit 16/15 on main, surfacing days later on the unrelated
PRs #676/#677.

Add .github/workflows/main.yaml (`main-post-merge`): on every push to main it
runs the same build+lint+unit-test leg ci.yaml runs, with the bazel-diff impact
set computed as the merge commit vs its first parent (HEAD^), falling back to a
full //... build+test when bazel-diff cannot compute it. --config=ci implies
--config=remote, which pins TestRunner to the local strategy, so tests stay
local exactly as they are on the PR path. The pull_request path is untouched
and `ci` remains the only required status check.

ci-impacted-targets.sh never assumed a PR merge-base functionally, but its
docs did; retitle them for the two callers and add the new workflow to the
seed-file list so editing it forces a full run.

The preventive half — branch protection required_status_checks.strict — is a
repo settings change applied alongside this PR, not code.


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.

security: aether.io/spiffe-id pod annotation is an unvalidated mesh-identity override

1 participant