Skip to content

feat(agent)!: replace SPIRE's Delegated Identity API with the SPIFFE Broker API (proposal 036, phase 1) - #802

Merged
bpalermo merged 1 commit into
mainfrom
feat/036-spiffe-broker-api
Sep 18, 2026
Merged

bpalermo merged 1 commit into
mainfrom
feat/036-spiffe-broker-api

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Phase 1 of proposal 036. BREAKING: requires SPIRE >= 1.15.2 with the Broker Endpoint enabled and the aether agent registered as a broker (explicit accessPolicy: permissive — chart 0.30.2's auto escalates to enforced for pod references and fails closed). Phase 0 is live on talos-main (bpalermo/k8s-talos-main#79). Cluster validation per the proposal follows the merge.

feat(agent)!: replace SPIRE's Delegated Identity API with the SPIFFE Broker API (#800) (036)

Proposal 036, phase 1: a hard switch, not an opt-in. The node agent no longer
mints per-pod SVIDs through SPIRE's proprietary Delegated Identity API on the
agent admin socket with a selector set it builds by hand; it presents a
KubernetesObjectReference over the standard SPIFFE Broker Endpoint and SPIRE
resolves and attests the referenced pod itself. The delegated client, the
admin-socket plumbing and the spire-api-sdk dependency are deleted.

What that buys: every selector SPIRE's Kubernetes attestor can produce (pod
labels, container image, sigstore) becomes usable in a registration entry —
under the delegated path an entry keyed on anything other than the four
selectors the agent supplied could never match, because SPIRE never attested
the pod. The all-or-nothing admin socket and its authorizedDelegates allow-list
disappear, and the agent speaks a SPIFFE standard rather than a SPIRE API.

agent/internal/spire/client.go is now a Broker client: it dials
unix:// with mutual TLS built from the agent's own WaitingSource
identity, authorises the server as a SPIFFE ID in our OWN trust domain under
/spire/agent/ (the endpoint spec requires the broker to authenticate the
provider, and "any member of the trust domain" would let any workload that can
bind the socket path hand us poisoned SVIDs), and adds the mandatory
broker.spiffe.io: true metadata on every unary and streaming call via
interceptors. #740 semantics carry over unchanged: no SVID yet simply means the
handshake cannot complete, the subscribe fails, and the bridge retries — the
agent never exits.

