ADR-046: Worker Directory — canopy-security Host, JIT Population from Observed Logins
Status: Accepted (2026-08-29); amended by ADR-049 (2026-09-30), effective 2026-10-12: Addendum 3
Issue: #597 (design ratified on-issue 2026-08-10; decoupled from epic &52)
Relates to: ADR-019 (adopts CRAIG ADR-026 lazy observation — this ADR implements it), ADR-023 (multi-IdP seam), ADR-043 (identity constraints), ADR-044 (role freshness bound), #1008 (opaque subs), #702/#729 (list-workers consumer)
Context
The worker-portal audit surfaces resolved audit_events.user_id through a
hardcoded devstack-fixture UUID map (fixture_display_name) — unshippable:
a post-deploy worker rendered as "another worker" forever. ADR-019 already
names the sanctioned pattern (a worker_identities-style table populated
lazily from observed JWT claims, never from IdP admin APIs) but it was
never implemented.
Decision
-
Host: canopy-security. It owns
audit_eventsand the events API whose actor UUIDs the directory resolves. New tableworker_directorykeyed(issuer, subject)—subjectis an OPAQUETEXTsub (#1008: never a UUID by contract),issueris the canonical EXTERNAL discoveryissuer(what token validation pins; internal spellings of the same realm must not mint a second identity). Plain mutable upsert table: outside the ADR-014 chain, no append-only trigger, no archive twin. -
Population: JIT from observed logins, no IdP admin APIs. The BFF fire-and-forgets
POST /v1/security/workers/observed(service-only) from BOTH the login callback and the slow-path refresh re-admission point, carrying the just-validated claims (sub,preferred_username,email?, derived role slug). The refresh hook bounds role staleness to one access-token lifetime (the ADR-044 freshness bound) — not merely the next full login. At-most-once, no retry: a lost observation self-heals at the next login/refresh; a canopy-security outage never degrades login (whole spawned task time-bounded). -
Read surface:
GET /v1/security/workers(list,last_seen_at DESC, page cap 200, the #702/#729 team-enumeration seam) andGET /v1/security/workers/lookup?issuer=&subject=(query-borne — an opaque sub is not path-segment-safe) — both behind the #1568 service-or-admin dual gate. Email crosses the wire ONLY masked (j***@domain), and only on the single-worker lookup. -
BFF resolution: the shared
resolve_actorseam takes asub → display namemap from a process-wide names cache (300s TTL, single-flight, paginated fetch-all bounded at 10,000 rows with a WARN on overflow — active workers win, the list is recency-ordered; SERVE-STALE past TTL through a 30s failure cooldown, so an upstream blip costs freshness, never names, never the page). "you"/"system" stay session-relative and are never cached. Display prettification (jane.caseworker→ "Jane Caseworker") is presentation-layer only — the directory stores the rawpreferred_username, the only name claim the trimmed realm profile scope emits. -
Cross-IdP sub collision tie-break: the sub-keyed BFF map takes the most-recently-seen identity (first occurrence in the recency-ordered walk). The real fix — a
source_idpcolumn onaudit_events— is DEFERRED until federation actually ships (single issuer today; the 2026-08-10 ratification). -
Seed posture: the devstack seeder upserts rows ONLY for its own seed-cast worker UUIDs (the
user_ids seeded audit rows carry), username-style names, under the visibly synthetic issuerurn:canopy:seed— never the realm-fixture subs, whose rows arrive through the real hook when those users actually log in. No truncate on re-seed: real observed rows survive. -
Log rule: no tracing field on the observation path carries the email — hook failures log issuer + subject only.
Consequences
-
Accepted limitation (ratified): never-logged-in workers have no row — zero logins = zero caseload = zero audit rows; they list nowhere and render "another worker" if referenced.
-
No retention/expiry: the table is bounded by workforce size plus test-minted residue (integration tests use unique per-run subjects); the recency-ordered walk keeps departed workers out of the cache map only past the 10k ceiling. Revisit if a deployment’s directory approaches the ceiling.
-
canopy-appeals persists actors as free-string
preferred_usernamevalues, not subs — historical appeal rows do not join this directory (pre-existing; unchanged here). -
The #702/#729 MiniBar remains dual-blocked: this delivers the directory half; per-worker workload stats still need assignment data (#607).
Addendum (2026-09-26, #1008) — opaque subjects in every row; the issuer still deferred
Item 1 made the directory’s subject an opaque TEXT sub, but the rest of
the fleet projected the same sub into UUIDs: attribution columns, the
composition user layer, worker path segments. #1008 extends item 1’s rule
to every row. The Decision text above is not edited.
-
One type.
canopy_types::identity::OidcSubject(ADR-043 Amendment 1) carries a worker’s subject everywhere:Claims.sub, the directory wire shapes (WorkerObservedRequest,WorkerDirectoryEntry,WorkerLookupParams), the ADR-027 worker author, and every attribution column, asTEXT. The directory row decodes its subject as one, so a malformed stored subject is a decode error, not a name. -
Taken exactly. The observation and the lookup no longer trim the subject:
" alice "and"alice"are two workers. An invalid subject is refused before any write or read: 422 on the observation body, 400 on the lookup query. -
Wording. Item 1’s "actor UUIDs the directory resolves" and item 6’s "seed-cast worker UUIDs" read as subjects:
audit_events.user_idisTEXTand resolves by exact subject, and a seed-cast worker’s subject need not be a UUID. -
The issuer is still not stored (item 5 stands, and ADR-043 Amendment 1 adds no issuer column). Two IdPs issuing the same
subwould collide in every attribution column, not only in the BFF names map. The trigger for a per-row issuer is a ruleset with more than one[[idp]](#515, #568); with a single issuer, the subject alone is unique.
Addendum 2 (2026-09-26, #515, ADR-048) — the per-row issuer trigger is a second trusted issuer
The addendum above names "a ruleset with more than one [[idp]]" as the
trigger for a per-row issuer. #515 changed what an [[idp]] entry is: a
sign-in chooser entry at the one trusted issuer, which selects an upstream and
never names an issuer (ADR-048).
Several entries now share one issuer, so the subject alone stays unique.
The trigger is therefore more than one trusted issuer. That is ADR-048’s reopen trigger (#2342), and firing it re-arms the per-row issuer (#2335). Item 5 and the addendum above otherwise stand.
Addendum 3 (2026-10-12, #2883, ADR-049) — the directory on canopy subjects
ADR-049 mints canopy’s own subjects (D8) and federates every sign-in through canopy-identity in canopy-security, and its plan I3g made that effective. The Decision text above is not edited.
-
Keyed on the canopy subject; the table is unchanged. canopy-web observes each worker at sign-in with canopy-identity’s issuer identifier as the
issuerand the worker’s canopy subject as thesubject(observeinservices/canopy-web/src/auth/routes.rs). A canopy subject is a UUID v7 minted for each upstream(iss, sub)pair.worker_directorykeeps its(issuer, subject)key, and attribution records the same canopy subject (Principal::actor), so names still resolve by exact subject. The seed links keep each cast worker’s canopy subject equal to the realm id its rows already hold (ADR-049 K8), and item 6’s synthetic seed rows are unchanged. -
Item 2: sign-in depends on canopy-security. canopy-identity, hosted in canopy-security, opens every web session, so a canopy-security outage now stops sign-in (D8). The observation itself stays fire-and-forget, sent under canopy-web’s system token for canopy-security, and carries no email. It runs at sign-in only: a session’s renewal does not re-observe, so a row’s role is as of the worker’s latest sign-in.
-
Item 5 and the addenda: no collision remains. Two upstreams' equal
subs mint two canopy subjects, so neither the names map nor an attribution column can collide, and no per-row issuer is needed; #2335 closed as obsolete (ADR-049 Consequences).