Identity plane split, plan I2c: subjects and web sessions (epic &132)

Status: Done (2026-10-05) — !1571
Epic: &132 (stage I2 of &130)
Issues: #2712 (w3), #2713 (w5), #2714 (w3), #2715 (w5), #2716 (w5), #2717 (w5), #2718 (w2), #2719 (w3)
MR: feat/identity-federation-sessions: U1–U8 in order, titled "canopy-identity federation grant, subjects and web sessions (#2712 … #2719)".

The eight issues are one deliverable, the federation half of the user plane that I2d’s delegation mint reads, 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 (Status In progress) and its nav entry: a new group, Identity Plane Split (epic &130), holding * Identity plane split, plan I2c — subjects and web sessions (epic &132), placed just above ** Completed Plans Archive in docs/modules/ROOT/nav.adoc, as plans I2a and I2b 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 D6 has canopy-web present a verified upstream id_token to canopy-identity’s RFC 8693 federation grant, authenticated with private_key_jwt; canopy-identity validates it again, calls userinfo bound to its sub where the profile says, projects, links or mints the subject (D8), checks suspension (D12) and opens a session. D3 makes a session opaque, client-bound, stored hashed and never a JWT; D5 checks it by hash, only from its opener, unrevoked and fresh. D6 has canopy-web re-federate after each upstream refresh and at least every 900 s, refuses minting from a session last validated upstream more than 900 s plus a grace ago, caps grace at 30 min (60 min in code) and audits it. Amendment 2 narrows grace on the refresh path; Amendment 5 (C7–C9) narrows the id_token rules and gives an unavailable userinfo D6’s original grace.

In the tree today:

  • services/canopy-security/src/identity/token_endpoint.rs serves only client_credentials; issue fixes one deadline before the form is parsed and audit_deadline clips the audit to request start + REQUEST_BUDGET (5 s); the form cap (token_endpoint/request.rs, MAX_FORM_BYTES, 16 KiB) is smaller than an upstream id_token plus an assertion; the 2 s PROCESSING_BUDGET is shorter than a cold discovery, JWKS and userinfo path (2.5 s each, crates/canopy-auth/src/upstream/client.rs).

  • services/canopy-security/src/main.rs loads the upstream profile and builds _identity_upstream_client, unused: "plan I2c’s federation grant is their first reader". No key source, validator or userinfo client is built.

  • crates/canopy-auth/src/upstream/ (I2b) verifies an id_token (UpstreamIdTokenValidator), calls userinfo (UpstreamUserinfo: Unavailable, Refused, Invalid) and projects (project → FederatedIdentity). VerifiedUpstreamIdToken exposes no iat; NumericDate has no public constructor; project takes only a validator-built UpstreamAnchor, so a userinfo renewal cannot project; the profile parses every claims_from × refresh pairing. crates/canopy-auth/src/key_cache.rs stamps a fetch attempt before awaiting it, so a cancelled fetch debounces lookups for 30 s, and both the validator’s key lookup and userinfo’s endpoint lookup can start one.

  • crates/canopy-auth/src/identity_policy/delegation.rs defines SubjectId and SessionId (any UUID version) without a mint, Display or FromStr.

  • The issuer login (identity/registry.rs, identity/probe.rs) holds INSERT and SELECT, plus EXECUTE on its jti purge; the probe refuses any UPDATE, DELETE or TRUNCATE grant. identity_issuance_log (migration 20261210000000) requires a kid and token_jti on every issued row, has no subject or session column, and digests to_jsonb(NEW).

  • No subject, link, session or suspension table exists. worker_directory is keyed on the upstream (issuer, subject); ADR-046’s banner moves it to the canopy subject at I3.

Scope

In scope: U1–U8 below: the session and subject primitives, the upstream changes renewal needs, the issuance log’s session rows, the subject and session stores, the federation grant, renewal with grace, revocation by the opener, and the Kanidm lane’s proof.

Out of scope:

  • canopy-web calling the grant, its nonce and max_age, its client key, the directory re-key, seed links and the worker_directory routes (I3);

  • the delegation mint and its freshness check, and rate limits keyed by client (I2d; capacity is I2g’s);

  • security-admin routes: suspending and lifting a subject, revoking any session, re-linking a subject, runtime client disablement, and step-up enforcement (I2e);

  • native sessions, the device grant and DPoP (I2f).

Design

Decisions (recorded in ADR-049 Amendment 6, which lands with U1; F4 fixes the web session’s end, which D3 needs and only D7’s native sessions have; F5 narrows C9’s Invalid class; F6 specifies how D6’s grace is recorded and extends C9’s grace to an unavailable key fetch)

# Decision

F1