Two things the delegated path never had to handle:

  • A reference resolves at REQUEST time, so a CNI ADD routinely beats the pod
    into the kubelet's pod list and gets NotFound. SubscribePod therefore never
    blocks on the broker: it registers the subscription and hands the first
    subscribe to the subscription's own goroutine, which retries on the existing
    jittered backoff. The gRPC codes are mapped per the proposal's Errors bullet
    (NotFound/FailedPrecondition retry, PermissionDenied retries slowly,
    Unauthenticated retries — go-spiffe re-reads the SVID per handshake, so a
    plain retry IS the credential refresh —, InvalidArgument never retries), with
    new counters aether.agent.spire.broker.{reference_not_found,permission_denied}
    seeded at zero (fix(agent): seed the #638 identity mismatch counters at zero (false-zero in Prometheus) #717) and an INFO->WARN escalation once one reference has been
    unresolved for 30s.
  • SPIRE blocks inside its own cache subscription before the handler sends
    anything, so a reference that resolves to an entry whose SVID never lands
    leaves Recv blocked forever with no error, no log line and no retry. The first
    receive is synchronous (that is where NotFound/PermissionDenied arrive at all)
    and bounded by firstResponseTimeout, which turns that silent hang into an
    ordinary retry that also re-resolves the reference.

Trust bundles needed rebuilding, because the Broker API has no node-wide bundle
stream — SubscribeToX509Bundles also takes a workload reference, and a node with
zero managed pods has none. Validation contexts are now DERIVED from two inputs:
the agent's own Workload API bundle (available as soon as SPIRE attests the
agent itself, strictly earlier than any pod's) and the union of the
federated_bundles each live pod stream carries, dropped when that pod
unsubscribes. #784's guarantees are unchanged and re-tested: single-writer
monotonic publication under pushMu with the generation stamp, and never
replacing a non-empty validation-context set with an empty one.

The converter takes the Broker X509SVID, whose chain is ONE concatenated ASN.1
DER byte string (leaf first) rather than a repeated field — the boundaries are
not given, so the chain must be parsed to be split, and a chain Envoy could not
load is now rejected where the error names the SVID.

Call sites, flags and chart: the CNI server passes namespace/name/UID instead of
selectors (the UID was already in the ADD path and in storage);
--spire-broker-socket replaces --spire-admin-socket (added to
TestRetiredFlagsGone); spire.adminSocket.* becomes spire.brokerSocket.* pointing
at /run/spire/agent/sockets/csi.spiffe.io/broker, where the spiffe/spire chart
puts the socket directory on the node. The socket is mode 0770 owned by the
spire-agent uid:gid, which the agent's existing runAsUser:0 + DAC_OVERRIDE
already covers, so no securityContext change and the same read-only hostPath
mount shape (verified on all five talos-main nodes under k8s-talos-main#79).

Proposal 036 is corrected in one place while its Status moves to implemented:
the access policy ships as an EXPLICIT permissive, never the chart's auto.
The chart's broker-access-policy helper escalates auto to enforced for any
allowed reference type other than WorkloadPIDReference — i.e. for the
KubernetesObjectReference this design uses — and enforced needs an
impersonation RBAC grant the chart only renders when the broker also sets
impersonation.clusterWidePodsOnly. auto alone therefore fails CLOSED with
PermissionDenied on every pod. Phasing item 3 now says the hardening step must
flip both at once.

Tests. A fake SPIFFE Broker Endpoint in common/spire/spiretest serves real mTLS
from a test CA, rejects any call missing the security header with
InvalidArgument, resolves references from a table and can return NotFound-then-
success, PermissionDenied, an early stream close and federated bundles — so the
bridge tests exercise the production client, a real UDS, a real handshake and
the real interceptors rather than a stub. Every existing test is ported, none
dropped: the push-ordering/S10/S11 suite (now driven through per-pod federated
bundles, with certificate serials carrying the SVID generation because the
converter parses the chain), the reconnect suite, the late-identity #740 test
and the node-SVID converter tests. New: the security header and the full
key+UID reference on every call, the server authorizer rejecting both a
non-SPIRE-agent path and a foreign trust domain, NotFound retrying to success,
the PermissionDenied counter, federated-bundle union add/remove, a zero-pod node
still serving validation contexts, a rotation on a live stream, and the error
classification table.

A second flag-contract test mirrors //agent/internal/supervisorcmd for the agent
DaemonSet: every --flag the chart passes must exist on the command. Without it a
half-migrated chart is invisible until a rollout leaves every node's agent
exiting on "unknown flag".

e2e harnesses move from SPIRE chart 0.28.4 (SPIRE 1.14.5, no Broker API) to
0.30.2 with crds 0.6.1, drop authorizedDelegates + sockets.admin, and register
the broker in both required blocks.

Verification: bazel build //... //test/e2e:e2e_test; bazel test //... (106
tests, all pass); bazel test --config=race --runs_per_test=3
//agent/internal/spire/... //common/spire/... //agent/internal/cni/... ;
//:format.check; --config=lint --@aspect_rules_lint//lint:fail_on_violation
//... ; gazelle no churn; bazel mod tidy idempotent; scripts/go-deps-audit.sh
OK after pruning spire-api-sdk's ten go.sum lines.

Not verifiable without a live SPIRE >= 1.15.2: the on-wire interop itself.
Validated on talos-main by the orchestrator.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…Broker API (#800) (036)

Proposal 036, phase 1: a hard switch, not an opt-in. The node agent no longer
mints per-pod SVIDs through SPIRE's proprietary Delegated Identity API on the
agent admin socket with a selector set it builds by hand; it presents a
KubernetesObjectReference over the standard SPIFFE Broker Endpoint and SPIRE
resolves and attests the referenced pod itself. The delegated client, the
admin-socket plumbing and the spire-api-sdk dependency are deleted.

What that buys: every selector SPIRE's Kubernetes attestor can produce (pod
labels, container image, sigstore) becomes usable in a registration entry —
under the delegated path an entry keyed on anything other than the four
selectors the agent supplied could never match, because SPIRE never attested
the pod. The all-or-nothing admin socket and its authorizedDelegates allow-list
disappear, and the agent speaks a SPIFFE standard rather than a SPIRE API.

agent/internal/spire/client.go is now a Broker client: it dials
unix://<broker socket> with mutual TLS built from the agent's own WaitingSource
identity, authorises the server as a SPIFFE ID in our OWN trust domain under
/spire/agent/ (the endpoint spec requires the broker to authenticate the
provider, and "any member of the trust domain" would let any workload that can
bind the socket path hand us poisoned SVIDs), and adds the mandatory
broker.spiffe.io: true metadata on every unary and streaming call via
interceptors. #740 semantics carry over unchanged: no SVID yet simply means the
handshake cannot complete, the subscribe fails, and the bridge retries — the
agent never exits.

Two things the delegated path never had to handle:

- A reference resolves at REQUEST time, so a CNI ADD routinely beats the pod
  into the kubelet's pod list and gets NotFound. SubscribePod therefore never
  blocks on the broker: it registers the subscription and hands the first
  subscribe to the subscription's own goroutine, which retries on the existing
  jittered backoff. The gRPC codes are mapped per the proposal's Errors bullet
  (NotFound/FailedPrecondition retry, PermissionDenied retries slowly,
  Unauthenticated retries — go-spiffe re-reads the SVID per handshake, so a
  plain retry IS the credential refresh —, InvalidArgument never retries), with
  new counters aether.agent.spire.broker.{reference_not_found,permission_denied}
  seeded at zero (#717) and an INFO->WARN escalation once one reference has been
  unresolved for 30s.
- SPIRE blocks inside its own cache subscription before the handler sends
  anything, so a reference that resolves to an entry whose SVID never lands
  leaves Recv blocked forever with no error, no log line and no retry. The first
  receive is synchronous (that is where NotFound/PermissionDenied arrive at all)
  and bounded by firstResponseTimeout, which turns that silent hang into an
  ordinary retry that also re-resolves the reference.

Trust bundles needed rebuilding, because the Broker API has no node-wide bundle
stream — SubscribeToX509Bundles also takes a workload reference, and a node with
zero managed pods has none. Validation contexts are now DERIVED from two inputs:
the agent's own Workload API bundle (available as soon as SPIRE attests the
agent itself, strictly earlier than any pod's) and the union of the
federated_bundles each live pod stream carries, dropped when that pod
unsubscribes. #784's guarantees are unchanged and re-tested: single-writer
monotonic publication under pushMu with the generation stamp, and never
replacing a non-empty validation-context set with an empty one.

The converter takes the Broker X509SVID, whose chain is ONE concatenated ASN.1
DER byte string (leaf first) rather than a repeated field — the boundaries are
not given, so the chain must be parsed to be split, and a chain Envoy could not
load is now rejected where the error names the SVID.

Call sites, flags and chart: the CNI server passes namespace/name/UID instead of
selectors (the UID was already in the ADD path and in storage);
--spire-broker-socket replaces --spire-admin-socket (added to
TestRetiredFlagsGone); spire.adminSocket.* becomes spire.brokerSocket.* pointing
at /run/spire/agent/sockets/csi.spiffe.io/broker, where the spiffe/spire chart
puts the socket directory on the node. The socket is mode 0770 owned by the
spire-agent uid:gid, which the agent's existing runAsUser:0 + DAC_OVERRIDE
already covers, so no securityContext change and the same read-only hostPath
mount shape (verified on all five talos-main nodes under k8s-talos-main#79).

Proposal 036 is corrected in one place while its Status moves to implemented:
the access policy ships as an EXPLICIT permissive, never the chart's `auto`.
The chart's broker-access-policy helper escalates `auto` to `enforced` for any
allowed reference type other than WorkloadPIDReference — i.e. for the
KubernetesObjectReference this design uses — and `enforced` needs an
impersonation RBAC grant the chart only renders when the broker also sets
impersonation.clusterWidePodsOnly. `auto` alone therefore fails CLOSED with
PermissionDenied on every pod. Phasing item 3 now says the hardening step must
flip both at once.

Tests. A fake SPIFFE Broker Endpoint in common/spire/spiretest serves real mTLS
from a test CA, rejects any call missing the security header with
InvalidArgument, resolves references from a table and can return NotFound-then-
success, PermissionDenied, an early stream close and federated bundles — so the
bridge tests exercise the production client, a real UDS, a real handshake and
the real interceptors rather than a stub. Every existing test is ported, none
dropped: the push-ordering/S10/S11 suite (now driven through per-pod federated
bundles, with certificate serials carrying the SVID generation because the
converter parses the chain), the reconnect suite, the late-identity #740 test
and the node-SVID converter tests. New: the security header and the full
key+UID reference on every call, the server authorizer rejecting both a
non-SPIRE-agent path and a foreign trust domain, NotFound retrying to success,
the PermissionDenied counter, federated-bundle union add/remove, a zero-pod node
still serving validation contexts, a rotation on a live stream, and the error
classification table.

A second flag-contract test mirrors //agent/internal/supervisorcmd for the agent
DaemonSet: every --flag the chart passes must exist on the command. Without it a
half-migrated chart is invisible until a rollout leaves every node's agent
exiting on "unknown flag".

e2e harnesses move from SPIRE chart 0.28.4 (SPIRE 1.14.5, no Broker API) to
0.30.2 with crds 0.6.1, drop authorizedDelegates + sockets.admin, and register
the broker in both required blocks.

Verification: bazel build //... //test/e2e:e2e_test; bazel test //... (106
tests, all pass); bazel test --config=race --runs_per_test=3
//agent/internal/spire/... //common/spire/... //agent/internal/cni/... ;
//:format.check; --config=lint --@aspect_rules_lint//lint:fail_on_violation
//... ; gazelle no churn; bazel mod tidy idempotent; scripts/go-deps-audit.sh
OK after pruning spire-api-sdk's ten go.sum lines.

Not verifiable without a live SPIRE >= 1.15.2: the on-wire interop itself.
Validated on talos-main by the orchestrator.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 9fc27c8 into main Sep 18, 2026
20 checks passed
@bpalermo
bpalermo deleted the feat/036-spiffe-broker-api branch September 18, 2026 17:02
bpalermo added a commit that referenced this pull request Sep 18, 2026
…ector claim (#803)

Phase 1 (#802) is deployed to talos-main as rev217 and validated: 39/39 pod
SVIDs over the Broker API within 1.5–2.2 s of each agent coming up, zero
prober errors across the roll, workload churn and a SPIRE agent restart,
resubscribe 17.18 s into a ~34 s outage against 17.4 s for the delegated
bridge.

The validation also showed that the "every attestor selector becomes usable"
gain is not observable on this cluster: spire-controller-manager writes entries
keyed on k8s:pod-uid only, which the delegated path's hand-built selector set
already carried. The Consequences section now says so, and the Outcome section
lists what was NOT exercised (the NotFound race, a rotation at the 4 h TTL,
PermissionDenied under `enforced`) plus the ERROR-severity startup race (#766).

The proposals index reproduces the Status line verbatim, so it must not carry
an in-page anchor (the strict site build rejects it on the index page).


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