Identity plane split, plan I2e: security administration (epic &132)

Status: Done (2026-10-06) — !1573
Epic: &132 (stage I2 of &130)
Issues: #2729 (w5), #2730 (w3), #2731 (w5), #2732 (w3), #2733 (w5), #2734 (w5), #2735 (w2), #2736 (w3); follow-ups #2737, #2738
MR: feat/identity-admin: U1–U8 in order, titled "canopy-identity security administration (#2729 … #2736)".

The eight issues are one deliverable, security administration, and each unit depends on the one before, so they ship as one MR under the maintainer’s one-MR-per-related-group ruling, one commit per issue. U1’s commit adds this page and its nav entry: the group Identity Plane Split (epic &130) holding * Identity plane split, plan I2e — security administration (epic &132), placed just above ** Completed Plans Archive in docs/modules/ROOT/nav.adoc, as plans I2a–I2d did. U8’s commit closes the plan.

This is a Design + Scope plan. GitLab owns tracking. The plan freezes when U1 starts.

Context

ADR-049 D12 gives canopy-security four kinds of revocation: subject suspension, session revocation, client disablement and key revocation; "the admin routes require a security-admin role. They are surfaced in canopy-web, and every change is audited." D6 adds step-up: security administration needs an auth_time within 10 minutes. D8 and Amendment 6 F7 make re-linking an upstream identity to a subject a security-admin write.

In the tree today:

  • identity_suspend_subject and identity_lift_subject_suspension are granted to nobody; the issuer probe enforces it (identity/probe.rs, NoSuspensionExecute), and operators run them as the migration identity (Security Operations). identity_revoke_key is granted to nobody and has no Rust caller.

  • Session revocation works by session id, but its reason CHECK has no admin cause (logout, upstream_refused, projection_refused, upstream_changed, suspended), and its client column is "always the session’s opener".

  • Client disablement is the boot-read enabled flag (Amendment 3 A7: "Runtime disablement is I2’s").

  • identity_subject_links is immutable (PK (upstream_iss, upstream_sub), UNIQUE (subject_id, upstream_iss), a trigger refusing UPDATE and DELETE), so a renamed upstream issuer mints new subjects with no way back.

  • ROLE_VOCABULARY (crates/canopy-auth/src/claims.rs) filters both projections and holds no security-admin role; xtask pins it to exactly the names a role check (has_role, require_any_role, …) reads. Today’s Keycloak Claims carry no auth_time; DelegationTokenClaims.auth_time does.

  • No route receives canopy-identity tokens yet. IdentityTokenValidator and MemoKeySource exist, the JwksMemo is shared in main.rs, and the call graph has canopy-web → canopy-security as Both.

  • Each identity migration ends with an audit refusing any grant to a role but the owner and the issuer; the issuer’s matrix is hard-coded in identity/probe.rs. Logins live in devstack/postgres/roles.sql and docker-compose.yml, settings keys in config.rs, pool labels in the closed PoolName; the lock inventories are crates/canopy-test-lib/src/global_ddl.rs and xtask’s ("security", 9) pin.

  • The issuance log has no actor column and a closed grant_type set.

Scope

In scope: U1–U8 below.