The grant’s wire shape. grant_type urn:ietf:params:oauth:grant-type:token-exchange on POST /identity/token, only from ConfidentialClient::Web; any other authenticated client is unauthorized_client before any lookup. Both forms carry requested_token_type urn:canopy:params:oauth:token-type:web-session:

  • open: subject_token = the upstream id_token, subject_token_type urn:ietf:params:oauth:token-type:id_token, plus upstream_access_token exactly when the profile’s claims come from userinfo;

  • renew: subject_token = the session credential, subject_token_type = the web-session URN, plus exactly one of: the refresh evidence the profile names (upstream_id_token for reissues_id_token, upstream_access_token for userinfo), or upstream_outcome=not_processed.

resource, scope, audience, actor_token and any parameter of the other form are refused. Decoded values are capped: id_tokens 16 KiB, the access token 8 KiB, the assertion 8 KiB, the session credential exactly 43 characters. The encoded form cap becomes 64 KiB, enough for every cap at once even when the access token’s +, / and = percent-encode to three bytes each. With no upstream profile the grant is unsupported_grant_type and metadata does not advertise it.

F2

The answer. RFC 8693 §2.2.1: access_token = the session credential (renewal echoes it: a web credential is never rotated, since only its opener’s key can present it), issued_token_type = the web-session URN, token_type N_A, expires_in = seconds to fresh_until (at least 0); plus sid and sub (UUID strings: the session and the canopy subject), auth_time, session_ends_at and fresh_until (integer NumericDates), roles and programs (string arrays) and username. Refusals: a request or subject-token defect is invalid_request (400, RFC 8693 §2.2.2); unavailability at open is temporarily_unavailable (503). A refusal canopy-web must act on adds canopy_refusal, from a closed set: the four projection codes, auth_time_too_old, subject_suspended, upstream_refused, grace_exhausted, and session_ended (unknown, ended or revoked, deliberately indistinguishable).

F3

Sessions. The credential is 32 CSPRNG bytes, canonical unpadded base64url, stored only as its SHA-256. A session is INSERT-only records owned by canopy_identity_owner: the session, its validations and at most one revocation, all written by owner functions; the issuer selects them and executes the functions. Each validation carries a version the function allocates under the session’s row lock (the open is 1, each later row the latest plus 1, unique per session); the latest validation is the highest version, and recorded_at is kept for audit only, since a wall clock can step back. Every state change commits its issuance-log row in the same transaction, so nothing takes effect unlogged (D13).

F4

Session terms. session_ends_at = upstream auth_time + identity_web_session_max_seconds (default 43200, between 1800 and 86400). An open whose end is under 900 s away is refused auth_time_too_old, so canopy-web re-authenticates with prompt=login. fresh_until = the last upstream validation + 900 s, never after session_ends_at; the validation instant is the presented id_token’s iat when the request carried one, else the userinfo answer’s arrival. Times are chrono::Utc::now() (D14).

F5

Renewal. A session is bound to the upstream issuer and client it opened under: a renewal under a profile whose issuer or client_id differs revokes the session (upstream_changed) before any upstream call, so a changed issuer’s equal sub never renews an old subject (F7). A refreshed id_token passes C7 (so aud is exactly the client, the session’s client by the binding), then must match the session’s iss, sub and original auth_time, carry a nonce equal to the original’s or none (OIDC Core §12.2; a nonce where the original had none is a mismatch), and carry an iat newer than the latest recorded. The latest id_token again (same SHA-256) is a replay and answers the current state. A userinfo renewal binds expected_sub to the session’s stored upstream sub. Every renewal carries the version it read before its upstream work; a renewal that finds a later version committed is superseded and answers the current state, never overwriting it. Each recorded renewal re-projects and the session takes the new roles and programs, either direction. Verdicts: a presentation defect (a malformed, mismatched or not-newer id_token; userinfo Invalid::AccessToken) or a deployment defect (NoEndpoint, UrlRefused, logged as such) refuses and leaves the session exactly as it was, so it lapses at its recorded fresh_until, which an earlier grace may hold to the last validation + 900 s + grace; the upstream’s verdict (userinfo Refused or any other Invalid; a projection refusal) revokes, narrowing C9’s "Invalid ends the session" to the cases the upstream decided.

F6

Grace. A renewal records grace when canopy-web declares upstream_outcome=not_processed (Amendment 2’s unprocessed classes, which only canopy-web observes) or canopy-identity’s own userinfo call or key fetch is unavailable (C9, extended to keys). Under the session’s lock, and only when no later version has committed, a grace row copies the latest successful validation’s instant, roles, programs and username and sets fresh_until = that instant + 900 s + identity_session_grace_seconds (default 1800, between 0 and 3600), never past session_ends_at; repeated grace never extends it. Grace whose window has passed is refused grace_exhausted. At open, unavailability fails the sign-in.

