ADR-085: Internal Token Issuer — CRAIG Mints Every Internal Token; the IdP Only Signs Workers In

Status

Proposed (2026-10-25), #2689 (epic &112, stage S2). Implemented by plan Internal Token Issuer (U1–U16) and plan Internal Token Issuer, Cut-over and Production (U17–U21); it becomes effective at the switch (U17). Until then ADR-028, ADR-029 and the sections amended below describe the running system.

Ruling (the maintainer, 2026-10-24): adopt Canopy’s identity architecture by porting it, never by sharing a crate; the issuer stays simple and bounded, like Keystone’s Fernet / JWS tokens; the IdP becomes login-only; keys rotate in stages and are published as JWKS; services validate locally and statelessly; #2685 folds in; an external security review gates production.

Supersedes at the switch: ADR-028 (service identity and X-Craig-Actor). Amends at the switch: ADR-026 (subjects and directory hydration, D7), ADR-029 (receivers stop introspecting, D14), ADR-021 (the internal validation policy, D9), ADR-076 D2 / D3 (the portal channel, D6), ADR-013 (BFF sessions move server-side, D6), ADR-011 (the CLI’s device flow, D12). ADR-005 is left to #2690.

Amended (2026-10-26, #2739): D2’s role names are required; see § Amendment — #2739.

Context

CRAIG trusts its IdP as the issuer of every token: worker bearers at every service, a client_credentials token per service (idp-integration.adoc:7, :16), and the portal subject token relayed in X-Craig-Subject (ADR-076 D2, adr-076-portal-identity.adoc:168). The 2026-10-24 comparison with Canopy found these consequences:

  1. A heavy, IdP-shaped onboarding ask. A state provisions 14 OIDC clients, 11 service:* roles, 11 service-account users and the audience mappers (idp-integration.adoc:403; the devstack realm’s 14 clients, devstack/keycloak/craig-realm.json:103-1533), plus the partners.replay-check scope (idp-integration.adoc:209). Every service holds an IdP client secret (for example docker-compose.yml:430-431).

  2. The actor-pair threat ADR-028 accepts (adr-028-service-identity.adoc:229-236). Each service signs actor JWTs with its own key under the fleet-wide audience craig-internal-actor (crates/craig-auth/src/actor_token.rs:60). A receiver resolves the key by the actor’s own (iss, kid) and checks iss against itself (actor_verifier.rs:261-274), apart from the bearer (middleware.rs:300-326). So a compromised service’s bearer plus any captured actor JWT evaluates as that worker, and the audit names only the first hop. The fix, #1481, is blocked (adr-028:251-257).

  3. Service identity rides the IdP’s claims. A service is a service: role in the IdP’s roles claim (claims.rs:396-399). An IdP whose client_credentials tokens are JWE forces every receiver to introspect (idp-integration.adoc:31; ADR-029 :41-43).

  4. Subjects are coupled to the IdP. sub must be a UUID: a non-UUID sub is a 500 in parse_actor_sub (crates/craig-api/src/request_claims.rs:573-577) and a silent skip in the identity cache (services/craig-security/src/api/worker_identity_middleware.rs:116). worker_identities.sub is a UUID primary key (services/craig-security/migrations/20260508210000_worker_identities.sql:11-12). That is #2685.

  5. Long-lived keys. IdP keys keep verifying for up to 24 h after the last refresh (crates/craig-auth/src/jwks.rs:46). Actor keys are long-lived per-service private JWKs, rotated by hand (idp-integration.adoc:464-485).

S0 (#2684, #2686, #2687) fixes neutrality defects on today’s path, but it does not change who issues. Canopy hit the same wall: Kanidm cannot be an internal issuer (Canopy adr-049-identity-plane-split.adoc:43-52). Its answer was canopy-identity, its own issuer (ADR-049 D1–D14, :72-358), with the IdP profile as deployment configuration (ADR-050 §2, :40-49).

ADR-028 derives from Canopy ADR-019 (adr-028:56-61). It rejected self-signed service tokens and an identity service (adr-028:75, :77). Canopy ADR-049 D2 adopted exactly those options, modified (adr-049:85-106), and this ADR does the same. The annex lists every Canopy control and whether CRAIG retains, changes or omits it.

The Keystone precedent. OpenStack Keystone’s Fernet key repository has one staged key, always the next primary; one primary key, which signs; and secondary keys, which only validate. Rotation promotes the staged key (Fernet FAQ). Its JWS tokens are ES256: a new public key reaches every server before its private key signs, and validation needs only public keys (JWS key rotation). D8 keeps that shape.

Decision

CRAIG specific Becomes

14 IdP clients (craig-realm.json:103-1533)

One confidential IdP client per deployment, used by both BFFs (D1)

Service-signed X-Craig-Actor JWTs, peer JWKS

Issuer-minted worker tokens, one hop at a time; the ADR-028 pair threat is gone (D3, D12)

RFC 7662 introspection at receivers

Optional, and unused: internal tokens are always local JWS (D14)

The IdP sub as the worker key

A CRAIG subject, minted or adopted once per upstream pair; #2685 folds in (D7)

A service’s IdP sub as its actor

A typed machine actor that is never a subject (D3)

Cookie-only BFF sessions (ADR-013)

Server-side BFF sessions with one renewal leader per session (D6)

D1 — Two layers, one issuer each

  • Edge. There is exactly one upstream OIDC IdP per deployment, with exactly one confidential client, craig. Its relying parties are craig-web and craig-portal (two redirect URIs). The IdP owes CRAIG OIDC sign-in only: an authorization code with PKCE S256, and an id_token carrying auth_time and the roles claim at the configured path (#2684’s RolesClaimPath, CRAIG_IDENTITY_ROLES_CLAIM_PATH). A refreshed id_token is the evidence for renewal.

  • Internal. There is exactly one issuer, the issuer process of craig-security (D2), and every receiver trusts only it.

  • CRAIG never verifies a human password. The password grant goes from every caller, tests included.

D2 — The issuer is a process role of craig-security

  • One crate, two processes. The issuer is craig-security code (src/identity/), in craig-security’s image, writing to craig-security’s database, which already owns worker_identities and audit_log (Canopy D2). It runs as a third process mode beside the migrate gate and --print-openapi (services/craig-security/src/lib.rs:149-160), deployed apart from the ordinary craig-security process, and serves only /identity/*, /livez and /readyz.

  • Why a process, not a module. craig-security’s boot awaits RabbitMQ and the archive probe, and fetches its rulesets from craig-rules over HTTP (retrying, then degrading to an empty cache), before it serves (services/craig-security/src/lib.rs:165-216; crates/craig-api/src/bootstrap.rs:588-609; crates/craig-bootstrap/src/authz.rs:146-184), and its readiness gates on RabbitMQ and its workers (crates/craig-api/src/lib.rs:1215-1230). Canopy’s issuer module was meant to depend on its database alone, but it still awaits RabbitMQ before serving (Canopy crates/canopy-api/src/bootstrap.rs:283-285) and gates readiness on it (crates/canopy-api/src/lib.rs:1169-1171). A sign-in dependency of the whole fleet cannot share that fate.

  • Startup. Settings, the issuer pool, the privilege probe, the schema check, then the first key; then it serves. Its settings name no RabbitMQ, rules or object store, and no boot step contacts the upstream, whose keys load on the first federation. It reads no CRAIG_SECURITY__DATABASE_URL (the app login’s), and its probe refuses a pool whose role is craig_security_app. /readyz answers ready once the database answers and the first key’s 60 s staged lead has passed.

  • Receivers in craig-security. The ordinary craig-security process is a receiver like any other (D9’s key cache). The issuer’s token endpoint checks subject tokens (D12) against the published set from its in-process JWKS memo (D9), never its key ring, which holds only that replica’s keys while a token may come from any replica (Canopy services/canopy-security/src/identity/key_source.rs:3-8).

  • Boot order. Postgres, the migrate gate, the issuer, craig-rules, craig-security (which already waits for craig-rules, docker-compose.yml:978-1026), the other services, then the BFFs. The other services boot with an empty key set and refuse every token until keys appear.

  • Production. D17 sets the replica count: at least three, at most ten.

  • Hardening. The issuer process makes itself non-dumpable before it generates a key (PR_SET_DUMPABLE, through rustix; Canopy services/canopy-security/src/main.rs:41-46).

  • Database privileges (Canopy docs/modules/ROOT/pages/security-operations.adoc:139-148). craig_security_owner owns every identity_ table and function (ADR-063 migrate gate). The migration revokes craig_security_app’s inherited grants (`devstack/postgres/init.sql:139-140) and grants exactly this matrix, where f() is EXECUTE on the owner SECURITY DEFINER function identity_f. No runtime login holds UPDATE, DELETE or TRUNCATE on an identity table.

    Table craig_security_issuer (the issuer process) craig_security_app (the ordinary process)

    signing_keys

    SELECT; INSERT on kid, x, y, replica_id, requested_sign_seconds

    SELECT

    key_revocations

    SELECT

    SELECT; admin_revoke_key()

    key_cap_guard

    none (the owner trigger takes it)

    none

    jti

    INSERT on client_id, jti, expires_at; purge_client_assertions()

    none

    issuance_log

    INSERT on every column but the stamped ones

    SELECT; prune_issuance_log()

    subjects, subject_links

    SELECT; link_or_mint()

    SELECT; admin_relink(), admin_create_subject()

    suspensions, client_status

    SELECT

    SELECT; admin_suspend(), admin_lift_suspension(), admin_set_client_status()

    sessions, with INSERT-only validation and revocation records

    SELECT; open_session() (which also writes a craig-web session’s worker_identities row), renew_session(), grace_session(), revoke_session(), purge_sessions()

    none (the admin functions read them as owner)

    device_codes, native_credentials

    SELECT; start_device(), approve_device(), redeem_device(), rotate_native(), purge_devices()

    none

    legacy_issuers and their retirements, adoption_state, soak

    SELECT

    record_legacy_issuer() until the switch’s migration revokes it; admin_end_soak()

    _sqlx_migrations, schema_compat_floor (the schema check)

    SELECT

    as today

    • The ordinary process serves the security-admin routes (D13) and runs the ADR-058 archive engine (services/craig-security/src/retention_archive.rs) over the issuance log. So the issuer login cannot suspend, re-link or revoke a key, cannot read its jti store, and the ordinary process never holds the issuer login.

    • Functions. PostgreSQL grants EXECUTE on a new function to PUBLIC, so every identity_ function is created with REVOKE ALL … FROM PUBLIC before its grant, as SECURITY DEFINER with SET search_path = pg_catalog, <schema>, pg_temp. The owner alone holds revoke_key(), retire_legacy_issuer() and the break-glass functions (D8, D13). The issuer login holds no TEMPORARY on the database (Canopy services/canopy-security/migrations/20261211000000_identity_issuer_no_temporary.sql).

    • Probes. Each process probes its own login at boot and refuses to serve when it holds anything on an identity table or function beyond this matrix: the issuer probe, and an app probe ported from Canopy’s services/canopy-security/src/identity/admin_probe.rs.

    • Provisioning. craig_security_owner cannot create roles (devstack/postgres/init.sql:86 grants no CREATEROLE). The devstack init.sql creates craig_security_issuer beside the app login, with CONNECT and schema USAGE; its password is its name, the public-fixture precedent of xtask/src/registry.rs:78. The next cargo xtask dev start wipes the volume so the change applies (xtask/src/devstack_guard.rs:893-905). A deployment runs the same statements, with a secret-managed password, before the migration, which fails when the role is absent. It runs them as the provisioning role craig_security_provisioner, which holds exactly CREATEROLE, ADMIN OPTION on craig_security_issuer and membership in pg_signal_backend; the devstack init.sql creates it so. D8’s response uses that role to end the issuer’s connections and rotate its password. These names are required, staged per unit (§ Amendment — #2739).

    • Primary keys are UUID v7, except kid (both key tables), (client_id, jti) (the jti store, whose jti the client picks; Canopy services/canopy-security/migrations/20261210000000_identity_issuance_stores.sql:49), the guard’s one row, and an adopted subject’s id, which is the upstream UUID of any version (D7). These are stated exceptions to the coding-conventions UUID v7 rule.

D3 — Credentials and the machine actor

Every token is a compact JWS. It is signed ES256, pinned in code, and its kid is the key’s RFC 7638 thumbprint. Its protected header is exactly alg, kid and typ, with typ: at+jwt. Each of the two layouts refuses unknown members, so one never parses as the other.

  • Worker token (the issuer-minted actor token).

    • Claims: iss sub aud exp iat nbf jti client_id sid roles act auth_time preferred_username.

    • sub is a CRAIG subject (a UUID). aud names one receiver, urn:craig:service:<name>.

    • act is the RFC 8693 chain of hops. Its outermost actor is client_id; its innermost is the session opener (craig-web, craig-portal or craig-cli). No actor repeats.

    • roles is a non-empty, sorted set drawn from REALM_ROLES or PORTAL_REALM_ROLES, never both, never service:*.

    • Lifetime: 1–300 s, never past the session’s end, and never past the subject token’s exp when delegated onward (D12). nbf = iat.

  • Service token.

    • Claims: iss sub aud exp iat nbf jti client_id scope, with sub = client_id.

    • One audience. scope is a subset of the compiled purpose for that pair (D4). Lifetime at most 600 s. It carries no user.

  • Session credential. 32 bytes from a CSPRNG, written as 43 characters of unpadded base64url and stored only as its SHA-256. Only the client that opened it can present it. It is never a JWT.

  • The machine actor (Canopy crates/canopy-auth/src/identity_receiver/principal.rs:19-103, crates/canopy-common/src/identity.rs:240-333). A receiver’s acting principal is Actor::Worker(Subject) or Actor::Service(ServiceName); a service never has a subject.

    • Claims::actor() returns it. Claims::worker_subject() returns the subject, or a 403 worker_required for a service, never a 500. ActingWorker::sub() is removed, so the compiler finds every raw use; a log line uses log_id().

    • Every persisted actor, intent digest and audit actor uses one encoding: the UUID for a worker, service:<name> for a service, which never parses as a UUID. A UUID column a service can write becomes a pair (the UUID column, a <column>_service TEXT column, and a CHECK that exactly one is set).

    • Today the service’s name already comes from service_id() (crates/craig-auth/src/claims.rs:317-323), and after the switch it comes from client_id. The contract lands before the switch (plan U3), so a service’s encoding, and with it every intent digest, is the same on both sides of the switch.

    • The stored digests. Digests stored before U3 hash a service’s IdP UUID. Intake answers a 409 by minting a fresh id and offering a new submission (services/craig-intake/static/js/report-form.js:800-807), so a mismatch could duplicate a report. So, from U3 until the switch, a duplicate whose stored digest does not match is also compared with the digest computed from the bearer’s UUID sub. This applies to the report, report-attachment and screening-stage digests (the screening-stage comparison retired with #2498, which keys the start to the relayed worker). The switch deletes the comparison, together with the IdP tokens that carry such a sub.

  • Not a claim: name and email. Federation writes them to worker_identities directly (D6), so the only identity field an internal token carries is the username.

  • Removed at the switch:

    • IdP bearers at receivers;

    • the service:* roles and multi-audience tokens;

    • X-Craig-Actor, X-Craig-Subject and the peer-JWKS map;

    • receiver introspection.

D4 — Policy is code

  • Compiled clients. A confidential client is every service that holds a peer URL setting, plus craig-web and craig-portal. craig-cli is the one native client.

  • The call graph. One compiled table of (caller, target, Worker | Service | Both). A test gates it against a census of every service’s *_URL / *_BASE_URL settings. The census fails on any URL setting it cannot classify as a peer or a non-peer (DATABASE_URL, RABBITMQ_URL, the identity and upstream URLs).

  • The purpose registry. Each (client, audience) pair maps to at most one scope set. partners.replay-check (craig-intake to craig-cases) moves here from the IdP.

D5 — One trust root per credential

Credential Verified against Binding

Internal token at a receiver

the issuer’s JWKS

typ: at+jwt; aud is the receiver; at most 8 KiB; the D9 lifetime and skew bounds; a service token’s client holds a Service or Both edge to the receiver (Canopy crates/canopy-auth/src/identity_token.rs:25-27)

Subject token for onward delegation

the issuer’s JWKS

a worker token with aud = the caller’s own URN; the call graph holds the edge; a service token never qualifies

Session credential

its hash

presented only by its opener’s client key; fresh and unrevoked (D6)

Client assertion (RFC 7523)

the client registry (D11)

aud is the issuer identifier alone; exp at most 60 s; jti single-use across replicas; at most 8 KiB

Upstream id_token

the upstream’s JWKS, through the profile’s algorithm list (#2687’s 2048-bit RSA floor holds)

at most 16 KiB; a header of exactly alg, kid and an optional typ (x5t members ignored); iss exact; aud exactly craig (a string, or an array whose every member is craig), or exactly craig plus the project for a profile that declares a project audience (ZITADEL), where azp is then required; azp, when present, is craig whatever the audience count; iat at most 300 s old and 60 s ahead; auth_time present and at most iat + 60 s; sub 1–255 ASCII characters without controls (Canopy crates/canopy-auth/src/upstream/id_token.rs:511-772). The BFF that started the login checks nonce

Native refresh credential

its hash

single-use; a reuse revokes the native session (D12)

CRAIG’s BFF requires azp today (crates/craig-auth/src/jwks.rs:786-795, configured at crates/craig-bff/src/boot.rs:196-198). The rule above accepts its absence only when aud is exactly craig, as OIDC Core 1.0 §3.1.3.7 allows, so a conforming IdP that omits it can sign in.

D6 — Federation (the login exchange), BFF sessions and logout

  1. The BFF runs the authorization-code flow: PKCE, a 32-byte state compared in constant time, a 32-byte nonce, and claims={"id_token":{"auth_time":{"essential":true}}}, because a conforming provider may omit auth_time unless asked (OIDC Core §2, §5.5; Canopy crates/canopy-auth/src/upstream/relying_party.rs:79-81). It validates the id_token (D5) and checks the nonce, then presents the id_token to the federation grant (D12), authenticated with its private_key_jwt key.

  2. The issuer validates the id_token again and projects roles through RolesClaimPath. It intersects them with the vocabulary, refusing service:* and an empty set.

  3. It enforces the opener’s population, which is ADR-076’s per-account rule: craig-web federates only accounts holding a worker role and no portal role, and craig-portal only the reverse.

  4. It links or mints the subject (D7), checks suspension (D13), and opens the session. For the worker population only (opener craig-web), open_session() upserts worker_identities (username, display name, email, last_seen_at) in the same transaction. A portal principal never enters the worker directory, as today’s middleware already ensures (services/craig-security/src/api/worker_identity_middleware.rs:99-109), because the directory’s search has no population filter (services/craig-security/src/store/worker_identities.rs:98-116).

The answer carries the session credential, sid, sub, roles, username, auth_time, session_ends_at and fresh_until, and the issuer stores the SHA-256 of the id_token’s nonce. A refusal adds a code from a closed set: no_role, dual_role, no_username, upstream_sub_invalid, auth_time_too_old, subject_suspended, grace_exhausted, session_ended, upstream_changed and soak_mint_refused. Unknown, ended and revoked sessions are deliberately indistinguishable.

  • Terms. A session ends at the upstream auth_time plus CRAIG_SECURITY__IDENTITY_SESSION_MAX_SECONDS (default 28800, bounded 1800–43200). An open whose end would come within 900 s is refused as auth_time_too_old (Canopy crates/canopy-auth/src/identity_session.rs:526-543). A session is fresh until its last upstream validation plus 900 s. Worker tokens are minted only from a fresh web session. A native session (D12) is never re-validated upstream, so it needs only to be unrevoked and before its end.

  • Stale upstream SSO (Canopy services/canopy-web/src/auth/routes.rs:362-366, :455-477). On auth_time_too_old, the BFF restarts the flow once with prompt=login, under a fresh state, nonce and verifier. The retried flow carries fresh_retry in its signed flow cookie, so a second stale answer becomes a refusal page, never a loop.

  • Renewal evidence (Canopy crates/canopy-auth/src/upstream/renewal.rs:173-181, :255-291; OIDC Core §12.2). The refreshed id_token passes D5. It must match the session’s iss, sub and auth_time. Its nonce must be absent or hash to the original’s; a nonce where the original carried none is refused. Its iat must be newer than the last one recorded; a token whose digest equals the last one is a replay, answered with the current state. A session bound to another upstream issuer or client is revoked as upstream_changed before any upstream call.

  • Grace (Canopy Amendment 2, adr-049:552-580). An upstream refresh that provably never reached the upstream (no connection, or 408 / 425 / 429) earns one audited grace: freshness extends to the last validation plus 900 s plus at most 1800 s. Every other failure ends the session. craig-portal never claims grace, which keeps today’s rule that it ends its session on any refresh failure (idp-integration.adoc:73).

  • BFF sessions (amending ADR-013; Canopy services/canopy-web/migrations/20270201000000_identity_web_session.sql:20-36).

    • Each BFF keeps its sessions in its own database: craig_web and craig_portal. Each has an owner and an app login (ADR-063). The app login holds SELECT, INSERT and UPDATE on the session tables and EXECUTE on the owner’s purge function, never DELETE or TRUNCATE, and a boot probe refuses more.

    • The cookie holds only a 256-bit handle, stored as its SHA-256. It is HttpOnly and SameSite=Strict, and Secure and __Host- where Secure is configured.

    • The row holds the issuer session credential, the upstream refresh token, the latest upstream id_token (the logout hint), the upstream binding, a version, and a claim (claim_id, claim_expires_at on the database clock).

    • Renewal never changes the cookie, so a late request carrying it simply re-reads the row. A sign-in or step-up replaces a session (superseded_by), and sign-out follows at most four such links.

    • The row’s credentials are not field-encrypted. Each needs a client key held outside the database: the issuer session credential needs the BFF’s assertion key (D5), and the upstream refresh token needs the craig client’s secret or key (D10). Canopy does the same; its field encryption is Canopy #2521.

  • One renewal leader per session (Canopy crates/canopy-auth/src/identity_web_session/engine/leader.rs:92-124, crates/canopy-auth/src/identity_web_session/decide.rs:109-136). Two BFF replicas must never both spend one rotating upstream refresh token (RFC 9700 §4.14.2).

    • What a request does, from the row it reads:

      • fresh and not due: serve;

      • fresh and due: serve, and maintain in a detached leader;

      • stale with a live claim: wait, at 20 ms doubling to 160 ms, jittered;

      • stale with no claim: lead;

      • a lapsed claim: end the session as refresh_lost, because its holder may have spent the token;

      • a row bound to another upstream: end it.

    • What the leader does. It claims at the version it read (compare-and-set), refreshes upstream, renews at the issuer, then commits: version + 1, claim cleared. A commit lands however late, because the token it presented is spent. If the upstream call never happened, the leader releases its claim instead.

    • Constants: lease 60 s, store operation 2 s, commit recovery 6 s, freshness lead 120 s, validation cadence 780 s (780 + 120 = the 900 s freshness), serve margin 15 s. Compile-time asserts tie them together (Canopy crates/canopy-auth/src/identity_web_session.rs:54-108).

  • Logout. The BFF revokes the session (RFC 7009), revokes the upstream refresh token, and uses RP-initiated logout where the upstream advertises it.

  • The portal. craig-portal opens sessions for portal principals. Their worker tokens (opener craig-portal) replace ADR-076’s X-Craig-Subject. The fleet guard keys on the opener and the portal paths.

D7 — Subjects and the identity mapping (#2685)

  • The link. A subject is linked to an exact upstream (iss, sub) pair, never to an email or a username. iss is stored as configured. The upstream sub must be 1–255 printable ASCII characters (OIDC Core §2); anything else is upstream_sub_invalid, which the BFF answers as 401.

  • Link or mint is one owner function, so concurrent first sign-ins yield one subject. For a new pair:

    • adopt the upstream sub as the subject when iss equals CRAIG_SECURITY__IDENTITY_ADOPT_UUID_SUBJECTS_FROM, the sub is a canonical lowercase hyphenated UUID, and no subject has that id;

    • otherwise mint a UUID v7, except during the soak (D15), when the pair is refused as soak_mint_refused.

  • Why adoption. Every persisted subject is an IdP UUID today. That includes worker_identities, every acting-worker column, placement’s portal bindings (caregiver_identities.subject_sub, services/craig-placement/src/store/caregivers.rs:367-384), and the devstack’s pinned subs (xtask/src/cmd/identity/model.rs:196-281). Adoption keeps them all, with no storage migration. Restricting it to one named issuer means a replacement IdP cannot claim a never-linked UUID; it mints, and a security administrator re-links.

  • The legacy issuer is recorded, not inferred. No table records an issuer today, and craig-security cannot see other services' bindings.

    • From plan U2, craig-security records its configured OIDC_ISSUER (the value every legacy iss matched) in INSERT-only identity_legacy_issuers at each boot, one row per distinct value.

    • The switch’s migration latches whether the deployment has history: audit_log or worker_identities has a row. Every service audits, the portal included, so portal-only history counts. The migration fails when there is history but no recorded issuer ("deploy a release at or after U2 first").

    • With history, the issuer refuses to boot when the adopt setting is unset, differs byte for byte from the one unretired recorded issuer, or more than one unretired issuer is recorded. An operator retires a recorded issuer that never validated a token with the owner-only identity_retire_legacy_issuer(), which writes an INSERT-only, logged retirement record.

    • Before the switch there is no latch row: the issuer boots, adoption follows the setting alone, and there is no soak. The switch’s migration also revokes the app login’s record_legacy_issuer(). The recording call treats a refusal as a WARN, never a boot failure, so a prior release redeployed during the soak still boots.

    • No table count, link count or population is consulted. So a wrong but non-empty setting, partial links and portal-only data each refuse rather than slip through.

  • Creating a subject. A security administrator can create a subject at a given UUID (nil refused; Canopy services/canopy-security/migrations/20261220000000_identity_admin_create_subject.sql), then re-link a pair to it. So a worker who never signed in during the soak keeps their history across a later IdP change.

  • Records. Subjects and links are INSERT-only. A re-link is an audited security-admin write (D13).

  • What services see. Only CRAIG subjects. The internal token parser requires a UUID sub in a worker token, so a non-UUID upstream sub works end to end and can never reach a subject parse.

D8 — Keys: generation, the registry and staged rotation

  • Generation. Each replica generates its keys in memory with craig_crypto::Es256SigningKey::generate() (aws-lc-rs, ADR-084 D1–D2; crates/craig-crypto/src/es256.rs:224). A key is never persisted or exported, and never sits in an env var, a file or sops. It is dropped, and AWS-LC frees it, when its window closes.

  • The registry.

    • identity_signing_keys holds kid, x, y, the replica id and the requested lifetime. It is owned by craig_security_owner; craig_security_issuer holds SELECT, and INSERT on those five columns only (D2’s matrix).

    • An owner-owned trigger stamps the times from clock_timestamp(). CHECKs repeat the arithmetic, so it holds even with triggers bypassed, and a CHECK pins kid to the thumbprint of (x, y).

    • The trigger refuses every UPDATE and DELETE.

    • At most 64 unrevoked rows may be published at once. An owner-held guard row serializes the count (Canopy Amendment 1, adr-049:500-549), and a revoked row frees its slot, so forged keys filling the cap cannot block the response.

    • Revocation is a separate INSERT-only table. The security-admin route writes it through identity_admin_revoke_key (D13); the owner alone holds identity_revoke_key, for recovery.

  • One key’s life (Keystone’s vocabulary on Canopy’s windows, adr-049:262-300):

    Stage Window (database clock) Meaning

    staged

    created_at to sign_from = created_at + 60 s

    published, not signing: every receiver can fetch it first

    primary

    sign_from to sign_until − 5 s

    the replica’s one signing key; deadlines are monotonic instants derived from the database clock, so a wall-clock step cannot move them

    retiring

    sign_until to publish_until = sign_until + 720 s

    verify-only: 600 s longest token + 60 s leeway + 60 s skew

  • Cadence.

    • A replica’s first key after boot signs for 600 s, so a crash loop leaves short rows. Every later key signs for 21600 s (6 h); the CHECK bounds requested_sign_seconds to 600–21600.

    • The next key is inserted 120 s before the current sign_until, so a replica never stops minting.

    • A failed insert retries with backoff from 1 s, doubling to 30 s. An insert whose outcome is unknown reads back its own kid before retrying.

    • If monotonic time stops tracking the database clock (a suspend, or a VM pause), the replica drops its keys and publishes a fresh one (Canopy services/canopy-security/src/identity/key_ring.rs:1-26).

  • Cap headroom (Canopy ADR-049 P10, adr-049:1475-1481).

    • The published keys come to about 2R, plus the restarts in the last 6 h 12 min that followed a replica’s first rotation, plus twice the restarts in the last 22 minutes.

    • At the ten-replica maximum (D17), a full rolling restart peaks at 50 of the 64. That leaves room, within 22 minutes, for four more restarts of replicas that have rotated (3 slots each), or seven of replicas that have not (2 each; a crash loop).

    • Past that, the cap refuses an insert: the replica holds readiness, WARNs and counts the refusal.

  • Compromise response (runbook; Canopy docs/modules/ROOT/pages/security-operations.adoc:324-361). No step uses the admin routes, because they depend on the issuer:

    • A replica. Its memory also holds the issuer’s DB password, so run the procedure below, revoking that replica’s keys as well.

    • The issuer DB credential. Containment runs as craig_security_owner, the migration identity, and needs no role administration:

      • REVOKE INSERT ON identity_signing_keys FROM craig_security_issuer, so no connection can publish a key from its next statement;

      • revoke, with identity_revoke_key, every key inserted since the compromise may have begun;

      • revoke, through the break-glass functions (D13), every session opened since then, and undo the administrative writes whose actor token’s kid is revoked (D13 records it).

    • Rotation runs as D2’s provisioning role:

      • ALTER ROLE craig_security_issuer NOLOGIN;

      • end its backends (pg_terminate_backend) until none remain;

      • set a new password and restore LOGIN.

           Then the owner restores the five-column INSERT grant, and every issuer replica restarts with the new secret.
        ** A revoked key stops verifying at a receiver on its next refresh: within 300 s plus the memo's 5 s, or 720 s during a
           JWKS outage (D9).

D9 — JWKS publication, caching, lifetimes and clock skew

  • Publication. GET /identity/jwks on the issuer is unauthenticated and documented in its OpenAPI document. It serves the published, unrevoked rows (created_at ≤ now < publish_until, by the database clock), newest first, at most 64, within 64 KiB, read from the registry and never from a replica’s copy.

    • Each replica memoizes the set for under 5 s, single-flight, and sends its age in Age (RFC 9111 §5.1).

    • A failed read answers 503; an older set is never served.

  • Receivers (Canopy crates/canopy-auth/src/key_cache.rs:65-83).

    • They refresh every 300 s, with a refresher task fetching every 240 s, and on an unknown kid at most once per 30 s. 5 s + 30 s is inside the 60 s staged lead.

    • They measure staleness from the request’s start minus Age. At 720 s stale they fail closed and verify nothing. Today’s 24 h bound (jwks.rs:46) stays only for the upstream’s keys.

    • Retention. A receiver keeps a fetched set until its next refresh. A key that leaves the published set (revoked, or past publish_until) therefore still verifies there for at most 300 s plus the memo’s 5 s, or 720 s during a JWKS outage. No per-key expiry is published or enforced locally; Canopy’s JWKS carries none either (services/canopy-security/src/identity/jwks.rs:271-281). The threat model counts this lag.

  • Maximum lifetimes. Worker token 300 s, service token 600 s, client assertion 60 s, device code 600 s. Sessions are not tokens: 8 h by default, 12 h at most.

  • Clock skew. Receivers accept iat ≤ now + 60 s and exp + 60 s > now, and refuse a lifetime over the layout’s maximum. They replace today’s 30 s (jwks.rs:200, actor_verifier.rs:60).

    • Token times read the wall clock (chrono::Utc::now()), never the business clock craig_common::clock.

    • Hosts run NTP; this is a deployment prerequisite.

D10 — Where private keys live

Key Lives Protection

Issuer signing keys

one issuer replica’s memory, 600 s–6 h plus its windows

never persisted; the registry holds public halves only; the process is non-dumpable (D2)

Client assertion keys (D11)

CRAIG_<SVC>__CLIENT_JWK_FILE (production); the devstack fixture env file

ADR-064: the devstack file is a deliberately public fixture (adr-064:27; security.adoc:51-53); production comes from the orchestrator’s secret store, never the repo (adr-064:50-52); held as craig_crypto::jwk::Es256PrivateJwk, which zeroizes d

The upstream client secret, when the IdP profile uses one

craig-web and craig-portal, as secrecy::SecretString

as the row above

`craig_security_issuer’s DB credential

the issuer process’s settings

as above; rotating it is the compromise response

Session credentials and upstream refresh tokens

each BFF’s session rows (D6)

useless without a client key held outside the database

A devstack value that is not a deliberately public fixture goes in the sops/age store secrets/dev.yaml (ADR-064; security.adoc:46-50), never in plaintext.

D11 — Client authentication is private_key_jwt

  • Every confidential client authenticates with RFC 7523 assertions. No secret is shared between a CRAIG client and the issuer.

  • Up to two public keys per client, for rotation, are registered in CRAIG_SECURITY__IDENTITY_CLIENT_KEYS_FILE. Their kid is the computed thumbprint, never a configured value.

  • The assertion’s protected header is exactly alg, kid, typ; typ is client-authentication+jwt or absent; iss = sub = the client id.

  • A client absent from the registry is refused at every mint. The registry is read at boot. A disabled client (D13) is refused within 5 s, before its jti is spent.

  • Today’s per-service ES256 keys and loaders (keypair_env.rs:164-179) become the client keys, and gen-actor-keys becomes gen-client-keys.

D12 — Grants

The endpoints live under /identity on the issuer process, outside /v1; their paths are constants in craig-auth.

  • POST /identity/token (a 64 KiB form cap):

    • Federation: RFC 8693, craig-web and craig-portal only. Open: subject_token is the id_token, of type urn:ietf:params:oauth:token-type:id_token. Renew: subject_token is the session credential, of type urn:craig:params:oauth:token-type:web-session, plus exactly one piece of evidence: upstream_id_token (the refreshed id_token, at most 16 KiB) or upstream_outcome=not_processed (the grace claim); none, both, or another outcome is invalid_request (Canopy services/canopy-security/src/identity/token_endpoint/request.rs:739-744).

    • Worker token (actor-token minting): RFC 8693 with an RFC 8707 resource. The subject token is either a session credential (the web-session type), presented by its opener, or a worker token addressed to the caller (type urn:ietf:params:oauth:token-type:access_token; onward delegation). The call graph must hold the edge. The caller is appended to act, at most MAX_ACT_DEPTH deep (computed from the graph); roles never widen; an onward token’s exp never passes its subject token’s, and a subject with under 5 s left is refused.

    • Service token: client_credentials with resource, through the purpose registry.

    • Native: urn:ietf:params:oauth:grant-type:device_code, then refresh_token with resource. craig-cli only.

  • POST /identity/device_authorization (RFC 8628) issues user codes of 8 characters from a 20-letter alphabet (§6.1). They live 600 s; polling is every 5 s with slow_down; device authorization is limited to 30 a minute, and code entry to a burst of 10 plus 1 a minute per upstream pair.

  • POST /identity/device/approve is called by craig-web for a worker whose session’s auth_time is at most 600 s old, and binds the approval to that web session (Canopy ADR-049 Z9). craig-web forces prompt=login, and the screen names the client and when the flow began. The step-up’s id_token carries a new auth_time, which renewal refuses, so it opens a new web session (Canopy adr-049:221). The approval opens a native session: a rotating refresh credential, single-use, whose reuse revokes the session (RFC 9700 §4.14.2). It ends 8 h after approval, 12 h at most (CRAIG_SECURITY__IDENTITY_NATIVE_SESSION_SECONDS, default 28800, bounded 1800–43200).

  • POST /identity/revoke (RFC 7009) revokes sessions and native credentials.

  • The native client’s store (Canopy crates/canopy-auth/src/identity_device_client/store.rs:34-176, crates/canopy-common/src/owner_only.rs:40-439).

    • The lock. One lock file is held with std::fs::File::try_lock across read → exchange → durable write. It is retried every 25 ms for at most 15 s, then answers Busy.

    • Cancellation. The work runs in a spawned task. A cancelled caller detaches it and never aborts it, so a successor credential is always stored.

    • The write. It goes to an O_EXCL 0600 sibling in a 0700 directory, then sync_all, then a rename, then an fsync of the directory.

    • Size. The store holds at most 16 KiB, in zeroizing buffers.

    • Without the lock, two CLI processes could spend one refresh credential, and the second presentation would revoke the session.

    • A process killed between the exchange and the rename loses the successor; its next presentation is a reuse that revokes the session, and the user signs in again.

  • Errors are RFC 6749 §5.2, plus 503 temporarily_unavailable, plus craig_refusal (D6).

D13 — Revocation, administration and issuance audit

  • craig-security owns four revocations, each INSERT-only with the latest record winning:

    • subject suspension;

    • session revocation;

    • client disablement, at runtime (Canopy services/canopy-security/src/identity/client_status.rs:44);

    • key revocation (D8).

  • Every mint checks suspension, the session and client status, the last through a memo of at most 5 s. An in-flight token therefore lives at most 300 s or 600 s, plus 60 s leeway and 60 s skew.

  • Administration (Canopy services/canopy-security/src/identity/admin/guard.rs:48-51, :114-282). The security-admin writes are re-link, subject creation (D7), suspend, lift, key revocation, client status and soak end (D15). They sit under /v1/security/identity on the ordinary process, are authorized through the ruleset engine (an identity_admin resource, admin only), and are limited to 60 a minute per IP.

    • Checks inside the write. Each write is one owner function that re-checks, inside its own transaction:

      • the actor’s session is live: not revoked or ended, opened by craig-web, the same sub, and fresh;

      • the actor’s subject is not suspended;

      • every client in the token’s act chain is enabled;

      • the session’s auth_time is at most 600 s old.

    • So a suspended administrator cannot lift their own suspension or re-link. A craig-cli actor is refused.

    • Refusals. A stale auth_time answers 401 with WWW-Authenticate: Bearer error="insufficient_user_authentication", max_age=600 (RFC 9470); craig-web answers it with a step-up sign-in at max_age=300, so 300 s + 60 s skew stays under 600. Every other failure answers 403.

    • Canopy checks before the write, in another transaction on another pool. CRAIG’s in-transaction check closes that window.

    • A re-link takes a per-pair lock and revokes the pair’s live sessions (Canopy services/canopy-security/migrations/20261217000000_identity_relinks.sql:15-46).

    • Break-glass. The owner alone holds the identity_breakglass_* functions. They lift a suspension, set a client’s status, undo a re-link, reopen the soak, and revoke the sessions opened since a given time. Each writes the same log row, naming an operator and a reason in place of an actor. Reopening the soak after a forged end leaves any subject minted meanwhile, so rollback then stays forward-fix only.

      • They exist because every administrative actor’s chain contains craig-web. A disabled craig-web, or forged writes suspending every administrator, would otherwise leave no way back.

      • Canopy runs the same steps as its migration identity.

  • The issuance log. Every mint and every refusal appends a row to the INSERT-only identity_issuance_log through a group-commit writer on its own connection. A credential is released only after its row commits; otherwise the answer is 503. Its time and row digest are stamped by the server. A worker token’s row names every hop.

  • State changes (link or mint, session open, renewal, grace and revocation, device approval and redemption, credential rotation, and every administrative write) commit their log row inside their owner function’s transaction instead. The change and its row commit or roll back together. An administrative row names the actor’s sub, sid, jti, kid and client chain. Refusals keep the writer (Canopy services/canopy-security/src/identity/issuance_log.rs:43-46).

  • Retention. The log joins ADR-058’s audit class (archive, then prune). Deletion goes only through an owner-owned SECURITY DEFINER prune, identity_prune_issuance_log, which the ADR-058 archive engine calls on craig_security_app (D2). Canopy never purges its log (its #1303 gate). The log is now partitioned by day and the prune is replaced by a count-checked partition drop: § Amendment — #3173.

D14 — What the issuer does not do

  • Not a general authorization server. No authorization endpoint or login UI, no consent, no dynamic client registration, no third-party clients, no userinfo, no introspection endpoint and no discovery document.

  • No refresh tokens for services. A service re-mints with one 60 s assertion and caches its token until 60 s before exp, so a refresh credential would only add a long-lived secret. The native session (D12) is the one refresh credential, and it serves a human.

  • Kept out: JWE, any algorithm other than ES256, multi-audience tokens, DPoP and mTLS binding, a second upstream, and claims from userinfo.

  • Introspection becomes optional. No IdP needs an introspection endpoint, and no receiver introspects. The switch deletes TOKEN_VALIDATION_MODE, the receiver IntrospectionClient path and its five settings (idp-integration.adoc:317-346).

D15 — Migration, cut-over, the soak, rollback and the production gate

  • Contracts first. Before the switch, on today’s path, U2 records the legacy issuer (D7), and U3 lands the machine actor (D3).

  • Additive next. Until the switch, units wire no receiver and no sender. The issuer runs and publishes, but no receiver trusts it and no sender asks it. The realm gains the craig client beside the 14.

  • The switch is one MR (Canopy K1, adr-049:1556).

    • It wires every receiver and sender, moves the BFFs to federation and server-side sessions, moves craig-cli and the operator tools to the device grant, and moves the harness and every password-grant tool to the token broker.

    • It deletes the IdP-issued path.

    • Its migration latches history and, with history, opens the soak (D7).

    • Main never holds a receiver trusting two issuers, or a sender holding two credentials. Dual trust would be a compatibility shim, and this pre-1.0 project carries none.

    • Cookie sessions end at the switch, so workers sign in again.

  • The identity-preserving soak. With history, the soak lasts until a security administrator ends it (D13). During the soak:

    • the issuer adopts and never mints; a pair that does not qualify for adoption is refused as soak_mint_refused. An unchanged IdP never sends one;

    • re-link is refused;

    • so every subject still equals its IdP sub.

        A redeploy of the prior release therefore reproduces every mapping during the soak. A fresh deployment has no soak.
      * *After the switch:* the realm collapses to `craig`, the conformance suites re-target, and the docs land.
      * *Rollback in the repository.* Revert in reverse merge order every MR merged since the switch that depends on it (at
        least the client collapse and the conformance tie-in), then the switch (`git revert -m 1`). The prior path, its realm
        included, returns intact. The revert keeps the switch's migration files: a deployment that applied them would
        otherwise read as Diverged (ADR-063) and refuse to serve.
      * *Rollback in a deployment.* During the soak, redeploy the prior release; workers sign in again.
      ** This works because the switch, and every migration merged during the soak, keep each service's
         `schema_compat_floor` at or below the prior release's (ADR-063, `crates/craig-db/src/schema_state.rs:7-11`). So the
         prior release boots on the post-switch schema, and a staging drill proves it before production (plan U21).
      ** Keep the retired IdP clients and their secrets registered until the soak ends.
      ** After the soak, rollback is forward-fix only, because minted subjects and re-links have no counterpart in the prior
         release.
      * *The production gate* (Canopy R24, `adr-049:3173`) is not a merge gate. No production deployment takes a release at or
        after the switch until all three hold; the switch writes them into `deployment-guide.adoc` § Deployment gates, open,
        as Canopy did (Canopy `deployment-guide.adoc:38-42`):
      ** an external security review of the issuer is complete and its findings are closed or accepted;
      ** D17's production run passes at the deployed replica count;
      ** the issuance log's retention runs.

D16 — State cleanup

  • The jti store. A row is kept until its assertion’s exp + 60 s. The verifier refuses exp ≤ now before it spends a jti, so a row that is due for purging can no longer be accepted (Canopy services/canopy-security/src/identity/client_auth.rs:65-67, :400-444). It is swept every 60 s, at most 1000 rows a call, within a 2 s run budget.

  • Sessions and devices. Sessions, with their validations, revocations and native credentials, and devices are purged 30 days after their end, revocation or expiry. Each call takes at most 100 rows, every 600 s (Canopy services/canopy-security/src/identity/sessions/sweeper.rs:33-51).

  • BFF sessions. Each BFF sweeps its ended sessions every 300 s, at most 500 a batch, and keeps the end log 30 days (Canopy services/canopy-web/src/web_session/sweep.rs:39-49).

  • How purges run. All purges are owner SECURITY DEFINER functions using FOR UPDATE SKIP LOCKED, so replicas never wait on each other. The issuer login holds EXECUTE only (D2). A call that overruns its budget detaches and drops its connection.

  • Not swept: the issuance log, which is archived and pruned (D13).

D17 — Capacity and the replica count

The workload, gates and replica rule port Canopy ADR-049 P1, G1–G7 and Amendment 13 T1 (adr-049:1387-1474, :1819-1824).

  • Workload W1. This is an assumption until a state supplies its own figures, in the shape of Canopy’s P1:

    • 3000 concurrent workers, each making 3 requests a minute;

    • each request reaches 3 receivers, and each token makes 0.3 onward hops;

    • that is about 600 issuer requests a second at design load, 585 of them worker-token mints and the rest renewals, opens, revocations and service tokens, and 1200 at peak.

  • Gates, at design and at peak:

    • G1: p99 ≤ 50 ms for the worker-token and client-credentials grants and for revocation, and ≤ 100 ms for federation.

    • G2: at design load, no 429 or 5xx, and ≥ 99.5 % answered.

    • G3: at peak, p99 ≤ 2 × G1, and 5xx ≤ 0.01 %.

    • G4: issuance-log append p99 ≤ max(1.2 × idle, idle + 2 ms).

    • G5: RSS ≤ 192 MiB per replica.

    • G6: the issuer pool stays below its ceiling, and the jti sweeper keeps up.

    • G7: the run is valid; neither the harness nor the host is the bottleneck (testing-reference.adoc § host pressure).

    • G8: the ADR-058 archive engine sustains the issuance log’s design append rate, and the deployment guide states the hot window’s storage (about 52 million rows a day at design load).

  • Replicas. R = max(3, ⌈peak ÷ C⌉ + 1), where C is one replica’s measured G3 capacity, so R − 1 replicas carry the peak. R is at most 10, D8’s cap headroom; a workload needing more sends this ADR back.

  • Limits and the pool (Canopy P2–P4, adr-049:1412-1434). All limits are per replica and process-local.

    • Per-client budgets: rate_limit_rpm in the client-keys file. The default is 6000 a minute. A BFF’s entry is at least 60 × its peak mint rate ÷ max(R − 1, 1), and the busiest onward caller’s at least 60 × its onward rate ÷ max(R − 1, 1).

    • The per-IP limit on the token and revocation routes (IDENTITY_TOKEN_RATE_LIMIT_RPM, default 30 000) is at least 60 × the BFFs' peak ÷ (pods × max(R − 1, 1)).

    • The issuer pool is IDENTITY_DB_MAX_CONNECTIONS (12–64, default 22): six background connections and the rest for requests.

  • Three runs, each of which may send this ADR back:

    • U7 on the issuer core: client credentials, JWKS fan-in, the log and key rotation;

    • U12 adding the worker-token mix, before the device grant and everything after it;

    • U21, the production run on the whole system at R, with federation, revocation, a rolling restart and a killed replica.

Threat model

The source, the CI configuration and this design are public. Security rests on keys.

Threat Bound

A stolen worker token

one audience, at most 300 s, never past its session, no wider than its subject

A stolen service token

one audience, one purpose’s scopes, at most 600 s

A stolen session credential

useless without the opener’s client key; revocable at once

A stolen client key

mints only that client’s purposes and edges, each logged; a BFF key still needs an upstream id_token at most 300 s old to federate

A compromised service (ADR-028’s accepted threat)

delegates only along its own edges, from tokens addressed to it, never widening; there is no separate actor JWT to pair, and the issuance log names every hop

A compromised BFF

acts as any worker whose session or id_token it holds, until its client is disabled (≤ 5 s)

A compromised upstream IdP

signs in any linked worker with roles the projection admits; it cannot mint service identity or bypass the issuance log

A stolen issuer DB credential

publishes forging keys that verify from a receiver’s next fetch (≤ 35 s for an unknown kid: the 30 s debounce plus the memo’s 5 s). They verify until publish_until plus a receiver’s retention: at most 22 685 s (6 h 18 min 5 s) after insertion, or 23 100 s (6 h 25 min) during a JWKS outage. D8’s owner procedure revokes them without the issuer, and a revoked one also verifies for at most a receiver’s retention

A memory read of a replica

exposes that replica’s live key for its 60 s lead, its sign window (≤ 6 h) and 720 s, plus a receiver’s retention (≤ 305 s, or 720 s during a JWKS outage), and the issuer’s DB password, so D8 rotates both; there is no persisted key to steal, and the process is non-dumpable

A JWKS outage used to prolong a revoked key

the key verifies until a receiver is 720 s stale; then receivers fail closed

A suspended administrator’s live token

every administrative write re-checks suspension, session, chain clients and a 600 s auth_time inside its transaction (D13)

Two BFF replicas spending one refresh token

one leader per session; a lapsed claim ends the session rather than guess (D6)

Device-code phishing

a native session of 8 h by default and 12 h at most, revocable, with codes that live 600 s and are rate-limited

A stolen native refresh credential

the thief’s first presentation of an unspent credential succeeds and rotates it; only a later presentation of the spent one, by either party, is a reuse that revokes the session. Until the legitimate client presents again, the thief holds the session, at most to its end (8 h by default)

Outstanding, not claimed

  • FIPS 140 and HSM custody. Not claimed (ADR-084 :75). Revisit trigger 2.

  • Native deprovisioning. An upstream deprovisioning ends web issuance within 900 s plus any grace. A native session lasts until its end, unless the CRAIG subject is suspended; Canopy re-federates native sessions (D7, adr-049:228-249). CRAIG does not. Revisit trigger 5.

  • Process hardening beyond D2. Core dumps off, a read-only root filesystem and no exec are deployment configuration, recorded in the runbook.

  • Workload. W1 is an assumption (D17). A state’s own figures replace it at the production gate.

Consequences

  • CRAIG owns an authorization server. That brings this threat model, proptests and an evil-input corpus for every new parser, and the external review before production.

  • The issuer is a boot dependency of every service and of sign-in. It runs as its own deployment of at least three replicas and depends only on its database. An issuer outage fails new worker calls at once, and stops background calls once cached service tokens expire (at most 600 s).

  • Each BFF gains a database. With sessions server-side, craig-web can scale beyond the one replica it runs today (docker-compose.scale.yml:13-14).

  • A state registers one IdP client and states its issuer, client id and roles path. It needs no service roles, service accounts, audience mappers or scopes.

  • The ADR-028 pair threat and #1481 close. The audit’s actor_service keeps its first-hop meaning (ADR-028 #1329), and the issuance log adds the hops.

  • A machine actor is never a subject. Services that persist an actor store D3’s encoding.

  • Services no longer hold a client secret. Actor keys become client keys.

  • Deprovisioning is bounded at 900 s plus at most 1800 s of grace for web sessions, and at the native session’s end (8 h by default, 12 h at most) for native sessions.

  • Rulesets keep reading claims.channel, claims.service_id and the acting worker, which the receiver projection preserves.

Alternatives

  • S0 fixes only (today’s path). This keeps 14 clients, the actor-pair threat and IdP-specific service identity. A Kanidm-class IdP stays impossible.

  • Share canopy-identity as a crate. Ruled out, 2026-10-24: both projects are too immature.

  • Keep an IdP as the internal issuer and broker the real IdP into it. A JVM stays on every write, and the pair threat and the vendor coupling remain (Canopy Alternative 2, adr-049:412-415).

  • Bind the actor iss to the bearer only (#1481). This closes the pairing, but keeps IdP-dependent service identity and a sender-side audit.

  • The issuer as an in-process module (Canopy D2), behind a gated router. It would share craig-security’s crash fate and its single readiness probe. A load balancer could not route /identity traffic while /v1 was unready.

  • Cookie-only BFF sessions with per-request refresh. Two replicas spending one rotating refresh token end a valid session. Only a shared store gives one leader per session.

  • The issuer refreshing upstream for the BFFs. The issuer would hold the upstream client credential and become a relying party. Canopy keeps that split.

  • Key custody.

    • A sops/age-provisioned signing key: humans and CI would hold a fleet-wide minting key, and rotation would be manual (adr-049:420).

    • A KMS or HSM: built only on a mandate (trigger 2).

    • Two-tier keys: the fallback if an HSM cannot meet latency.

Revisit triggers

  1. A separation-of-duties or ATO rule requires the issuer in its own crate and database, or issuance load needs its own database. The issuer then becomes its own service.

  2. A mandated HSM or FIPS 140 module for token signing. This adds a signer backend under an ADR-scoped exception.

  3. A source no single upstream can broker. This needs a second upstream at the edge.

  4. A supported IdP that cannot put auth_time and the roles claim in the id_token, or does not re-issue the id_token on refresh. This adds a userinfo claim source, as Canopy’s profiles allow (adr-049:195-198).

  5. A state, or the external review, requires sender-constrained tokens, native re-federation, or field encryption of BFF session rows.

  6. Canopy changes the design ported here materially. The port is re-diffed, never shared.

Amendment — #3173 the issuance log is partitioned by day (2026-11-28)

Ruling (the maintainer, 2026-11-27, plan audit-day-partitions). The unit of the log’s retention is a whole closed day: once a day’s partition is past the hot window it is archived, its row count is checked, and it is dropped in one transaction; no row is deleted.

  • Why. At the design load the log grows by about 52 million rows a day (deployment-guide.adoc § Identity capacity, G8). Deleting archived rows at that rate leaves constant dead tuples, vacuum work and WAL; dropping a partition costs almost nothing.

  • The shape. identity_issuance_log is range-partitioned by UTC day on recorded_at, one identity_issuance_log_pYYYYMMDD partition a day and no default partition, with PRIMARY KEY (recorded_at, id). craig-security’s partition-maintenance worker, in the ordinary process, keeps yesterday through 30 days ahead; the identity_issuance_log_partition_horizon invariant fires when the instant 7 days ahead has no partition.

  • recorded_at comes from a column default. It is DEFAULT clock_timestamp(), and the stamp trigger no longer assigns it, because a BEFORE INSERT row trigger may not move a row to another partition. The trigger still computes row_digest, over the stored time. D13’s "time stamped by the server" holds for every issuer row: the issuer cannot name the column.

  • The prune is replaced. identity_prune_issuance_log is dropped. The ADR-058 engine, on craig_security_app, reads a closed day through the parent and drops it through the owner’s identity_issuance_log_drop_partition(day, expected), which refuses the current UTC day, counts the partition under a lock that stops writers, and drops it only on an equal count. The app login also executes identity_issuance_log_ensure_partitions and identity_issuance_log_partition_days; it holds no privilege on a partition and no DDL of its own.

  • The issuer’s privileges are unchanged. It holds INSERT on the same columns of the parent, none on recorded_at or row_digest, no read, and EXECUTE on none of the new functions, so its login stays insert-only (D2). Every partition is created with every privilege revoked from every grantee but the owner, read from its ACL as § Amendment — #2739’s name-free sweep reads it, and from PUBLIC, craig_security_app and craig_security_issuer by name; it refuses UPDATE and TRUNCATE like the parent. identity_execute_matrix and the issuer probe hold the matrix.

  • A cost accepted. With no partition for the current day, a mint answers 503 (fail-closed), which the 30-day horizon and its invariant guard against. The partition drop takes the parent’s lock for at most 2 s, during which the issuer’s log inserts queue.

Schema and functions: the craig-security data model.

Amendment — #3152 the issuer listens once its first key can sign (2026-11-27)

Ruling (the maintainer, 2026-11-27). D2’s startup order, "then the first key; then it serves", means a key that signs, not one that was only published.

  • Before. The process bound its listener as soon as the first key was published. For the key’s 60 s staged lead it answered every token request 503 no_signing_key, and /readyz read not ready. A load balancer reads readiness on an interval, so after a restart it still routed to the replica until its next read.

  • The measurement. On the 2026-11-27 issuer-capacity run (!2604), that window failed 109 of 110 requests at a killed replica and 174 of 175 through a rolling restart, against G3’s 0.01 %. Each failure fell in the 5 s after a replica’s restart, on that replica.

  • Now. serve waits until the ring’s first key can sign (KeyRing::signable_at), then binds. A booting replica refuses connections, which an ingress retries on another replica, and its probes are refused too. A deployment therefore gives the issuer a startup probe (deployment-guide.adoc § Health Checks); compose’s 90 s start_period already allows for it.

  • A refused first publication. A replica whose first key the registry refused (D8’s 64-key cap) binds at once and serves unready while the driver retries, as before.

Amendment — #3151 the jti is spent in the log writer’s transaction (2026-11-27)

Ruling (the maintainer, 2026-11-27, plan one-commit-mint). D13’s group-commit writer spends each mint’s assertion jti in the transaction that commits the mint’s row.

  • Before. A mint did two commits in series: the request inserted its jti on the issuer pool, then waited for its row in the writer’s batch. Every request held an issuer-pool connection for its own jti commit, so a short write stall at 600 requests a second per replica filled the pool. On the 2026-11-27 issuer-capacity run, two replicas at the peak reached the ceiling of 22 (D17’s G6).

  • Now.

    • The writer drains its queue as before. It commits each batch in one transaction: its jtis in (client_id, jti) order, then every row to append and the minted row of every fresh jti.

    • One statement spends the batch’s jtis with a bare ON CONFLICT DO NOTHING. If fewer rows are affected than spends, the writer rolls back and spends each on its own, then writes the rows.

    • A request takes an issuer-pool connection only for the 5 s client-status read.

  • What holds.

    • D11’s order holds: a disabled client is refused before its jti is spent.

    • A replay still loses on the primary key across every replica, and outranks every other refusal.

    • A credential is still released only after the commit (D13).

    • D2’s privileges are unchanged: the issuer inserts client_id, jti and expires_at and reads nothing. The bare clause names no column, so it needs no SELECT.

    • The key order means no two replicas' batches wait on each other in a cycle.

Amendment — #2739 craig-security’s required role names (2026-10-26)

Ruling (the maintainer, 2026-10-26): craig-security’s identity-relevant roles have required canonical names. This is an explicit, documented exception to #2337’s name-free provisioning, for craig-security only (deployment guide § Per-service DB roles).

  • The names, staged per unit. Each role is required from the unit that introduces it. U2 requires craig_security_owner (the migrate gate’s login, owner of every identity_ object) and craig_security_app (the serving login). U4 requires craig_security_issuer and craig_security_provisioner, and its issuer probe requires the issuer login positively, not only refusing the app role.

  • Why. D2’s matrix grants distinct, partly column-level privileges and function EXECUTE to distinct principals. Default privileges cannot express that, and neither can the gate’s name-free hardening (#1550, #2337): it reads the ACLs and revokes writes from every grantee but the owner, which suits uniform read-only tables, not a matrix that grants one principal more than another.

  • Enforcement. The grants are unconditional statements in versioned migrations, so a migration fails when a role it names is absent; there is no DO $$ … IF EXISTS guard. Before its grants, each identity_ migration revokes everything on its objects from every grantee but the owner, PUBLIC included, read from the ACLs (a name-free sweep), so a role holding the owner’s default privileges under any name keeps nothing. The names supplement effective-privilege checks, never replace them. From U2, craig-security’s boot check (services/craig-security/src/identity/app_probe.rs) refuses to serve unless its login is craig_security_app and holds no privilege on an identity_ table, no EXECUTE on identity_retire_legacy_issuer and no grant option on an identity_ object, held directly, through PUBLIC or through a role membership, and owns, directly or through a membership (pg_database_owner included), neither the database, the public schema nor an identity_ object. An identity_ object it names that is missing is a refusal, never "no privilege"; it names them with schema-qualified names and argument types, so a shadowing type cannot hide one. EXECUTE on identity_record_legacy_issuer is required while present but removable: the switch revokes it, so its absence is a WARN, never a refusal (D7). The blocking invariant identity_execute_matrix compares every grantee’s rights on every identity_ object (from the ACLs), and PUBLIC’s and the app login’s effective rights, with the matrix, and flags any grant option a grantee but the owner holds (the matrix grants none). Later units extend the check and the invariant.

  • Tradeoff. Roles are cluster-wide, so two independently credentialed CRAIG installations cannot share one PostgreSQL cluster under these names. A configurable-principal design, each name a setting the migrations and probes read, was considered and declined for now.

References

  • Canopy (gitlab.com/gadhs/application/eligibility/canopy at 504b21b2d):

    • docs/modules/ROOT/pages/adrs/adr-049-identity-plane-split.adoc (D1–D14, the threat model, P1, P10, G1–G7, Amendments 1, 2, 3, 6, 11, 13 and 25) and adr-050-kanidm-default-upstream.adoc (§2, profiles and the conformance rule, :48);

    • under services/canopy-security/src/identity/: key_ring.rs, key_ring/schedule.rs, jwks.rs, key_source.rs, client_auth.rs, client_status.rs, issuance_log.rs, issuance_log/sweeper.rs, probe.rs, sessions.rs, sessions/sweeper.rs, admin/guard.rs, admin/writes.rs, and token_endpoint/ (federation.rs, federation/renewal.rs, request.rs, delegation.rs, device.rs);

    • its migrations 20261209000000_identity_signing_keys.sql, 20261210000000_identity_issuance_stores.sql, 20261211000000_identity_issuer_no_temporary.sql, 20261216000000_identity_admin.sql, 20261217000000_identity_relinks.sql and 20261220000000_identity_admin_create_subject.sql, and src/identity/admin_probe.rs;

    • under crates/canopy-auth/src/: key_cache.rs, identity_receiver/principal.rs, upstream/id_token.rs, upstream/renewal.rs, upstream/relying_party.rs, identity_web_session.rs and its engine, identity_device_client/store.rs; and crates/canopy-common/src/owner_only.rs;

    • canopy-web: services/canopy-web/src/web_session/ and src/auth/routes.rs, and its migration 20270201000000_identity_web_session.sql;

    • the privilege matrix and compromise runbook: docs/modules/ROOT/pages/security-operations.adoc:139-148, :324-361;

    • the external review gate: docs/modules/ROOT/pages/deployment-guide.adoc:38-42 (#2884).

  • Keystone: the Fernet FAQ and JWS key rotation pages linked in Context.

  • RFC 6749, 7009, 7523, 7638, 8628, 8693, 8707, 9068, 9111, 9470, 9700; OIDC Core 1.0.

Annex: Canopy’s identity controls, retained, changed or omitted

The table below covers the identity controls canopy-identity implements at 504b21b2d, grouped by area. The paths are Canopy’s. Retained means CRAIG builds the same control in the decision or plan unit named.

Canopy control CRAIG

Token format: ES256-only compact JWS with an exact header (crates/canopy-auth/src/identity_jws.rs:8-20); typ at+jwt (identity_policy.rs:71); system (600 s) and delegation (1–300 s) layouts refusing unknown claims (identity_policy.rs:74, identity_policy/delegation.rs:42); the audience URN (identity_policy.rs:52)

Retained (D3). The programs claim is omitted: CRAIG has no programs.

Policy: the compiled call graph and purposes (identity_policy.rs:123, identity_policy/call_graph.rs); an act depth of 8 with no repeat (call_graph.rs:129); the settings census (xtask/src/cmd/call_graph.rs)

Retained (D4, U6); CRAIG computes MAX_ACT_DEPTH from its graph.

Delegated-routes table: 119 compiled route admissions, census-gated (identity_receiver/delegated_routes.rs:44)

Omitted: every CRAIG handler authorizes through the ruleset engine, which already separates service and worker callers.

Receivers: the validator, an 8 KiB token cap and the system-edge check (identity_token.rs:8-49, :82, :25-27); the key cache, 300 s / 30 s / 720 s with a 240 s refresher (key_cache.rs:65-83); a 64 KiB JWKS cap (identity_token/jwks_source.rs:59); one Bearer, an actor header refused, a 2 s key budget (identity_receiver/layer.rs:11-12, :48); the admission arms (identity_receiver/admission.rs)

Retained (D5, D9, U14); the admission arms become the plan’s §C projection and the portal guard.

Principal: Principal and Actor (identity_receiver/principal.rs:21-103, crates/canopy-common/src/identity.rs:240-333); idempotency keyed by principal (crates/canopy-api/src/idempotency.rs:607-674)

Retained (D3, U3).

Client authentication: the assertion checks and an 8 KiB cap (identity/client_auth.rs:1-60); the INSERT-only jti store (:231-232); at most two keys with thumbprint kids (identity/clients.rs:46); runtime disablement through a 5 s memo (identity/client_status.rs:44)

Retained (D11, D13, U6). Changed: runtime disablement replaces revision 1’s restart-only rule.

Limits: per client 6000 a minute (identity/clients.rs:19); per IP 30 000 a minute (identity/token_endpoint.rs:230); device authorization 30 a minute (:239); code entry 10 + 1 a minute per upstream pair (token_endpoint/attempts.rs:34-37); 5 s polls over 4096 devices (token_endpoint/polls.rs:33-38); admin 60 a minute with 5 s and 2 s budgets (identity/admin.rs:51-57); a 64 KiB form (identity_url.rs:39); grant deadlines (token_endpoint.rs:273-325); delegation refused under 5 s left (identity_delegation.rs:50-63); trusted proxies (crates/canopy-common/src/http/client_ip.rs:35, :79)

Retained (U6, U10, U12, U13) with D17’s sizing, through craig-api’s rate limiter and craig-common’s client_ip.

Issuance log: release after commit, group commit on its own connection (identity/issuance_log.rs:3-27, :75-135); INSERT-only, a server-stamped time and row digest (20261210000000_identity_issuance_stores.sql:57-125)

Retained (D13, U6). Changed: CRAIG archives and prunes it (ADR-058); Canopy never purges it.

Keys: the registry trigger, the 64-cap guard row, INSERT-only revocations (20261209000000_identity_signing_keys.sql:125-265); per-replica in-memory keys and their schedule (identity/key_ring.rs:84-98, key_ring/schedule.rs:25-57); readiness (crates/canopy-api/src/lib.rs:1155-1171); the role split and boot probes (identity/registry.rs:40-48, identity/probe.rs); PR_SET_DUMPABLE (services/canopy-security/src/main.rs:41-46)

Retained (D2, D8, U4). Changed: CRAIG’s runtime logins are the issuer and the existing app login, in separate processes; the non-dumpable process, omitted in revision 1, is retained.

Bootstrap: the issuer inside canopy-security’s shared bootstrap (services/canopy-security/src/main.rs:59-65)

Changed: CRAIG runs the issuer as its own process (D2).

Issuer without TEMPORARY (20261211000000_identity_issuer_no_temporary.sql)

Retained (D2, U4): TEMPORARY revoked on craig-security’s database from PUBLIC (no craig-security code uses temporary tables), and TEMPORARY and CREATE from the issuer login.

The admin login and its probe (Amendment 8 H3, identity/admin_probe.rs)

Changed: CRAIG’s admin functions run on its existing app login, in its own process; an app probe ported from admin_probe.rs refuses that login holding more than D2’s matrix (D2, U10).

Main-pool least privilege (20270124000000_main_pool_least_privilege.sql)

Omitted: narrowing the app login’s grants on craig-security’s other tables is outside this ADR; D2 covers the identity tables.

Compromise response (docs/modules/ROOT/pages/security-operations.adoc:324-361)

Changed (D8): containment revokes the issuer’s INSERT grant as the owner, and role administration runs as the provisioning role. Owner-only break-glass functions (D13) replace Canopy’s migration-identity SQL for suspensions and clients.

Sessions: the credential (identity_session.rs:84-87); terms, web 12 h (≤ 24 h), grace 30 min, native 8 h (≤ 24 h) (:94-136); the mint-time judge (identity/sessions.rs:745-764); re-link locking that revokes the pair’s sessions (20261217000000_identity_relinks.sql:15-46)

Retained (D3, D6, D13, U9, U10). Changed: CRAIG’s bounds are tighter, web 8 h (≤ 12 h) and native 8 h (≤ 12 h).

Administration: the guard, with a live session, enabled chain clients, no native actor, the role and a 600 s auth_time, and its challenge (identity/admin/guard.rs:48-51, :114-282); writes with an INSERT-only action row (identity/admin/writes.rs:345-384, 20261216000000_identity_admin.sql); subject creation (20261220000000_identity_admin_create_subject.sql)

Retained (D7, D13, U10). Changed: CRAIG re-checks inside the write’s transaction.

Upstream: the profile and its algorithm list with RSA ≥ 2048 (upstream/profile.rs:94-98); configured CA anchors (upstream/tls.rs); 2 s connect and 2.5 s request bounds, no redirects (upstream/client.rs:42-48); the id_token validator, including ZITADEL’s project pair (upstream/id_token.rs:85-92, :511-772); the renewal check and binding (upstream/renewal.rs:173-181, :255-291); discovery equality (upstream/keys.rs:340-342); the projection (upstream/projection.rs:72)

Retained (D5, D6, U8).

Relying party and web sessions: PKCE, 256-bit state and nonce, essential auth_time, a constant-time compare (upstream/relying_party.rs:79-81, :229-338); the stale-SSO retry (services/canopy-web/src/auth/routes.rs:362-366, :455-477); the session store, single-flight and constants (services/canopy-web/src/web_session/sql.rs:131-181, identity_web_session.rs:54-108); grace (Amendment 2); cookies (web_session/cookie.rs:7-37); sign-out CSRF (services/canopy-web/src/csrf.rs:151-175); a 2048-byte local return path (auth/return_path.rs:27); the sweep (web_session/sweep.rs:39-49)

Retained (D6, D16, U11). Changed: the login flow stays in CRAIG’s signed 300 s cookie (crates/craig-bff/src/oidc.rs:71-84), not a database row; the upstream code is single-use, so a replayed callback fails at the upstream.

Native: device codes (identity_native.rs:70-87); approver binding (Z9); rotation whose superseded version revokes the session (N6); the device store and owner-only writer (identity_device_client/store.rs:34-48, crates/canopy-common/src/owner_only.rs:40-439)

Retained (D12, U13), with a two-process test that Canopy lacks.

Native re-federation (identity_native_session.rs:39-45)

Omitted: a recorded gap (Outstanding; trigger 5).

DPoP (identity_dpop.rs:49-67, identity/dpop_jti.rs:35-36)

Omitted (D14; trigger 5).

Senders: a 6.5 s budget, a zeroizing bearer, one retry after a 401 (identity_sender.rs:52, :146, :408); the per-request delegation cache (identity_client/delegation.rs:95); the system-token cache (identity_client.rs:51-54); the web and portal senders (identity_web_sender.rs:100, identity_portal_sender.rs:40)

Retained (U15).

Applicant carve-out and edge forwarder (applicant_verifier.rs, identity_edge.rs:64-68, :227)

Omitted: CRAIG has no applicant population and no edge-forwarded public routes.

Sweepers: jti (identity/issuance_log/sweeper.rs); sessions and devices (identity/sessions/sweeper.rs)

Retained (D16).

Deploy check (xtask/src/cmd/identity/check.rs:3-19)

Retained as an extension of cargo xtask identity verify (U6).

Edit this page · latest