Out of scope:

  • canopy-web’s admin screens and their max_age sign-in (I3: canopy-web signs in through canopy-identity only then);

  • a read route for the action log (#2737) and a replica rotating off its own revoked key (#2738);

  • device approval’s step-up (I2f);

  • the conformance manifest, which covers /v1 Keycloak-bearer routes only (documented, as for the token routes).

Design

Decisions (recorded in ADR-049 Amendment 8, which lands with U1)

# Decision

H1

The surface. Routes under /identity/admin/, mounted with the identity routes outside /v1, the Keycloak bearer middleware and the OpenAPI document. JSON in (at most 4 KiB), RFC 9457 problem details out (ApiError with a code); a per-IP limiter of 60 a minute (canopy_api::apply_rate_limit) and Cache-Control: no-store; a 5 s budget per request (the token and session checks by 2 s, the transaction by the end); 503 when the issuer or the admin login is unconfigured. Every write creates its action record (H4), so each answers 201 Created with {action_id, changed}; changed is false when the state was already so.

Method

Path

Body

GET

/identity/admin/subjects?upstream_iss=&upstream_sub=

—

GET

/identity/admin/subjects/{subject_id}

—

POST

/identity/admin/subjects/{subject_id}/suspend, /lift

{reason}

POST

/identity/admin/sessions/{session_id}/revoke

{reason}

GET

/identity/admin/clients

—

POST

/identity/admin/clients/{client}/disable, /enable

{reason}

GET

/identity/admin/keys

—

POST

/identity/admin/keys/{kid}/revoke

{reason}

POST

/identity/admin/links

{upstream_iss, upstream_sub, subject_id, reason}

reason is 1 to 200 bytes with no control character. The lookup answers {subject_id} or 404; the subject read {subject_id, links, suspended, sessions} (effective links, H7; unpurged sessions with session_id, opener, auth_time, ends_at, fresh_until, revoked); the clients read every compiled confidential client’s {client, registered, enabled, runtime_disabled}; the keys read every published key’s {kid, created_at, sign_from, sign_until, publish_until, revoked_at}.

H2

Who may call. A canopy-identity delegation token for canopy-security, as Authorization: Bearer, checked in order:

  1. The token: IdentityTokenValidator::new(issuer, CanopyService::Security, MemoKeySource) (G8, the last hop included). No header is 401 with a bare WWW-Authenticate: Bearer (RFC 6750 §3.1); a refused token 401 error="invalid_token"; keys unavailable, or no answer by 2 s, 503.

  2. The session and clients behind it: the session re-read with IdentitySessions::mint_view(Session(sid)) and held to G5’s judgment (the chain opener and sub); every client in the act chain enabled in the registry and not runtime-disabled (H6). A failure is 401 invalid_token, an unavailable memo 503. An admin’s revocation or suspension stops their administration at once, a disabled client’s bearers within H6’s 5 s.

  3. The role: roles.has_role("security_admin"), else 403 error="insufficient_scope".

  4. Step-up: now − auth_time ≤ SECURITY_ADMIN_MAX_AGE (600 s, exported for canopy-web’s max_age at I3), else 401 error="insufficient_user_authentication", max_age=600 (RFC 9470).

security_admin joins ROLE_VOCABULARY. The IdP must emit exactly that name in the roles claim the profile points at: a profile selects claim locations and translates no names (ADR-044). admin does not imply it.

H3

The admin login. canopy_identity_admin, created NOLOGIN by migration with the issuer’s attribute and member guards: EXECUTE on the admin functions (H4) only, and SELECT on identity_signing_keys, identity_key_revocations, identity_subjects, identity_subject_links, identity_subject_suspensions, the session, validation and session-revocation tables, identity_client_disablements and (U6) identity_subject_relinks. It writes nothing directly; the probe, the migration audit and the fixture hold exactly this list. Its pool (4 connections) comes from CANOPY_SECURITY__IDENTITY_ADMIN_DATABASE_URL, read with optional_secret: unset, boot warns once and the routes answer 503; set, a strict probe holds the matrix and a failure aborts the boot.

What the separation gives: the issuer can call no admin function and write no admin table, and its identity_revoke_session is replaced to refuse any reason but its own five (23514), so admin and relinked revocations, disablements, re-links and action rows come only from the audited functions. It does not stop a stolen issuer credential at the HTTP layer: that credential can publish keys and forge any token (the threat model’s accepted cost of D9), a security admin’s bearer included. Such a change still writes its action row with the token’s kid, which the compromise response reviews after revoking the keys. Administration depends on the issuer (minting, the JWKS memo, session reads), so while the issuer is shut out the routes are unavailable and recovery is SQL as the migration identity.

H4

Every change audited with it. An INSERT-only identity_admin_actions: action_id, recorded_at, action (suspend, lift, revoke_session, disable_client, enable_client, revoke_key, link), one target column per kind with a CHECK per action, the actor (actor_subject, actor_session, actor_token_jti, actor_token_kid, actor_client), reason, changed. Each change is a SECURITY DEFINER identity_admin_<action>(target…, actor…, reason) making the change and its action row in one transaction, returning (action_id, changed). Every such function refuses outside READ COMMITTED (25000), and the admin store opens each transaction READ COMMITTED, so a statement after a lock wait reads a fresh snapshot. H2’s refusals are tracing::warn! lines (subject id and reason code only).

This narrows Amendment 6 F3: an admin change commits its action row, not an issuance-log row; the issuance log stays the issuer’s record. Exporting both through ADR-041 waits on #1301.

H5

Suspension and session revocation. Suspend and lift call the existing writers with the actor’s subject as actor; a repeat writes no event. Every mint checks suspension (G5) and H2 re-checks it. Revoking a session writes reason admin with the actor’s client; only the client column’s comment changes.

H6

Runtime client disablement. An INSERT-only identity_client_disablements (client, version, disabled, recorded_at, action_id; latest version wins), written under a two-key transaction advisory lock per client. A ClientStatusMemo on the issuer pool (at most 5 s old, never older after a failed read, as JwksMemo) is read by every client authentication, after the signature and before the jti: a disabled client is invalid_client / client_disabled, an unavailable memo 503 client_status_unavailable. The YAML enabled: false stays absolute. A disablement takes effect within 5 s; disabling canopy-web stops admin requests too, and the runbook keeps the SQL path to re-enable it. The issuer pool grows from 17 to 18.

H7

Re-linking. An INSERT-only identity_subject_relinks (upstream_iss, upstream_sub, version, subject_id, recorded_at, action_id); a pair’s effective link is its latest relink, else its base link, which identity_link_or_mint_subject and identity_open_session (replaced) read. Each pair has a transaction advisory lock: identity_admin_link takes it exclusive, locks the target and current subjects FOR UPDATE in ascending id order, then reads; link-or-mint takes it shared inside the open’s READ COMMITTED transaction. An open waits for an in-flight re-link and opens as the new subject; a re-link waits for in-flight opens and revokes their sessions.

Under those locks: an unlinked pair gets its base link (or relink version 1 when the target’s base link under that issuer already exists); a pair linked elsewhere gets relink n+1 and its live sessions revoked relinked; a pair linked to the target is changed false; a target already holding an effective link under that issuer for another sub is 23505 (409 link_conflict); an unknown subject P0002. No subject is created, so D8’s seed links are I3’s.

H8

Key revocation. identity_admin_revoke_key wraps identity_revoke_key (p_actor the actor’s subject; revoked_by the admin login). Unknown is 404, a repeat changed false. The JWKS and MemoKeySource drop the key within 5 s, receivers within their refresh. A replica keeps signing with its own revoked key until it rotates (#2738); the runbook says to restart it.

U1: the database record (canopy-security)

  • Migration 20261216000000_identity_admin.sql: the role and its guards; identity_admin_actions and identity_client_disablements; reason admin; identity_revoke_session replaced (H3); identity_admin_{suspend,lift,revoke_session,disable_client,enable_client,revoke_key}; admin grants; issuer SELECT on the disablements; the closing audit admitting the admin role; markers, global_ddl.rs and the xtask pin (10). identity/registry.rs's REGISTRY_TABLES and REGISTRY_FUNCTIONS; the issuer probe (SELECT on the disablements, no identity_admin_*).

  • Tests (tests/identity_admin_store_test.rs, an admin_login fixture in tests/common/issuer.rs): each function’s change and action row together and a rollback leaving neither; changed on repeats; P0002, 23503, 23514; immutability; REPEATABLE READ refused 25000; the admin login refused direct writes, the issuer every identity_admin_*; the issuer’s identity_revoke_session refusing admin and accepting its own reasons.

  • Docs: data-models/canopy-security.adoc; security-operations.adoc (grants; the compromise response reviews admin actions by actor_token_kid and notes the routes are unavailable while the issuer is shut out); ADR-049 Amendment 8; this page and its nav entry.

  • Erratum (2026-10-06): the admin_login fixture is tests/common/admin.rs, over a role-agnostic mirror_login in tests/common/issuer.rs; the tests assert P0002 and 23514, since each function checks its target before writing, and add two racing transactions per locked change (disable, key revocation) settling to one change.

U2: the admin login’s pool (canopy-security)

  • CANOPY_SECURITY__IDENTITY_ADMIN_DATABASE_URL in config.rs; PoolName::IdentityAdmin (identity_admin) in PoolName::ALL; the census NotPeer entry in xtask/src/cmd/call_graph/observed.rs; connect_admin_pool (4 connections, application_name = canopy-identity-admin); the strict admin probe; main.rs per H3; roles.sql and compose.

  • Tests: the probe accepting the migrated grants and refusing a widened grant, a superuser and an issuer member; the pool’s doc table.

  • Docs: configuration-reference.adoc; the pool-label lists in shared-crates.adoc and deployment-guide.adoc.

U3: authenticating security administrators (canopy-auth, canopy-security)

  • canopy-auth: security_admin in ROLE_VOCABULARY (its tests, xtask’s scan), RoleSet::has_role, SECURITY_ADMIN_MAX_AGE. canopy-security: identity/admin.rs, admin/guard.rs (H2; the bearer’s kid from its verified header; registry-enabled act clients), the router (H1) and the two subject reads. G5’s judgment moves to identity/sessions.rs as SessionVerdict (Ended, Mismatch, Suspended, Stale), with its test; the mint maps it to Cause, the guard to 401.

  • Tests (in process, scripted sessions and keys): each H2 refusal in order with status and challenge (none, malformed, another receiver’s, a system token, unknown kid, revoked, suspended, stale, a registry-disabled client, non-admin); auth_time 600 s accepted, 601 s refused; stalled keys 503; the reads; no token logged; the evil-input corpus (jws_evil_cases! on the bearer, malformed and oversized bodies and reasons, bad path ids).

  • Docs: api/canopy-security.adoc (the admin section), security.adoc, authorization-inventory.adoc.

  • Erratum (2026-10-06): the step-up bound is SECURITY_ADMIN_MAX_AGE_SECONDS: i64 (600), beside canopy-auth’s other session bounds in seconds; the guard checks it through a pure authorized(claims, now), tested at 600 s and 601 s.

U4: suspension and session revocation routes (canopy-security)

  • The three routes. Tests (DB, tests/identity_admin_test.rs, a federation-opened session): suspend stops the next mint (subject_suspended) and the admin’s own requests when the admin is the target; lift resumes; revoke ends minting (session_ended); the action rows' actor fields; 404 and 400.

  • Erratum (2026-10-06): U4’s tests observe each effect in the store’s mint_view, the row a mint judges (suspended, revoked), over a worker session written as the migration identity, as U3’s rig does; the token endpoint’s subject_suspended and session_ended for an admin write are U8’s end-to-end proof. They add a reason of exactly 200 bytes (ASCII and two-byte) accepted, and no refused write recorded.

U5: runtime client disablement (canopy-security)

  • identity/client_status.rs (ClientStatusMemo, injected clock), checked by ClientAuthenticator on all three paths and by the guard for every act client; ClientAuthRefusal::Disabled; issuer pool 18; the routes and GET clients.

  • Tests: the memo’s bound on a fake clock, single flight, failure 503 with no stale set; disabled invalid_client with its row and no jti spent; enabling restores; a YAML-disabled client stays refused; revocation refused; a pre-disablement admin bearer refused once the memo turns; DB route tests.

  • Erratum (2026-10-06): the memo implements a ClientStatus trait asked with the caller’s deadline; ClientAuthenticator::new and TokenEndpointParts require one, so nothing defaults to "none disabled", and the check sits in authenticate, which the three paths share, once the claims verify. GET clients answers {clients: […​]}; a client id no compiled confidential client has is 404 client_not_found. The SQL path that re-enables canopy-web passes the nil session, a fresh jti and the kid repeat('A', 43), since every action row names an actor; the lockout test runs it.

U6: re-linking (canopy-security)

  • Migration 20261217000000_identity_relinks.sql: the relinks, reason relinked, identity_admin_link, the replaced functions with the pair lock, the action link, grants (admin and issuer SELECT on the relinks), audit, pins (11). Both probes' matrices and fixtures; the lookup and subject read on effective links; POST /identity/admin/links.

  • Tests (DB): the rename scenario; pre-linking; a repeat; link_conflict; an unknown subject; concurrency in both orders; two pairs re-linked to one subject at once (one link_conflict); REPEATABLE READ refused; the reads after a re-link and after the collision fallback; both boot probes against the full migration set.

  • Erratum (2026-10-06): the effective subject is read inline in each function, adding no helper to the function lists; each relink names its action (action_id), and the action table gains shape CHECKs on the upstream pair; the open takes the pair’s shared lock too, so it holds when called on its own. The store-level tests are tests/identity_relink_test.rs, the route and read tests tests/identity_admin_test.rs.

U7: key revocation route (canopy-security)

  • The route and GET keys. Tests (DB): the JWKS omits the kid once its memo turns, and an onward subject token under it is refused subject_token_unknown_key; 404; a repeat. Docs: security-operations.adoc (the route is the path; the SQL stays for the compromise response).

  • Erratum (2026-10-06): U7’s tests observe a revoked key’s tokens refused through the admin guard, which verifies with the same IdentityTokenValidator over the JWKS memo as the token endpoint’s onward check (token_rejected once the memo turns); the token endpoint’s subject_token_unknown_key for an admin revocation is U8’s. GET keys lists the keys still in their publish window, revoked or not, at most 128, and answers {keys: […​]}; a kid outside the registry’s shape is 400 kid_invalid.

U8: the in-process proof (canopy-security)

  • services/canopy-security/tests/identity_admin/end_to_end.rs: a federated security_admin session, canopy-auth’s DelegationTokenSource for canopy-security, each write route with its effect observed at the token endpoint, a non-admin refused 403, an 11-minute-old sign-in refused with the RFC 9470 challenge.

  • Erratum (2026-10-06): the proof is two tests, the subject and session writes and the rest; the re-link’s target is a subject linked under the upstream’s old issuer, since one subject holds one link per issuer. The memos run on a manual clock.

  • Docs: Amendment 8’s as-built record. The plan closes here: Status Done (YYYY-MM-DD) — !N; the page moved to docs/modules/ROOT/pages/plans/archive/, every xref following; the nav group removed and the archived entry appended, suffixed — DONE YYYY-MM-DD, as the last line of the Completed Plans Archive group; cargo xtask plan-lint --done docs/modules/ROOT/pages/plans/archive/identity-plane-split-i2e.adoc with --allow-open for 2729 to 2738.

Conventions every unit follows

  • Every new input has its evil-input cases; errors never echo input; logs carry canopy subject and session ids, never a token, credential or upstream sub.

  • Times come from chrono::Utc::now() (D14); tests inject clocks and never sleep. Database tests live in tests/.

  • Every unit ships its CHANGELOG.adoc bullet and the canonical page for its surface.

Units

  1. U1 (w5) — feat(security): record security administration in the database (#2729).

  2. U2 (w3) — feat(security): connect as the security-admin login (#2730).

  3. U3 (w5) — feat(security): authenticate security administrators (#2731).

  4. U4 (w3) — feat(security): suspend subjects and revoke sessions by route (#2732).

  5. U5 (w5) — feat(security): disable clients at runtime (#2733).

  6. U6 (w5) — feat(security): re-link an upstream identity to a subject (#2734).

  7. U7 (w2) — feat(security): revoke keys by route (#2735).

  8. U8 (w3) — test(identity): prove security administration end to end in process (#2736).

Verification

  1. Per unit: fmt; clippy in both profiles; nextest for canopy-auth and canopy-security; rustdoc-private; quality-budgets; feature-builds; migrations-lint and db-pools (U1, U2, U5, U6); the named database tests with CANOPY_TEST_INFRA=required against a reloaded devstack.

  2. End to end: U8 drives every write route with a real federated security admin and observes each effect at the token endpoint.

  3. Per MR: cargo xtask dev reload, then git push (the pre-push battery).

Review log

round vendor resolved model verdict

1 (2026-10-06)

Anthropic

claude-opus-5-5

no-ship. Two blockers, fixed: an open racing a re-link could neither open as the new subject nor be revoked, and crossing re-links could deadlock (H7’s pair lock and ordered subject locks); admin session changes skipped F3’s issuance-log row unstated (H4’s narrowing). Also taken: the registry scan lists, the census entry, PoolName::ALL, Amendment 8 in U1, SessionVerdict, the optional admin URL, the admin grant list, seed links scoped out, the base-link collision, 201 for writes, the bare Bearer challenge, the one-MR reason, the follow-ups in plan-lint, the evil-input corpus.

2 (2026-10-06)

human-run

not stated

Seven findings, all fixed: an existing admin bearer outlived its client’s disablement (H2 checks every act client); administration depends on the issuer (H3, with SQL recovery during containment); the stolen-issuer claim was overstated (H3 states what the separation gives; identity_revoke_session refuses the admin reasons; action rows record the bearer’s kid); the READ COMMITTED contract; U6’s probe matrices and fixtures; the lookup’s effective links; the role mapping is the IdP’s. No round 3.

Edit this page · default