F7

Subjects. A subject is a UUID v7 minted on the first successful open of an unseen (iss, sub) pair, after projection succeeds, so a refused account leaves nothing. iss is stored exactly as the profile writes it. Matching is that exact pair; a changed issuer (a renamed Kanidm client) mints a new subject until a security admin re-links it (I2e). Link-or-mint is one owner function, so concurrent first opens yield one subject.

F8

Suspension and revocation. I2c builds the suspension record (INSERT-only, latest wins) and checks it at open and renewal; its writer functions are granted to nobody, as identity_revoke_key is, until I2e’s routes call them. A suspended subject’s renewal revokes the session. canopy-web revokes its own session through RFC 7009 POST /identity/revoke; admin revocation is I2e’s.

F9

Profile pairing and deadlines. claims_from and refresh must name the same source (id_token with reissues_id_token, userinfo with userinfo); the parser refuses both mixed pairings. A token-exchange request has one absolute deadline, 13 s from its start, with a 3 s audit reserve: the form, authentication and the renewal’s session read finish by start + 2.5 s; at most three sequential upstream calls (discovery, JWKS, userinfo) follow, bounded by the client’s 2.5 s each; the final transaction or a refusal’s log row runs in the reserve. The deadline is compile-asserted and exported for canopy-web. The key cache runs each fetch in a task it owns, so no caller’s deadline or dropped request cancels a fetch, whether the validator’s key lookup or userinfo’s endpoint lookup started it.

