Skip to content

feat(identity): injected identity-ready init container holds a mesh pod's app containers until its SVID exists — the egress twin of the inbound readiness gate (#1053) - #1055

Merged
bpalermo merged 6 commits into
mainfrom
feat/1053-egress-identity-gate
Sep 28, 2026

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Why

A pod that sends within ~8 s of its CNI ADD has no SVID yet: SPIRE delivers the initial SVID only after the pod's registration entry is created and synced to the node's spire-agent (two svids=0 updates, then update=initial 7.46 s after the subscribe on talos-main). In that window the source proxy has no client certificate for the pod, connects sit until connect_timeout, and the app gets 503 UF (h2; 503 NC on QUIC before #1051). The inbound side already gates endpoint health on an mTLS handshake with the pod's own inbound listener (#815); egress had nothing.

The decision on #1053 (2026-09-28): do not block the CNI ADD. That would make SPIRE a hard dependency of sandbox creation, and the ADD races SPIRE's own pod-list attestation. Gate the app container instead: the netns and sandbox exist, SPIRE attests normally, the app cannot open a socket before its identity exists, and a SPIRE outage shows up as pods in Init with a reason instead of as 503s.

Design

  • agent/cmd/identity-ready, a new binary. It waits until the pod's X.509 SVID is obtainable, then exits 0. By default it fails closed: with no timeout it waits forever, and every 10 s it logs a WARN that names the socket and the last Workload API error. --timeout makes it exit 1 with a clear message. SIGTERM is reported as an interruption, not as a timeout.

  • Source of truth: the pod's own SPIRE Workload API, read through a csi.spiffe.io volume that is mounted into the init container only. The app containers never get the socket. I rejected the alternative, an agent RPC over a host-local UDS, because it has the bigger blast radius:

    • It needs a hostPath volume in every workload pod, which the Pod Security baseline profile rejects. A CSI volume is allowed even under restricted.
    • It needs a new proto RPC.
    • It needs caller authentication on the agent side.

    The Workload API answers from the same spire-agent cache that the agent's Broker API stream is fed from, and controller-manager entries carry only k8s:pod-uid, which the init container matches. The proxy fetches the client certificate on demand at connect time (Make the source-identity filter state Hashable so the mesh can drop connection_pool_per_downstream_connection #842/Inbound validation context accepts any trust-domain member: pin a spiffe://<td>/ns/*/sa/* URI SAN prefix #843), so there is no settle delay. Measured on kind: after release, the first request took 12–14 ms.

  • Dependencies: gRPC, protobuf and go-spiffe's generated proto/spiffe/workload client only. It does not use workloadapi/x509svid, so no go-jose. The binary is 11.4 MB, 8 modules. //agent/cmd/identity-ready:deps_test reads the embedded build info and asserts an explicit module allow-list, plus a forbidden-package scan and a size ceiling. It is not stdlib-only, so there is no deps_test claiming that.

  • Image: an extra layer (/identity-ready) in the agent image, following the proxy-ready pattern. The agent DaemonSet already has that image on every node, so the gate costs no extra pull and cannot skew from the agent. container_test.yaml asserts the file is there.

  • Injection (controller/internal/podmutate/identitygate.go):

    • The webhook injects aether-identity-ready first among init containers, so it also holds the pod's own init containers and native sidecars.
    • It adds the CSI volume aether-identity-gate-spiffe.
    • Resources are tiny: requests 5m CPU / 16Mi memory, limit 64Mi memory.
    • The security context passes the Pod Security restricted profile: nonroot 65532, read-only root filesystem, drop ALL, RuntimeDefault seccomp.
    • terminationMessagePolicy: FallbackToLogsOnError, so kubectl describe shows why a pod is held.
    • Pods it skips: aether.io/identity-gate: "false", hostNetwork, and mesh-ignored namespaces (gating SPIRE's own namespace would deadlock SPIRE's bootstrap).
    • Re-mutation is idempotent: the container name is the key, and an existing volume is reused.

Knob and annotation

  • controller.webhook.identityGate.enabled defaults to true. The chart always renders --identity-gate=true|false, and it forces false when spire.enabled=false, because no SVID would ever come.
  • The other values are identityGate.image.* (empty means agent.image), pullPolicy (default IfNotPresent: the image is digest-pinned and already on the node), timeout (empty means wait forever) and resources.
  • The chart passes these to new controller flags: --identity-gate, --identity-gate-image, --identity-gate-image-pull-policy, --identity-gate-workload-socket (= spire.workloadSocketPath), --identity-gate-timeout, and --identity-gate-{cpu,memory}-{request,limit}. A bad value fails controller startup, not admission.
  • The per-pod opt-out annotation is aether.io/identity-gate: "false" (annotations.AnnotationIdentityGate).
  • Chart version 1.0.4.

Tests

  • podmutate:
    • The gate is injected by default, with the exact shape pinned.
    • No timeout means no --timeout argument.
    • The opt-out annotation works, and any other value keeps the gate.
    • Chart-disabled (nil gate) injects nothing.
    • Re-admission is idempotent and produces no patch.
    • Non-mesh pods are untouched: aether.io/managed=false, hostNetwork, and spire-mgmt/aether-system/kube-system.
    • An existing volume is reused.
    • Validation.
    • Also run under --config=race.
  • controller cmd: the gate is off by default in the binary, the defaults are right, bad config is rejected, and the flags exist under the names the chart renders.
  • identity-ready: tested against the fake Workload API in common/spire/spiretest:
    • When ready, it releases on the first fetch, with the security header present.
    • When not ready, it keeps waiting and logs the waiting line, then releases the moment the fake serves.
    • With a timeout, it returns errTimedOut naming the socket and the last SPIRE error. An attempt cut short by the deadline no longer overwrites that error; race × 20 runs was clean.
    • With no SPIRE agent listening, it keeps waiting.
    • Cancel is reported as an interruption, not a timeout.
    • Flag parsing is covered.
    • Real main() exit codes are covered in a subprocess: 0 when ready, 1 on timeout.
  • deps_test holds the module allow-list.
  • chart helm_template_tests: aether_identity_gate_default_test (the agent image from quay by digest, IfNotPresent, the socket path and resources), _disabled_test, _no_spire_test and _overrides_test (timeout plus mirror image).
  • bazel test //controller/... //agent/cmd/... //charts/... //common/constants/... //e2e/...: 42/42 passed. Lint with fail_on_violation, make format-check, make gazelle, make tidy and make deps-audit are all clean. //test/envoy_validate is untouched; there is no xDS change.

e2e evidence (kind, e2e/eastwest-quic.sh, new phase E6 + idgate subcommand)

E6 creates a ServiceAccount that did not exist a second earlier and a bare Pod whose container sends its first request to h2only the instant it starts. E6 asserts four things: the init containers start with aether-identity-ready, it exited 0, the first request is 200, and the XFCC URI= is the new SA's own SPIFFE ID.

Run Gate Held in Init First request
idgate ×4 off (IDENTITY_GATE=off) — (no init container) 200 after 3.4 / 4.6 / 5.4 s (stalled waiting for the pod's client cert)
idgate ×3 on (chart default) 4.12 / 3.61 / 3.60 s (exit 0) 200 in 12.5 / 14.0 / 12.2 ms as spiffe://aether.internal/ns/aether-test/sa/idgate-…

With the gate off, the agent log for the same pods shows the talos-main shape: subscribe, then svids=0 twice, then update=initial 3.9–5.9 s later.

The red arm did not reproduce as a 503 on kind. kind's SPIRE issued the SVID inside the mesh cluster connect_timeout, so the gate-off first request stalled (the missing-cert wait) rather than failing. On talos-main the window is ~7.5 s, which crosses connect_timeout and becomes 503 UF. E6 reports the first request's status and latency in both modes and asserts only the gate-on contract.

A full verify (E0–E6) with the gate on passed. That run also covers E5, which deletes client-a's pod; it came back gated and still carried its own identity over HTTP/3. The kind cluster was deleted and the kube context restored to talos-main.

Docs

Closes #1053

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 6 commits September 28, 2026 15:52
…od's app containers until its SVID exists — the egress twin of the inbound readiness gate (#1053)

A pod that sent within ~8 s of its CNI ADD had no SVID yet: the source proxy
had no client certificate for it and connects sat until connect_timeout
(503 UF on h2). The CNI ADD is deliberately not blocked (SPIRE must not become
a hard dependency of sandbox creation); the app container is gated instead.

- agent/cmd/identity-ready: waits on the pod's own SPIRE Workload API
  (csi.spiffe.io, mounted into the init container only) until an X.509 SVID is
  issued, then exits 0. Fail closed by default, periodic WARN naming the socket
  and last error, optional --timeout. Links gRPC + go-spiffe's generated
  Workload API client only; deps_test holds an explicit module allow-list.
  Ships as an extra layer in the agent image.
- controller/internal/podmutate: injects aether-identity-ready FIRST (ahead of
  the pod's own init containers) plus its CSI volume into every mesh pod;
  skips aether.io/identity-gate=false, hostNetwork and mesh-ignored
  namespaces; idempotent; Pod Security "restricted"-compliant.
- chart: controller.webhook.identityGate.{enabled,image,pullPolicy,timeout,
  resources}, default ON, never rendered with spire.enabled=false; chart 1.0.4.
- e2e/eastwest-quic.sh E6: fresh ServiceAccount, request at container start.
  kind: gate off -> first request stalls 3.4-5.4 s for the cert; gate on ->
  gate holds 3.6-4.1 s, first request 200 in 12-14 ms as the new SA.
- docs: workload requirements, configuration, runbook, proposal 036 follow-up.

Closes #1053

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit cd05ee0 into main Sep 28, 2026
24 checks passed
@bpalermo
bpalermo deleted the feat/1053-egress-identity-gate branch September 28, 2026 19:28
bpalermo added a commit that referenced this pull request Sep 29, 2026
Brings #979 up to date with 36 commits of main (demand-scoped twins #1020/#1032,
fresh-stream classifier #1033/#1035, dormant-pair ledger #1036/#1038, per-twin
EDS names #1012/#1029, the twin certificate gate #1051, the ODCDS always-answer
override, --east-west-quic-idle-timeout #1063, L4 stat keys #1043, access-log
timing #1048, the identity gate #1055, hot-restart knobs #1068 and the carried
Envoy patches) while keeping #979's intent: no allow-list, every destination in
the node's dependency set is QUIC-eligible.

Resolution:
- cache: quicServices / SetEastWestQUICServices removed. armsFor gives arms to
  every default, identity-ready, non-waypointed entry whose service is in the
  dependency set (the same rule recordQUICPair admits by, so no route names a
  twin the agent would refuse); twins stay demand-scoped. The
  destination_not_quic_enabled refusal/prune reason is gone.
- quicpairs: the dependency-set prune now waits for the pod set like the
  source prune does -- the allow-list used to force its destinations into the
  set, and without it the first snapshot after an agent restart dropped every
  restored pair (TestQUICDemandPairSurvivesAgentRestart was red).
- fan-out log: allow_listed_services dropped; observed_pairs and
  awaiting_client_cert kept.
- chart 1.0.12: eastWestQuicServices removed, eastWestQuicIdleTimeout and its
  parentShutdownTime check kept.
- e2e/eastwest-quic.sh: main's demand-scoped E1/E4c/E6 + #979's QUIC_DNS_SANS
  negative control; h2only/E3 removed; E6 dials quic-a and its idgate-* pairs
  are excluded from the driven-pair count. eastwest-quic-hotrestart.sh's h2
  control is now the weighted GAMMA split (the one h2-by-design path).
- tests, runbook, soak README, configuration.md, 038 rewritten for the
  unconditional state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant