Repository navigation
fix(controller,registrar,edge): wait for the SPIRE Workload API instead of dying on it (#740) - #742
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
buildControllerBootstrapOpts(the earliest of the four — runs beforemanager.Bootstrap, because the webhook server is built from its options)WaitingSourcewhoseRunis started on the command context (goroutine — there is no manager yet), handed tospire.WebhookServerCertWebhookServerCertinstallstls.Config.GetCertificate, consulted per handshake. A still-waiting source fails individual TLS handshakes, not the process.buildSpireGRPCCreds(beforem.Start)WaitingSourceregistered with the manager;grpc.Creds(credentials.NewTLS(...))over a newspire.ServerTLSConfigForOwnTrustDomaintls.Configresolves 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.resolveEdgeIdentitywireEdgeIdentitycalls the newSnapshotCache.UpdateEdgeIdentityon the first SVIDUpdateEdgeIdentityrebuilds 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:recomputeMTLSClustersskips injection entirely whilenodeSpiffeID == "".Fail-open / endpoint semantics
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.Sourcewidens toSVIDSource, its initial-inject ERROR becomes INFO onerrors.Is(err, spire.ErrNoSVIDYet), and the injection is performed by theUpdated()wake — verified:WaitingSourcefiresUpdated()on first land as well as on every rotation, so no retry logic was added.Names
spire-svidon all four, now from one constant (spire.ReadyCheckName), dwellcommonspire.NotReadyDwell= 2 m.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 APIwebhook caBundle injection deferred until this workload has an SVID(INFO),resolved workload trust domain from SPIRE,resolved edge identity from SPIRE.WithComponentoption onNewWaitingSourcenamespaces 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'saether.agent.spire.*names are unchanged (DefaultComponent).Negative controls
spire.NewSourceon an unserved socket (the pre-fix shape at all three call sites)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.buildControllerBootstrapOptsagainst an unserved socketbuildSpireGRPCCredsagainst an unserved socketresolveEdgeIdentityagainst an unserved socketspire-svidinside the dwell / past itno SPIRE SVID after …, per binary--spire-enabled=false(#421)CABundleInjectorbefore the SVIDinitial webhook caBundle injection failedis absent, caBundle empty; injects PEM onUpdated()once the fake Workload API servesUpdateEdgeIdentitycalled exactly once, with the fake's SPIFFE ID and trust domain, only after it starts serving; unchanged identity does not bump the snapshot versionAll tests are hermetic: PR 1's fake
SpiffeWorkloadAPIServermoved to a sharedcommon/spire/spiretest(testonly) helper so all four binaries exercise the same fake.Chart / docs
charts/aether/values.yaml: thespire.waitWarnAfternote said the dwell applied "on the agent"; it now applies to all four. Chart.yaml PATCH bumped0.92.9 → 0.92.10(comment-only changes are CI-enforced too). No new values — PR 1 already threaded--spire-wait-warn-afterto 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 (queryingaether_agent_spire_*for the controller is a false zero).Verification
bazel test --test_arg=-test.short //agent/... //common/... //registrar/... //controller/...— 66 tests passbazel build --config=lint //controller/... //registrar/... //agent/internal/cmd/... //common/spire/...— cleanmake gazelle,make format-check— clean🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr