Mirror never fetches newly-watched Secrets: App pinned fail-closed 503 until restart #63

Open
opened 2026-11-05 15:17:39 +00:00 by ginjiruu · 0 comments
Owner

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 onboarding searxng to the bridge.

Symptom

Every ext_authz Check for App searxng/searxng was denied with 503 and the debug
line App client secret is not ready from the moment the OauthClient was born
until a controller-pod restart ~3 minutes later, even though the referenced
Secret held the clientSecret key the whole time. Nothing self-heals: the only
recovery was rollout restart.

Root cause (confirmed in code)

The Mirror learns referenced-Secret bytes through exactly two paths:

  1. bootstrap() (internal/snapshot/mirror.go:172) fetches every watched Secret,
    but runs only once at startup; and
  2. ingest() (internal/snapshot/mirror.go:223) folds watch events in, but only
    for Secrets already in m.watched: the guard at mirror.go:238-242 drops
    events 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 but
never 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, sets
SecretReady=false, and the OIDC Flow fail-closes 503 (ADR 0011,
internal/serve/oidc.go:152-170) permanently, until that Secret is modified
again or the pod restarts.

The standard onboarding is exactly this race. docs/guides/protecting-an-existing-app.md
creates 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-frigate and k8s-hub went through
the 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 and
can rewrite the Registry with a fresh SecretReady flag
(internal/registry/builder.go:152), but the data plane derives readiness only
from 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:01 flux applies the searxng OauthClient and the ExternalSecret that
    adds the clientSecret key to the existing searxng-oauth-secrets, one revision.
  • ~15:12:02 ESO syncs the Secret (key present, Ready=True/SecretSynced from here).
  • 15:12:02 leader creates ReferenceGrant authz-bridge-searxng-searxng;
    15:12:03 the Mirror ingests the Registry change:
    {"msg":"Rebuilt the Snapshot","apps":4,"rebuilds":41} — the last rebuild before the restart.
  • 15:12:52-15:13:20 repeated debug lines:
    {"level":"debug","msg":"App client secret is not ready","app":"searxng/searxng"};
    the public route 503s (server: envoy, empty body).
  • Throughout, the OauthClient CR reports Available=True / Degraded=False: the
    leader reads the Secret through its own cached client and sees it; only the
    data-plane Mirror is stale.
  • After ~15:13:20 gateway Checks stop reaching the bridge entirely (503s keep
    coming from envoy, zero Check log lines). Unexplained — see follow-up 3.
  • 15:15 kubectl -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

  1. Fetch on watch-set growth. Where parseRegistry (or rebuild) detects a
    watched entry missing from m.secrets, fetchSecret it and store the
    result (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 Build
    filter — simpler, but keeps a bytes copy of every Secret in the cluster.
  2. Make permanent degradation visible. "secret not ready" is logged at debug
    with no metric; the CR claims Available=True the entire time. Add a
    per-App unavailable counter (e.g. authz_bridge_app_degraded{app,reason})
    and/or rate-limited Info logging for repeated degraded Checks, so an alert
    can catch a stuck App without curling by hand.
  3. Investigate the silent gateway: after ~2.5 minutes of 503 Check responses,
    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).

# 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 onboarding `searxng` to the bridge. ## Symptom Every ext_authz Check for App `searxng/searxng` was denied with 503 and the debug line `App client secret is not ready` from the moment the OauthClient was born until a controller-pod restart ~3 minutes later, even though the referenced Secret held the `clientSecret` key the whole time. Nothing self-heals: the only recovery was `rollout restart`. ## Root cause (confirmed in code) The Mirror learns referenced-Secret bytes through exactly two paths: 1. `bootstrap()` (`internal/snapshot/mirror.go:172`) fetches every watched Secret, but runs only once at startup; and 2. `ingest()` (`internal/snapshot/mirror.go:223`) folds watch events in, but only for Secrets already in `m.watched`: the guard at `mirror.go:238-242` drops events 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 but never 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, sets `SecretReady=false`, and the OIDC Flow fail-closes 503 (ADR 0011, `internal/serve/oidc.go:152-170`) permanently, until that Secret is modified again or the pod restarts. The standard onboarding is exactly this race. `docs/guides/protecting-an-existing-app.md` creates 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-frigate` and `k8s-hub` went through the 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 and can rewrite the Registry with a fresh `SecretReady` flag (`internal/registry/builder.go:152`), but the data plane derives readiness only from 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:01` flux applies the `searxng` OauthClient and the ExternalSecret that adds the `clientSecret` key to the existing `searxng-oauth-secrets`, one revision. - `~15:12:02` ESO syncs the Secret (key present, `Ready=True/SecretSynced` from here). - `15:12:02` leader creates `ReferenceGrant authz-bridge-searxng-searxng`; `15:12:03` the Mirror ingests the Registry change: `{"msg":"Rebuilt the Snapshot","apps":4,"rebuilds":41}` — the last rebuild before the restart. - `15:12:52`-`15:13:20` repeated debug lines: `{"level":"debug","msg":"App client secret is not ready","app":"searxng/searxng"}`; the public route 503s (`server: envoy`, empty body). - Throughout, the OauthClient CR reports `Available=True / Degraded=False`: the leader reads the Secret through its own cached client and sees it; only the data-plane Mirror is stale. - After `~15:13:20` gateway Checks stop reaching the bridge entirely (503s keep coming from envoy, zero Check log lines). Unexplained — see follow-up 3. - `15:15` `kubectl -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 1. Fetch on watch-set growth. Where `parseRegistry` (or `rebuild`) detects a `watched` entry missing from `m.secrets`, `fetchSecret` it and store the result (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 `Build` filter — simpler, but keeps a bytes copy of every Secret in the cluster. 2. Make permanent degradation visible. "secret not ready" is logged at debug with no metric; the CR claims `Available=True` the entire time. Add a per-App unavailable counter (e.g. `authz_bridge_app_degraded{app,reason}`) and/or rate-limited `Info` logging for repeated degraded Checks, so an alert can catch a stuck App without curling by hand. 3. Investigate the silent gateway: after ~2.5 minutes of 503 Check responses, 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).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lab/authz-bridge#63
No description provided.