U1: session and subject primitives (canopy-auth)

  • identity_policy/delegation.rs: SubjectId::mint() and SessionId::mint() (UUID v7), Display and FromStr, keeping any-version parsing.

  • New crates/canopy-auth/src/identity_session.rs:

    • SessionCredential: mint(), parse(&str) (exactly 43 canonical base64url characters), hash() → SessionCredentialHash (SHA-256); zeroized, no Debug, Display or Serialize (compile-time probes as SubjectBearer has);

    • F1 and F2’s wire constants (TOKEN_EXCHANGE_GRANT, ID_TOKEN_TYPE, WEB_SESSION_TOKEN_TYPE, the upstream_* parameter names, NOT_PROCESSED) and the closed CanopyRefusal with code();

    • F4 and F6’s terms as pure functions of injected times: SessionTerms::open(auth_time, validated_at, now, &SessionLimits) → Result<SessionTerms, OpenRefusal>, fresh_until(validated_at, ends_at), grace_until(last_success, ends_at, &SessionLimits); SessionLimits::new refuses either setting outside F4’s and F6’s bounds;

    • F9’s deadline constants, compile-asserted.

  • Tests: credential round trip, an evil-input table (padding, +//, 42 and 44 characters, non-canonical trailing bits, non-ASCII) and a proptest that parse accepts exactly what mint renders; each term at its boundary (899/900 s, the bounds, grace never past the end); the ids' v7 mint and any-version parse.

  • Docs: ADR-049 Amendment 6 (F1–F9) with its Status line; an identity_session bullet under == canopy-auth in shared-crates.adoc, after upstream; this page and its nav entry.

Erratum (2026-10-05): TOKEN_EXCHANGE_GRANT re-exports the existing canopy_auth::discovery::TOKEN_EXCHANGE_GRANT.

Erratum (2026-10-05): SessionTerms::open also refuses OpenRefusal::EndOutOfRange when auth_time plus the maximum passes the last NumericDate (unreachable from a validated id_token); U5 answers it invalid_request.

Erratum (2026-10-05): the session terms take and give whole-second NumericDates, with now a chrono::DateTime<Utc> judged in whole seconds, as the id_token validator judges it; F4’s "under 900 s" is read against that now.

U2: the upstream changes renewal needs (canopy-auth)

  • upstream/id_token.rs: VerifiedUpstreamIdToken::issued_at() → NumericDate (NumericDate::from_seconds(i64) landed in U1).

  • upstream/projection.rs: project takes a ProjectionAnchor (iss, sub, auth_time), built From<&UpstreamAnchor> or From<&StoredAnchor>.

  • New upstream/renewal.rs:

    • StoredAnchor::new(iss, client, sub, auth_time, nonce_digest: Option<[u8; 32]>, last_iat: Option<NumericDate>, last_digest: Option<[u8; 32]>), built by canopy-security from its own store; StoredAnchor::bound_to(&UpstreamProfile) → Result<(), BindingMismatch> checks F5’s issuer and client binding;

    • check_refreshed(&StoredAnchor, &VerifiedUpstreamIdToken, presented_digest) → Result<Refreshed, RefreshMismatch>: F5’s match; Refreshed::{Newer, Replay}; RefreshMismatch names the rule, never a value;

    • RenewalVerdict::{Revoke(RevokeReason), Grace, Lapse(LapseReason)} with classify_userinfo(&UpstreamUserinfoError), classify_keys_unavailable(), classify_projection(&ProjectionRefusal), classify_mismatch(&RefreshMismatch) and classify_binding(&BindingMismatch), F5 and F6’s table.

  • upstream/profile.rs: F9’s pairing rule, refused as Invalid { field: "refresh", fault: UpstreamFieldFault::MixedSources }. upstream/userinfo.rs: MAX_UPSTREAM_ACCESS_TOKEN_BYTES = 8 KiB, refused as Invalid::AccessToken before any request.

  • key_cache.rs: a refresh runs its fetch in a task the cache spawns and owns; callers await the task’s result, so dropping a caller never cancels the fetch or leaves the debounce stamped without a result. This covers UpstreamKeySource (keys and userinfo’s endpoint) and I1b’s HttpJwksKeySource alike.

  • Tests: each RefreshMismatch and BindingMismatch alone; Replay vs NotNewer at an equal iat; the four nonce pairs; a stored anchor projecting as the validator-built one does; every outcome’s verdict; both mixed pairings refused; the access-token cap; a cold-cache lookup dropped mid-fetch (by a key lookup and by userinfo’s endpoint lookup) after which the fetch completes and the next lookup is served without a debounce.

  • Docs: the upstream bullet in shared-crates.adoc; configuration-reference.adoc's [#identity-upstream] gains the pairing rule.

Erratum (2026-10-05): U1 adds NumericDate::from_seconds, which U2 named, because U1’s session terms build NumericDates; U2’s section is corrected to as-built.

Erratum (2026-10-05): ProjectionAnchor and FederatedIdentity hold the upstream issuer as written (FederatedIdentity::iss() → &str), since a StoredAnchor's issuer is its store’s text and UpstreamIssuer has no public constructor; StoredAnchor::new takes iss and client as String and sub as OidcSubject.

Erratum (2026-10-05): U2 also exports upstream::nonce_digest and upstream::id_token_digest (SHA-256 of the nonce’s bytes and of the compact id_token as presented), which U4 and U5 store and check_refreshed compares.

Erratum (2026-10-05): check_refreshed refuses a session with no recorded id_token iat as NotNewer and finds no replay without a recorded digest.

Erratum (2026-10-05): U2 adds a sixth classifier, classify_id_token, so a refused refreshed id_token lapses and an unavailable key fetch grants grace through the same exhaustive table; the upstream anchors' Debug output omits the upstream sub and nonce.

U3: session rows in the issuance log (canopy-security)

  • Migration services/canopy-security/migrations/20261213000000_identity_issuance_log_v2.sql adds grant_type IN ('client_credentials','token_exchange','revocation'), subject_id UUID, session_id UUID, session_event IN ('opened','renewed','grace','replayed','superseded','revoked'), and widens outcome to issued, refused, revoked, ignored. Version 1 rows stay valid as history; a NOT VALID CHECK makes every new row version 2, under this table:

    grant_type outcome session_event requires

    client_credentials

    issued

    none

    token_jti, kid, expires_at

    client_credentials

    refused

    none

    error

    token_exchange

    issued

    opened, renewed, grace, replayed, superseded

    session_id, subject_id, expires_at = fresh_until; no kid or token_jti

    token_exchange

    refused

    none, or revoked

    error; subject_id and session_id when known; revoked needs both

    revocation

    revoked

    revoked

    session_id, subject_id

    revocation

    refused

    none

    error: any of invalid_request, invalid_client, unauthorized_client, temporarily_unavailable

    revocation

    ignored

    none

    nothing else (an unknown, ended or revoked credential, answered 200)

  • The stamp trigger digests version 2 rows over every column; data-models/canopy-security.adoc documents each version’s digest recompute. IssuanceRecord and the batch insert carry the new columns, and a log_in(&mut PgConnection, &IssuanceRecord) inserts one row inside a caller’s transaction for U4’s state changes; refusals keep the group-commit writer. The registry tests that insert version 1 rows move to version 2.

  • No upstream sub, username, token or credential is logged.

  • Tests: every row of the table, and each refused error, as CHECK cases; the NOT VALID refusal of a new version 1 row; each version’s digest; a mixed-grant batch; log_in rolled back with its transaction.

  • Docs: [#identity-issuance-stores] in data-models/canopy-security.adoc.

Erratum (2026-10-05): U3’s table gains a row: no grant_type | refused | none | error, for a token request refused before its grant type was established; the token endpoint records the grant once grant_type has passed its check, including for a later missing-parameter or assertion-type refusal.

Erratum (2026-10-05): a refused revocation carries subject_id and session_id together when known; on a refused token exchange, session_id appears only with subject_id.

U4: the subject and session stores (canopy-security)

  • Migration 20261214000000_identity_subjects_sessions.sql, following 20261210000000 (owner transfer, REVOKE ALL, column grants, a closing audit over every identity object):

    • identity_subjects (subject_id UUID PK, created_at); identity_subject_links (upstream_iss, upstream_sub, subject_id REFERENCES identity_subjects, linked_at) with UNIQUE (upstream_iss, upstream_sub), UNIQUE (subject_id, upstream_iss), upstream_sub checked to OidcSubject's shape;

    • identity_subject_suspensions (event_id UUID PK, subject_id, suspended BOOLEAN, recorded_at, actor TEXT, reason TEXT), actor and reason 1–200 bytes;

    • identity_sessions (session_id UUID PK, credential_hash BYTEA UNIQUE, kind, client, subject_id, upstream_iss, upstream_client, upstream_sub, auth_time, nonce_digest BYTEA NULL, opened_at, ends_at): digests 32 bytes; kind = 'web' with client = 'canopy-web'; opened_at < ends_at ⇐ auth_time + interval '86400 seconds';

    • identity_session_validations (validation_id UUID PK, session_id, version BIGINT, recorded_at DEFAULT clock_timestamp(), kind IN ('open','renewal','grace'), validated_at, id_token_iat NULL, id_token_digest BYTEA NULL, fresh_until, roles TEXT[], programs TEXT[], username TEXT): UNIQUE (session_id, version), version >= 1, (kind = 'open') = (version = 1); the iat and digest both present or both absent, absent on grace rows; fresh_until ⇐ validated_at + interval '4500 seconds';

    • identity_session_revocations (session_id UUID PK, revoked_at DEFAULT clock_timestamp(), reason IN ('logout','upstream_refused','projection_refused','upstream_changed','suspended'), client);

    • owner functions, SECURITY DEFINER, issuer EXECUTE (the issuer holds no INSERT on these tables):

      • identity_link_or_mint_subject(p_iss text, p_sub text, p_candidate uuid) RETURNS uuid;

      • identity_open_session(…​), inserting the session (every column above) and its version 1 validation;

      • identity_record_session_renewal(p_session uuid, p_expected_version bigint, p_validation uuid, p_validated_at timestamptz, p_id_token_iat timestamptz, p_id_token_digest bytea, p_fresh_until timestamptz, p_roles text[], p_programs text[], p_username text, p_now timestamptz) RETURNS text: locks the session row, then answers in order revoked; ended (p_now >= ends_at); replayed (digest equal to the latest id_token row’s); not_newer (iat not after it); superseded (latest version ≠ p_expected_version); else inserts version + 1 and answers recorded;

      • identity_record_session_grace(p_session uuid, p_expected_version bigint, p_validation uuid, p_grace_seconds integer, p_now timestamptz) RETURNS text: locks the row, answers revoked, ended, superseded, or exhausted (F6’s fresh_until not after p_now), else copies the latest successful row’s instant, roles, programs and username, inserts version + 1 and answers recorded;

      • identity_revoke_session(p_session uuid, p_reason text, p_client text) RETURNS boolean, false when a revocation exists;

      • identity_purge_sessions(p_batch integer), deleting sessions ended or revoked over 30 days ago with their rows;

    • owner functions granted to nobody: identity_suspend_subject(p_subject uuid, p_actor text, p_reason text) and identity_lift_subject_suspension(p_subject uuid, p_actor text, p_reason text).

  • identity/registry.rs and identity/probe.rs take the new tables and functions into the grant matrix. ISSUER_POOL_MAX_CONNECTIONS rises from 8 to 13, its doc table gaining four connections for federation’s transactions (none held across an upstream call) and one for the session purge.

  • New identity/sessions.rs: an IdentitySessions trait with a Pg implementation on the issuer pool, as JtiStore is. Each write is one composite operation that owns its whole transaction and commits its U3 log row inside it:

    • open(OpenRecord) → OpenOutcome: link-or-mint, the subject’s suspension, identity_open_session, the opened row; a suspended subject rolls back and answers Suspended;

    • renew(RenewRecord) → RenewOutcome and grace(GraceRecord) → GraceOutcome: the suspension (a hit revokes suspended and commits the revoked row), then the function, then the row for its answer;

    • revoke(RevokeRecord) → bool, with its row;

    • current(hash, client) → Option<SessionState>, a read: F2’s fields plus the version, the revocation and the stored anchor.

  • A new identity/sessions/sweeper.rs task calls the purge beside the jti sweeper.

  • SecurityConfig gains identity_web_session_max_seconds and identity_session_grace_seconds, refused at boot through SessionLimits::new.

  • Tests (tests/identity_session_store_test.rs, EphemeralSchema as the issuer login): every CHECK; link-or-mint racing on two pools to one subject; each function’s answers; two userinfo renewals interleaved so the broader one reads first and commits last, answering superseded and leaving the narrower one latest; a grace racing a narrowing renewal never re-widening; versions ordered by allocation when two rows share a recorded_at; a failed log row leaving no subject, session, renewal or grace; the issuer refused direct INSERT, UPDATE and DELETE and the nobody-granted functions; the probe accepting the new matrix and refusing a widened grant; the purge’s age and batch bounds.

  • Docs: data-models/canopy-security.adoc gains [#identity-subjects-sessions] after [#identity-issuance-stores]; configuration-reference.adoc gains both settings; security-operations.adoc [#identity-registry] gains the new grants, the purge, and suspending a subject as the owner until I2e.

Erratum (2026-10-05): every IdentitySessions operation takes the caller’s deadline, detaching its connection past it.

Erratum (2026-10-05): suspension events carry a per-subject version allocated under the subject’s row lock; the latest is the highest version.

Erratum (2026-10-05): a session’s fresh_until is its highest version’s, a grace’s included; roles, programs and username are the latest successful validation’s, which a grace copies.

Erratum (2026-10-05): UpstreamUsername::parse is public, for the session store’s read-back; the issuer-login test fixtures live in tests/common/issuer.rs.

Erratum (2026-10-05): the store judges a session by its stored subject, and the owner functions guard inputs their store never sends.

Erratum (2026-10-05): the open, renewal and grace functions read the subject’s suspension under a key-share lock on the subject row and answer suspended, so a suspension committed during an operation is never missed.

Erratum (2026-10-05): the open, renewal, grace and link-or-mint functions refuse any isolation level but READ COMMITTED (25000), and the store begins every transaction at READ COMMITTED.

U5: the federation grant: open (canopy-security)

  • token_endpoint/request.rs: TokenRequest becomes per-grant (ClientCredentials | TokenExchange), F1’s grammar and caps, MAX_FORM_BYTES 64 KiB.

  • main.rs builds UpstreamKeySource, UpstreamIdTokenValidator and UpstreamUserinfo from the profile and one UpstreamHttpClient (no request at boot, D2) and passes them, as Option, into TokenEndpoint::new.

  • token_endpoint.rs: issue reads and authenticates within F9’s first phase; a token exchange then runs to F9’s absolute deadline, and audit_deadline takes that deadline instead of REQUEST_BUDGET. An open runs: Web only; validate the id_token; userinfo with expected_sub = the anchor’s sub when the claims come from userinfo; project; SessionTerms::open; IdentitySessions::open; F2’s body. A refusal is logged before the answer, as today. TokenErrorCode gains unauthorized_client; metadata lists the grant when a profile is configured.

  • Tests (tests/identity_federation_test.rs, EphemeralSchema plus mock_issuer, a registry holding a test canopy-web key): an open per profile kind; every refusal (client, each grammar defect, each C7 class, keys unavailable, each userinfo outcome, each projection code, auth_time_too_old, suspended); nothing left by a refusal; nothing released without its log row; an upstream refusal arriving at 7.4 s still logged before the deadline; a form at every cap at once with the access token fully percent-encoded; an evil-input table of forms (duplicates, both forms mixed, oversized decoded values, percent-encoded control characters) and a proptest that no form panics the parser.

  • Docs: api/canopy-security.adoc (the token endpoint’s grants, body, canopy_refusal, error table); idp-integration.adoc gains [#federation-grant] after [#upstream-profile]; configuration-reference.adoc's [#identity-upstream] no longer says nothing reads the profile; security.adoc no longer says the endpoint grants only client credentials; authorization-inventory.adoc and services.adoc gain the grant.

Erratum (2026-10-05): the body is read within the 2 s processing budget before the grant is known; a token exchange’s client is authenticated by the first phase’s 2.5 s, and its exchange parameters are judged after the client and profile checks.

Erratum (2026-10-05): both grants recognize every parameter either reads, so a repeated or control-bearing token-exchange parameter also refuses a client-credentials form (RFC 6749 §3.2).

Erratum (2026-10-05): main.rs passes the upstream parts as one Option<Federation> (profile, key source, validator, userinfo client, session store, limits); canopy-security gains the workspace dependency zeroize for the access token userinfo takes.

Erratum (2026-10-05): no valid assertion reaches 8 KiB (its claims are closed and its jti is at most 128 characters), so the every-cap form is read whole to invalid_client, and an open at the id_token’s and access token’s caps is tested separately; the grammar’s 16 KiB cap refuses an oversized id_token before the validator’s own cap, which is mapped and unit-tested.

Erratum (2026-10-05): F5’s classification holds at open too: a presentation defect is invalid_request and a deployment defect 503 temporarily_unavailable, neither with a canopy_refusal; upstream_refused names only the upstream’s own verdicts.

Erratum (2026-10-05): the late-refusal test scripts three 2.4 s upstream delays, so the refusal arrives at 7.2 s or later, past the client-credentials budget, with 100 ms of margin under the client’s 2.5 s timeout.

Erratum (2026-10-05): the session transaction takes the deadline less 1.5 s (TOKEN_EXCHANGE_TRANSACTION_END, 11.5 s from the start), so a transaction that never answers is still refused with its log row before the deadline; the reserve’s last 1.5 s are the refusal’s.

U6: renewal and grace (canopy-security)

  • The renew form: current by hash and opener (session_ended if none), within F9’s first phase; StoredAnchor::bound_to the profile (a mismatch revokes upstream_changed); then by the evidence: check_refreshed and re-project the refreshed id_token; or userinfo bound to the stored sub, projected through ProjectionAnchor::from(&StoredAnchor); or grace. Act on RenewalVerdict; record through renew or grace with the version current read; answer F2’s body, or the current state for a replay or a superseded renewal.

  • Tests (in tests/identity_federation_test.rs): renewal per profile; the profile’s issuer changed and its client changed, each revoking with no upstream call; each RefreshMismatch refused with the session intact; a replay answering the same state; a superseded renewal answering the newer state; userinfo Refused and upstream Invalid revoking, AccessToken and NoEndpoint lapsing; a refusal after a grace leaving the grace’s fresh_until; Unavailable, keys unavailable and not_processed granting grace; grace_exhausted; roles widening and narrowing; a stalled session read refused within the first phase and logged; a cold-cache userinfo renewal dropped mid-discovery, after which the fetch completes.

Erratum (2026-10-05): U6’s database tests live in tests/identity_federation/renewal.rs, a #[path] module of the identity_federation_test binary.

Erratum (2026-10-05): a replayed id_token is verified, matched and projected as a newer one is, and recorded through renew, which answers replayed under the session’s lock; a replay whose claims no longer project revokes.

Erratum (2026-10-05): the renew grammar refuses a malformed credential (session_credential_malformed) and an upstream_outcome other than not_processed (upstream_outcome_unsupported), each invalid_request with no canopy_refusal; ExchangeParameters::form takes the profile’s claims_from and refresh.

Erratum (2026-10-05): a changed binding’s refused revoked row names the field (upstream_issuer_changed, upstream_client_changed); the stored revocation reason is upstream_changed. A refreshed id_token from another issuer is refused by C7 before the refresh rules, RefreshMismatch::Issuer staying as defence in depth.

Erratum (2026-10-05): a renewal’s revocation, renewal and grace each run by the transaction end; a refusal whose row the store committed with its revocation is answered without a second row.

U7: revocation by the opener (canopy-security)

  • POST /identity/revoke (RFC 7009) on the token endpoint’s router and limiter, private_key_jwt: a client other than canopy-web is unauthorized_client before any lookup; canopy-web’s request for its live session revokes it (logout) and answers 200; an unknown, ended or revoked credential answers 200 and revokes nothing. token_type_hint is ignored, as RFC 7009 permits. A malformed form is invalid_request, a bad or spent assertion invalid_client, an unavailable store temporarily_unavailable, each logged per U3’s table. IssuerConfig gains revocation_endpoint and its internal twin; metadata gains revocation_endpoint, revocation_endpoint_auth_methods_supported: ["private_key_jwt"] and revocation_endpoint_auth_signing_alg_values_supported: ["ES256"] (RFC 8414 §2).

  • Tests: each outcome and its log row, every refused error, an idempotent repeat, a revoked session refused at renewal, the metadata fields resolving to the route, an evil-input form table.

  • Docs: api/canopy-security.adoc, authorization-inventory.adoc and services.adoc gain the route.

Erratum (2026-10-05): TokenEndpoint::new takes the session store beside Federation's, so the revocation endpoint is served, and the metadata lists it, with or without an upstream profile, since a session outlives its profile; main.rs passes one store to both.

Erratum (2026-10-05): a revocation runs under the client-credentials budget: the body, authentication, session read and revocation (with its revoked row) by 2 s, and an ignored or refused row within 5 s; its 200 carries no body (RFC 7009 §2.2).

Erratum (2026-10-05): the revocation form uses the token form’s read_body and scan and its 64 KiB cap; token_type_hint is recognized, so a repeated or control-bearing one is refused, and its value is ignored. U7 adds canopy_identity_revocation_answers_total{answer}.

U8: the Kanidm lane’s proof (canopy-test-lib)

  • crates/canopy-test-lib/tests/idp_conformance_kanidm.rs runs U1’s and U2’s rules on real tokens (the grant itself needs canopy-security and a database, so U5 and U6 prove it in-process): SessionTerms::open on a fresh sign-in; check_refreshed answering Newer for a real refreshed id_token (refreshed after sleep_until_early_in_next_second, since Kanidm stamps whole seconds), Replay for the same token again, and NotNewer for the original once the stored anchor has advanced; a stored anchor projecting a real userinfo answer as the id_token did; the expired person’s userinfo Refused classified Revoke. The module doc’s one-job list names these readers.

  • ADR-050 Amendment 4, a run record in Amendment 3’s style, stating which session properties the lane proved and which only in-process.

  • 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; and cargo xtask plan-lint --done docs/modules/ROOT/pages/plans/archive/identity-plane-split-i2c.adoc --allow-open 2712 --allow-open 2713 --allow-open 2714 --allow-open 2715 --allow-open 2716 --allow-open 2717 --allow-open 2718 --allow-open 2719.

Conventions every unit follows

  • Every parser has an evil-input table and a proptest (the credential, the token-exchange form, the revocation form); the id_tokens keep I2b’s jws_evil_cases!. Errors are thiserror enums that never echo input; logs carry canopy subject and session ids, never an upstream sub, username, token or credential.

  • Nothing calls the upstream at boot. Tests inject now and never sleep, except the real-IdP lane, which waits for Kanidm’s whole-second clock through its existing helpers. Database tests live in tests/ or an infra_tests module.

  • Every serde_json::Value under src/ carries // PARTNER-EDGE-UNTYPED: on the line before.

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

Units

  1. U1 (w3) — feat(auth): mint canopy subjects, session ids and credentials (#2712).

  2. U2 (w5) — feat(auth): check refreshed id_tokens, project stored anchors (#2713).

  3. U3 (w3) — feat(security): log session events in the issuance log (#2714).

  4. U4 (w5) — feat(security): store canopy subjects and web sessions (#2715).

  5. U5 (w5) — feat(security): open a web session from an upstream id_token (#2716).

  6. U6 (w5) — feat(security): renew web sessions under a bounded grace (#2717).

  7. U7 (w2) — feat(security): let canopy-web revoke its own sessions (#2718).

  8. U8 (w3) — test(identity): prove the session rules on the Kanidm lane (#2719).

Verification

  1. Per unit: fmt; clippy in both profiles; nextest for canopy-auth, canopy-security and canopy-test-lib; rustdoc-private; quality-budgets; feature-builds; http-clients audit-timeouts and audit-redirects; secret-loads; migrations-lint and db-pools (U3, U4); the named database tests with CANOPY_TEST_INFRA=required.

  2. U8: two full cargo xtask identity conformance --idp kanidm runs, reading the JUnit in full.

  3. Per MR: every validate stage, then git push (the pre-push battery), after cargo xtask dev reload brings the migrations up on the devstack.

Review log

round vendor resolved model verdict

1 (2026-10-05)

Anthropic

claude-opus-5-5

no-ship. Eight blockers, all fixed: profile pairings that could never renew (now both sources must match); an unreachable replay (the digest joins the stored anchor); a grace row built from state read before the lock (the grace function copies under the lock); state changes that could take effect unlogged (each commits its log row); the log’s version 2 shape; the revocation endpoint revealing another opener’s credential; a lane assertion no unit built (the renewal verdict table); and the key-fetch cancellation claim. Also taken: C9’s Invalid narrowed to the upstream’s verdicts, the refreshed-nonce reading, typed answer fields, grace_exhausted, setting bounds, schema backstops, evil-input tables, and the operations, inventory, services and security pages.

2 (2026-10-05)

OpenAI

gpt-6-astra

no-ship. Ten findings and two gaps, all fixed: a session bound to its upstream issuer and client (a change revokes it); stale renewal results rejected by an expected version; validations ordered by a version allocated under the lock, not a wall clock; every revocation refusal loggable; composite store operations owning their transactions; a refusal after grace leaving the grace (the lapse promise corrected); one absolute deadline with an audit reserve; the issuance log moved ahead of the stores (a dependency cycle); RFC 8414’s revocation signing-algorithm field; a 64 KiB encoded form cap; fetches detached inside the key cache, covering userinfo’s discovery; the real-IdP lane’s whole-second waits. No round 3.

Edit this page · default