Skip to content

fix(controller,registrar,edge): wait for the SPIRE Workload API instead of dying on it (#740) - #742

Merged
bpalermo merged 1 commit into
mainfrom
fix/740-pr2-controller-registrar-edge
Sep 7, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/740-pr2-controller-registrar-edge

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Closes the remaining #740 call sites. PR 1 (#741) moved the node agent off the one-shot, fatal commonspire.NewSource; the controller, registrar and edge still exited the process on a 25 s Workload API wait, so a cold boot in which SPIRE was still coming up crash-looped all three.

Per-binary mechanism

Binary Call site What replaces the fatal wait Why nothing needs the SVID at construction
Controller buildControllerBootstrapOpts (the earliest of the four — runs before manager.Bootstrap, because the webhook server is built from its options) WaitingSource whose Run is started on the command context (goroutine — there is no manager yet), handed to spire.WebhookServerCert WebhookServerCert installs tls.Config.GetCertificate, consulted per handshake. A still-waiting source fails individual TLS handshakes, not the process.
Registrar buildSpireGRPCCreds (before m.Start) WaitingSource registered with the manager; grpc.Creds(credentials.NewTLS(...)) over a new spire.ServerTLSConfigForOwnTrustDomain The whole tls.Config resolves at handshake time. The trust-domain resolution moved out of startup into the authorizer (which re-reads the registrar's own SVID, so it is also correct across a rotation) plus a post-arrival callback that logs it.
Edge resolveEdgeIdentity Returns the seeds (mesh domain, empty SPIFFE ID) immediately; wireEdgeIdentity calls the new SnapshotCache.UpdateEdgeIdentity on the first SVID UpdateEdgeIdentity rebuilds the cached mTLS clusters and pushes a snapshot, so the edge Envoy picks the identity up on the next CDS update rather than on a restart. The empty ID does not leak: recomputeMTLSClusters skips injection entirely while nodeSpiffeID == "".

Fail-open / endpoint semantics

  • Controller — the apiserver fails open. Both webhook configurations are failurePolicy: Ignore, so while the SVID is pending, admission proceeds unvalidated and pods are not ndots-mutated. That is exactly what happened while the container was crash-looping; the difference is that the controller is now alive and starts serving the moment the SVID lands. CABundleInjector.Source widens to SVIDSource, its initial-inject ERROR becomes INFO on errors.Is(err, spire.ErrNoSVIDYet), and the injection is performed by the Updated() wake — verified: WaitingSource fires Updated() on first land as well as on every rotation, so no retry logic was added.
  • Registrar — authorizes nothing until the SVID lands. An agent's handshake fails before the peer authorizer is ever consulted, so the deferred trust-domain read cannot widen authorization.
  • Edge — ingress keeps serving on the certs its Envoy already holds; only newly loaded clusters carry no upstream mTLS until the SVID arrives.
  • Readiness is load-bearing on all three (unlike on the DaemonSet): these are Deployments behind Services, so past the dwell the replica leaves the endpoints — the apiserver stops routing admission to a controller that cannot handshake, agents stop dialing a registrar that cannot, and the edge stops advertising an ingress whose upstreams have no identity. A workload that already holds an SVID keeps it, so the gate can only fail one that never got its first.

Names

  • readyz check: spire-svid on all four, now from one constant (spire.ReadyCheckName), dwell commonspire.NotReadyDwell = 2 m.
  • log lines (PR 1's, shared via the same helper, so one LogsQL phrase covers all four binaries):
    • waiting for the SPIRE Workload API to issue this workload's SVID (INFO, escalating to WARN past --spire-wait-warn-after)
    • obtained this workload's SVID from the SPIRE Workload API
    • plus per-component arrivals: webhook caBundle injection deferred until this workload has an SVID (INFO), resolved workload trust domain from SPIRE, resolved edge identity from SPIRE.
  • metrics — a minimal WithComponent option on NewWaitingSource namespaces the instruments PR 1 defined instead of duplicating them: aether.controller.spire.{wait_seconds,source_restarts,svid_ready}, aether.registrar.spire.*, aether.edge.spire.*. The agent's aether.agent.spire.* names are unchanged (DefaultComponent).

Negative controls

Control Result
The code this replaces — spire.NewSource on an unserved socket (the pre-fix shape at all three call sites) returned after 25.02 s with failed to create SPIRE Workload API source (socket …): context deadline exceeded — the error the callers turned into a process exit. Run once as a throwaway test, not committed.
buildControllerBootstrapOpts against an unserved socket returned in 3.94 ms (asserted < 100 ms)
buildSpireGRPCCreds against an unserved socket returned in 32.6 µs (asserted < 100 ms)
resolveEdgeIdentity against an unserved socket returned in 46.6 µs (asserted < 100 ms)
spire-svid inside the dwell / past it passes / fails with no SPIRE SVID after …, per binary
--spire-enabled=false (#421) no source, no runnable, no readiness check, no log line — asserted per binary
CABundleInjector before the SVID logs the deferral at INFO, initial webhook caBundle injection failed is absent, caBundle empty; injects PEM on Updated() once the fake Workload API serves
Edge identity UpdateEdgeIdentity called exactly once, with the fake's SPIFFE ID and trust domain, only after it starts serving; unchanged identity does not bump the snapshot version

All tests are hermetic: PR 1's fake SpiffeWorkloadAPIServer moved to a shared common/spire/spiretest (testonly) helper so all four binaries exercise the same fake.

Chart / docs

  • charts/aether/values.yaml: the spire.waitWarnAfter note said the dwell applied "on the agent"; it now applies to all four. Chart.yaml PATCH bumped 0.92.9 → 0.92.10 (comment-only changes are CI-enforced too). No new values — PR 1 already threaded --spire-wait-warn-after to all four components.
  • docs/runbook.md: "The agent is stuck waiting for SPIRE" gains a per-component section (webhook fail-open, registrar out of endpoints, edge seeds) and the correct metric namespaces (querying aether_agent_spire_* for the controller is a false zero).

Verification

  • bazel test --test_arg=-test.short //agent/... //common/... //registrar/... //controller/... — 66 tests pass
  • bazel build --config=lint //controller/... //registrar/... //agent/internal/cmd/... //common/spire/... — clean
  • make gazelle, make format-check — clean

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…ad of dying on it (#740)

PR 1 (#741) moved the node agent off the one-shot, fatal `commonspire.NewSource`
(25s bound, #668). This closes the three remaining call sites, which all still
exited the process when SPIRE was not serving yet — measured negative control:
`NewSource` on an unserved socket returns after 25.02s with
`failed to create SPIRE Workload API source: context deadline exceeded`.

Controller (`buildControllerBootstrapOpts`, the earliest of the four — it runs
before `manager.Bootstrap` because the webhook server is built from its options):
constructs a `WaitingSource` and starts its `Run` on the command context, then
hands it to `spire.WebhookServerCert`. The certificate is resolved per handshake
(`tls.Config.GetCertificate`), so a source that is still waiting fails individual
TLS handshakes rather than the process; both webhook configurations are
`failurePolicy: Ignore`, so the apiserver fails OPEN meanwhile — admission
proceeds unvalidated and pods are not ndots-mutated, exactly as they were while
the container was crash-looping, only now the controller is alive and starts
serving the moment the SVID lands. `CABundleInjector.Source` widens to
`SVIDSource` and its initial-inject ERROR becomes INFO on `ErrNoSVIDYet`; the
injection is then performed by the `Updated()` wake `WaitingSource` fires on first
land as well as on rotation, so no retry logic was added.

Registrar (`buildSpireGRPCCreds`): same `WaitingSource`, registered with the
manager. `grpc.Creds` accepts a lazy source because the whole `tls.Config`
resolves at handshake time — the trust-domain resolution moves out of startup and
into `ServerTLSConfigForOwnTrustDomain`, which reads the registrar's own SVID per
handshake (so it stays correct across a rotation), plus one post-arrival callback
that logs the resolved trust domain. Until the SVID lands the registrar authorizes
NOTHING: the handshake fails before the authorizer is ever consulted.

Edge (`resolveEdgeIdentity`): needs the trust domain AND its own SPIFFE ID, so it
returns the seeds (mesh domain, empty ID) immediately and folds the real identity
in on the first SVID. `SnapshotCache.UpdateEdgeIdentity` is the after-start form
of `SetEdgeIdentity` — it rebuilds the cached mTLS clusters and pushes a snapshot,
so the edge Envoy picks the identity up on the next CDS update instead of on a
restart. The empty SPIFFE ID does not leak: `recomputeMTLSClusters` skips
injection entirely while it is empty.

All three register the same `spire-svid` readiness gate (`spire.ReadyCheckName`)
with the same `commonspire.NotReadyDwell` (2m). Here it is load-bearing in a way
it is not on a DaemonSet: these are Deployments behind Services, so past the dwell
the replica leaves the endpoints — the apiserver stops routing admission to a
controller that cannot handshake, agents stop dialing a registrar that cannot, and
the edge stops advertising an ingress whose upstreams have no identity. A workload
that already holds an SVID keeps it, so the gate can only fail one that never got
its first.

The wait's log lines are PR 1's, unchanged and shared, so one LogsQL phrase covers
all four binaries: `waiting for the SPIRE Workload API to issue this workload's
SVID` and `obtained this workload's SVID from the SPIRE Workload API`. Only the
metric namespace differs, via a new minimal `WithComponent` option on
`NewWaitingSource`: `aether.controller.spire.*`, `aether.registrar.spire.*`,
`aether.edge.spire.*` (the agent's names are unchanged by default).

`--spire-enabled=false` (#421) is byte-identical on all three paths — no source,
no runnable, no readiness check, no log line — and pinned by a test each. PR 1's
fake Workload API server moves to `common/spire/spiretest` so all four binaries
test against it.

Chart: the values.yaml note is corrected (the dwell now applies to all four
components) and Chart.yaml PATCH bumped. Runbook: the "stuck waiting for SPIRE"
section gains the per-component symptoms.

Co-Authored-By: Claude Fable 5.1 <[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

Development

Successfully merging this pull request may close these issues.

1 participant