Mirror never fetches newly-watched Secrets: App pinned fail-closed 503 until restart #63
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
lab/authz-bridge#63
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Mirror never fetches newly-watched Secrets: an App is pinned fail-closed 503 until restart
Hit on mini 2026-11-05 (image v0.1.3, deployments pin
27e87b7) while onboardingsearxngto the bridge.Symptom
Every ext_authz Check for App
searxng/searxngwas denied with 503 and the debugline
App client secret is not readyfrom the moment the OauthClient was bornuntil a controller-pod restart ~3 minutes later, even though the referenced
Secret held the
clientSecretkey the whole time. Nothing self-heals: the onlyrecovery was
rollout restart.Root cause (confirmed in code)
The Mirror learns referenced-Secret bytes through exactly two paths:
bootstrap()(internal/snapshot/mirror.go:172) fetches every watched Secret,but runs only once at startup; and
ingest()(internal/snapshot/mirror.go:223) folds watch events in, but onlyfor Secrets already in
m.watched: the guard atmirror.go:238-242dropsevents for anything else.
The watched set is derived from the managed Registry by
parseRegistry()(
internal/snapshot/mirror.go:304): it prunes no-longer-referenced Secrets butnever fetches the bytes of a newly-referenced one. So a Secret whose last
change event landed before the Registry started referencing it is never seen
again:
Build()(internal/snapshot/snapshot.go:70-77) finds no bytes, setsSecretReady=false, and the OIDC Flow fail-closes 503 (ADR 0011,internal/serve/oidc.go:152-170) permanently, until that Secret is modifiedagain or the pod restarts.
The standard onboarding is exactly this race.
docs/guides/protecting-an-existing-app.mdcreates the Secret first, then the OauthClient. An ExternalSecret-backed Secret
rewrites only on content drift, so no later Update event will come. The outcome
depends on whether the ESO Secret write or the leader's Registry write lands
first on the data-plane informer.
carwash-frigateandk8s-hubwent throughthe identical flow and got the lucky order; searxng got the unlucky one.
The leader-side Secret watch cannot heal it either:
mapSecretToClients(
internal/controller/providers/oauthclient_controller.go:63) re-reconciles andcan rewrite the Registry with a fresh
SecretReadyflag(
internal/registry/builder.go:152), but the data plane derives readiness onlyfrom its own local bytes (the leader's flag is zeroed by
copyEntry,internal/snapshot/snapshot.go:66).Timeline (mini, 2026-11-05, UTC)
15:12:01flux applies thesearxngOauthClient and the ExternalSecret thatadds the
clientSecretkey to the existingsearxng-oauth-secrets, one revision.~15:12:02ESO syncs the Secret (key present,Ready=True/SecretSyncedfrom here).15:12:02leader createsReferenceGrant authz-bridge-searxng-searxng;15:12:03the Mirror ingests the Registry change:{"msg":"Rebuilt the Snapshot","apps":4,"rebuilds":41}— the last rebuild before the restart.15:12:52-15:13:20repeated debug lines:{"level":"debug","msg":"App client secret is not ready","app":"searxng/searxng"};the public route 503s (
server: envoy, empty body).Available=True / Degraded=False: theleader reads the Secret through its own cached client and sees it; only the
data-plane Mirror is stale.
~15:13:20gateway Checks stop reaching the bridge entirely (503s keepcoming from envoy, zero Check log lines). Unexplained — see follow-up 3.
15:15kubectl -n authz-bridge-system rollout restart deploy/authz-bridge-controller-manager;the first unauthenticated GET after Ready returns the expected 302 to Kanidm.
carwash-frigate, admin.media and the hub are green after the restart.
Proposed fixes
parseRegistry(orrebuild) detects awatchedentry missing fromm.secrets,fetchSecretit and store theresult (absent stays absent: 503 is then correct). After cache sync this is
a cheap cached-client Get. Alternative: ingest every Secret event
unconditionally (the informer already caches all Secrets) and let
Buildfilter — simpler, but keeps a bytes copy of every Secret in the cluster.
with no metric; the CR claims
Available=Truethe entire time. Add aper-App unavailable counter (e.g.
authz_bridge_app_degraded{app,reason})and/or rate-limited
Infologging for repeated degraded Checks, so an alertcan catch a stuck App without curling by hand.
envoy stopped forwarding Checks to the bridge at all (503s with no bridge
log lines). If cilium/envoy ejects a repeatedly-503ing ext_authz endpoint,
document the recovery latency and consider whether the degraded state should
be answered with a status that does not trip ejection.
Immediate mitigation
kubectl -n authz-bridge-system rollout restart deploy/authz-bridge-controller-manager(bootstrap fetches every referenced Secret).