Worker Program Scope — Cutover & Operations (#1515 / ADR-044)
ADR-044 makes a worker’s programs a required authorization attribute. They come from the upstream IdP alone, through canopy-identity’s federation:
-
canopy-identity projects them from the upstream’s claims at the profile’s programs pointer (
/primary_programsunder thekanidmpreset; IdP Integration › The upstream profile), at sign-in and again at every renewal (crates/canopy-auth/src/upstream/projection.rs). None, or an empty list, is refusedmissing_primary_programs; anything that is not a list of program wire ids is refusedmalformed_primary_programs. A renewal whose claims are refused revokes the session. -
canopy-web admits the session’s programs again as the worker’s
WorkerProgramScope(services/canopy-web/src/program_scope.rs), which gates its program views and writes. -
Each delegation token carries the session’s programs as
programs(Principal::programson the receiving service).
There is no canopy-side override and no role-tier bypass: the deployment’s override is the IdP’s program assignment. A worker whose upstream entry lacks it cannot sign in.
1. Upstream inventory (before go-live)
At the deployment’s upstream (the one identity-upstream.yaml names),
enumerate the workers without a usable program assignment and backfill them.
Two distinct defects to look for:
-
the claim mapping is missing — no worker is admitted;
-
the mapping exists but the worker’s assignment is unset — only some workers are refused, which is the harder case to spot.
On Kanidm a worker’s programs are its memberships in the
canopy_program_<program> groups, which the canopy-web client’s claim maps
project into primary_programs; a worker in no such group is the gap.
devstack/kanidm/migrations/00-canopy.hjson is the devstack’s instance of the
convention.
Backfill before go-live, not during. A worker legitimately authorized for
everything is assigned all five programs (snap, tanf, medicaid, caps,
wic) — the IdP is the only place that decision is expressed. chip is a
wire id of its own, which canopy-web scopes as medicaid.
Privileged workers are not exempt: supervisors, jurisdiction admins, Studio admins, analysts and auditors need programs exactly like caseworkers.
2. Claim preflight
A session renews its claims from where it opened them: the profile pairs
claims_from: id_token with refresh: reissues_id_token, or userinfo with
userinfo (crates/canopy-auth/src/upstream/profile.rs). The programs must
therefore be on that source at sign-in and on every refresh. A mapping
present only at the initial grant produces a deployment where everyone signs
in and is signed out at the first renewal.
Sign one worker in at canopy-web, keep the session past one renewal
(canopy-web renews at least every 900 s, FRESHNESS_SECONDS in
crates/canopy-auth/src/identity_session.rs), and load a page: a worker still
signed in has passed both. A worker signed out at the renewal, with
canopy_identity_federation_answers_total{answer="missing_primary_programs"}
counting it, is the classic "works until it doesn’t" misconfiguration.
3. Watching refusals
Watch the refusal signals at go-live, and keep them on the dashboard:
-
canopy_identity_federation_answers_total{answer}(canopy-security) — the primary signal. A refusal’sansweris its code:missing_primary_programs,malformed_primary_programs,no_role,no_username,subject_suspendedand the rest, at sign-in and at renewal alike. -
canopy_web.auth.admission_rejected{stage,reason}— sessions canopy-identity opened that canopy-web’s own admission refused:stage=callbackat sign-in,stage=servefor a served session. -
canopy_web.session.decode_failed— session rows whose record no longer decodes, a schema-change signal rather than an ordinary sign-out.
The refusal rate need not be zero: a worker with no program assignment should be refused.
4. Steady-state operations
Onboarding. Assigning programs is part of worker provisioning at the
upstream. A new worker without them is refused with a banner naming the
missing program assignment — the sign-in page does not loop back to the
IdP, so the failure is legible to the worker and reportable to the service
desk (services/canopy-web/src/auth/refusal.rs).
Break-glass. Granting a worker emergency cross-program access means assigning the programs at the upstream. There is no canopy flag, and adding one would create a second source of truth for authorization scope (ADR-044).
Revocation delay. A program change at the upstream reaches canopy at the
session’s next renewal, at most 900 s after its last one; a delegation token
already minted carries the old programs for at most its 300 s lifetime
(DELEGATION_TOKEN_MAX_LIFETIME_SECS). When that is too slow — a revoked or
compromised worker:
-
disable the worker at the upstream;
-
suspend the worker’s canopy subject at canopy-web’s
/admin/security(a security administrator, stepped up). canopy-identity then mints the subject no delegation token and opens it no session (subject_suspended), for canopy-web and canopy-cli alike, and revokes its sessions at their next renewal (Security Operations › Subjects and web sessions); -
to end canopy-web’s own session rows at once as well, run the logged end canopy-web’s store runs (
END_SUBJECT_SESSIONS,services/canopy-web/src/web_session/sql.rs). Never a bareDELETE: the statement deletes the rows and records each end inweb_session_endtogether.
-- :'worker_sub' is the worker's canopy subject, the record's `sub`.
WITH gone AS (
DELETE FROM web_session WHERE record ->> 'sub' = :'worker_sub'
RETURNING id, token_hash, record, created_at
), logged AS (
INSERT INTO web_session_end (session_id, kind, token_hash, subject, created_at, reason)
SELECT id, 'web', token_hash, record ->> 'sub', created_at, 'operator' FROM gone
)
SELECT id FROM gone;
A sign-in whose flow replaces one of the sessions this ended is refused at the callback, since the session it replaces ended by an operator; any other sign-in (another browser, a later one) is stopped only by the upstream’s disablement or the subject’s suspension.
Diagnosing "a worker can’t sign in". The banner names the class, and
canopy-web logs sign-in refused with the code. no_role is #1024’s rule (no
role in canopy’s vocabulary), missing_primary_programs is an absent or empty
assignment, and malformed_primary_programs names a program canopy does not
recognize (check for a typo, or a program that needs a canopy change, not a
mapping change).
Devstack
The devstack’s worker programs are the cast’s canopy_program_* group
memberships in devstack/kanidm/migrations/00-canopy.hjson. To change one,
edit the file and run cargo xtask dev refresh: an edit under
devstack/kanidm/ marks the infrastructure stale, and the bring-up sees the
cast’s changed digest and provisions the cast afresh on an empty Kanidm volume
(xtask/src/devstack_identity/cast.rs), with new passwords and TOTP seeds in
.devstack/idp/kanidm.json, and links it to its seeded subjects again. Then
sign the worker in again. See
Local Development › Upstream IdP: Kanidm.