Identity plane split, plan I2d: delegation tokens and receivers (epic &132)
- Context
- Scope
- Design
- Decisions (recorded in ADR-049 Amendment 7, which lands with U1)
- U1: delegation primitives (canopy-auth)
- U2: the receiver’s delegation validator (canopy-auth)
- U3: delegation rows in the issuance log (canopy-security)
- U4: the mint-time session read (canopy-security)
- U5: the session mint (canopy-security)
- U6: the onward mint (canopy-security)
- U7: per-client limits (canopy-security)
- U8: the sender (canopy-auth)
- U9: the in-process proof (canopy-security)
- Conventions every unit follows
- Units
- Verification
- Review log
Status: Done (2026-10-06) — !1572
Epic: &132 (stage I2 of &130)
Issues: #2720 (w3), #2721 (w3), #2722 (w5), #2723 (w3), #2724 (w5), #2725 (w5), #2726 (w3), #2727 (w5), #2728 (w3)
MR: feat/identity-delegation: U1–U9 in order, titled "canopy-identity delegation tokens and receivers (#2720 … #2728)". Its description relates #1448.
The nine issues are one deliverable, the delegation half of the user plane, so they ship as one MR under the maintainer’s one-MR-per-related-group ruling, one commit per issue. U1’s commit adds this page and its nav entry: the group Identity Plane Split (epic &130) holding * Identity plane split, plan I2d — delegation tokens and receivers (epic &132), placed just above ** Completed Plans Archive in docs/modules/ROOT/nav.adoc, as plans I2a–I2c did. U9’s commit closes the plan.
This is a Design + Scope plan. GitLab owns tracking. The plan freezes when U1 starts.
Context
ADR-049 D3 mints delegation tokens from a session: one audience, the RFC 8693 act chain, a lifetime of at most min(now + 300 s, the subject credential’s exp, the session’s end), roles and programs that may narrow on a hop but never widen, and sender reuse only within the request served. D4 has the issuer apply the call graph and receivers re-check aud, typ and the last hop; D5 binds a subject token to the authenticated client’s audience; D6 refuses a mint from a stale session; D12 checks suspension and session revocation at every mint; D13 and Amendment 3 A6 audit every mint before release. Amendment 4 (B1–B7) compiled the clients, receivers, call graph and token layout; Amendment 6 (F1–F9) built the sessions.
In the tree today:
-
crates/canopy-auth/src/identity_token.rsvalidates system tokens only.IdentityTokenValidator::new(issuer, audience, keys)takes the audience as a string; five call sites in three files construct one (crates/canopy-auth/src/identity_token/tests.rs,services/canopy-security/src/identity/key_source/tests.rs,services/canopy-security/tests/identity_token_test.rs). -
crates/canopy-auth/src/identity_policy/delegation.rspinsDelegationTokenClaimsandActorChain;identity_policy/call_graph.rshasmay_delegateandMAX_ACT_DEPTH(8). Nothing mints a delegation token. -
services/canopy-security/src/identity/token_endpoint/federation.rsserves token exchange only to canopy-web, then refuses withFederationUnconfigured(unsupported_grant_type) when no upstream profile is configured.token_endpoint/request.rsrefusesresourcein a token exchange. The metadata lists token exchange only with a profile.TokenEndpoint::newtakes seven arguments. -
identity/sessions.rsreads a session by credential hash (current) and, privately, by id (state_of, through thestate_select!macro). The issuer holds SELECT on every session table, the suspensions included. -
The issuance log (v2,
20261213000000) has no delegation row. Its four per-grant CHECKs bindschema_version = 2only. The writer inserts each batch as UNNEST of scalar parallel arrays (issuance_log.rs,INSERT_ROWS).identity/registry.rsISSUANCE_INSERT_COLUMNSpins the issuer’s 17 insert columns, which the boot probe holds exactly. -
identity/key_source.rs'sMemoKeySourceis unwired; its memo’s cold read may takeREGISTRY_CALL_BUDGET(11 s).main.rsbuilds theJwksMemoinline insidejwks::router(…). -
crates/canopy-auth/src/identity_client.rsacquires system tokens only. The Keycloak-eratoken_exchanger.rsstays the running exchange until I3: itsExchangeCacheis ruling R4’s per-request reuse, and it compares a returned token’sexpwith the subject’s. -
The token route’s only limiter is per IP (
Quota::per_minute(120)). The issuer pool holds 13 connections. -
#1448 asks for per-hop exchange with attribution in the token and a jti chain over every hop. Its route-narrowing and
X-Canopy-Actorcriteria need senders and receivers wired (I3).
Scope
In scope: U1–U9 below: the delegation primitives, the receiver validator, the log’s delegation rows, the mint-time session read, the session mint, the onward mint, per-client limits, the sender, and the in-process proof.
Out of scope:
-
wiring any sender or receiver, and retiring
token_exchanger.rs(I3, &133); -
the native session’s mint through the refresh grant (I2f), which reuses this plan’s mint core;
-
security-admin routes and step-up enforcement (I2e);
-
production sizing of the per-IP limit, the per-client defaults and the issuer pool (I2g);
-
a breaker or retry in the sender (I3).
Design
Decisions (recorded in ADR-049 Amendment 7, which lands with U1)
| # | Decision |
|---|---|
G1 |
The grant’s wire shape. RFC 8693 token exchange on
After authentication,
Delegation is served whenever the issuer is configured, with or without an upstream profile, since a session outlives its profile; the metadata always lists token exchange. |
G2 |
The answer. RFC 8693 §2.2.1: |
G3 |
Claims and lifetime. B5’s layout. |
G4 |
Narrowing. The base sets are the session’s current roles and programs from a session; onward, the subject token’s intersected with the session’s current, so a renewal’s narrowing reaches the next hop at once. |
G5 |
The session at every mint (D6, D12). One SELECT on the issuer pool reads the session by credential hash and opener (session form) or by
A failed or late read is 503 ( |
G6 |
The subject token, onward. Verified in process against the JWKS memo ( |
G7 |
The issuance log, version 3. Migration
|
G8 |
Receivers. |
G9 |
The sender.
|
G10 |
Budget and limits. A delegation mint ends its processing (body, authentication, subject, session read, signing) by the token exchange’s first phase, start + 2.5 s, and its row within |
U1: delegation primitives (canopy-auth)
-
New
crates/canopy-auth/src/identity_delegation.rs:ACCESS_TOKEN_TOKEN_TYPE,REQUESTED_ROLES_PARAM,REQUESTED_PROGRAMS_PARAM,DELEGATION_MIN_LIFETIME,DELEGATION_AUDIT_RESERVEandDELEGATION_BUDGET, the last compile-asserted equal toTOKEN_EXCHANGE_FIRST_PHASEplus the reserve;Narrowing::parseandNarrowing::apply(G4) with thiserrorNarrowingErrorandScopeRefusal, naming the parameter, never a value;delegation_expiry(G3). -
identity_policy/delegation.rs:RoleSet::intersectandProgramSet::intersect(Nonewhen empty);ActorChain::extended_by(Client), refusing a repeat and the depth bound throughActorChainError. -
identity_session.rs:CanopyRefusal::SessionStale(session_stale) andCanopyRefusal::from_code, the inverse ofcode. -
Tests:
Narrowing::parse's evil-input table (duplicates, empty tokens, upper case, a 65-byte role, unknown and repeated programs, tabs and controls; unsorted input accepted and canonicalized), and proptests that parsing a canonical rendering returns the set, that order does not matter, and that no input panics; subset, widen and exhaust per set;delegation_expiryat each cap and at the 5 s floor;extended_byfor a repeat, the bound and an opener moving inward;from_coderound trip. -
Docs: ADR-049 Amendment 7 (G1–G10) and its Status line;
shared-crates.adoc's canopy-auth bullets; this page and its nav entry.
U2: the receiver’s delegation validator (canopy-auth)
-
identity_token.rsper G8; the five call sites follow. -
Tests: each G8 rule refused alone; the last hop, exhaustively over
Client × CanopyService, accepted exactly whenmay_delegate; a system token never passesvalidate_delegationnor the reverse, andvalidateroutes each;jws_evil_cases!overvalidate_delegation;VerifiedDelegation'sDebugfree of the token. -
Docs:
shared-crates.adoc.
U3: delegation rows in the issuance log (canopy-security)
-
G7’s migration;
GrantType::Delegation,Outcome::DelegatedwithDelegationOrigin::{Session, Onward}andRefusedGrant::Delegation, so the types admit only G7’s shapes;SCHEMA_VERSION3;INSERT_ROWSper G7;ISSUANCE_INSERT_COLUMNSandidentity/probe.rs's matrix. No upstreamsub, username, token or credential is logged. -
Tests: every v2-table row and violation at version 3; each delegation row and violation; a new v2 row refused; stored v1 and v2 fixtures still valid, their stored digests matching their versions' recomputes; a mixed writer batch with unequal role and program lengths and other grants' NULLs;
log_inrolled back with its transaction; the boot probe accepting the migrated matrix and refusing a widened grant. -
Docs:
[#identity-issuance-stores]indata-models/canopy-security.adoc(version 3 and each version’s recompute);authorization-inventory.adoc's probe row.
U4: the mint-time session read (canopy-security)
-
IdentitySessions::mint_view(MintLookup, deadline) → Result<Option<MintView>, SessionStoreError>, one SELECT built onstate_select!;MintLookupisCredential { hash, opener: Client }orSession(SessionId);MintViewholds G5’s fields: the session and subject, the opener,auth_time,ends_at, the highest version’sfresh_until, roles and programs (a grace copies the last success’s, F6), whether revoked, and whether the subject’s highest-version suspension event suspends. -
ISSUER_POOL_MAX_CONNECTIONS13 → 17: theregistry.rsdoc table, its unit test andconfiguration-reference.adoc'sIDENTITY_DATABASE_URLrow. -
Tests (
tests/identity_session_store_test.rs), each separately: every field; a grace’sfresh_until; revoked; suspended, then lifted; the wrong opener, an unknown hash and an unknown id answeringOk(None); a failed queryErr(Database); a stalled readErr(Deadline).
U5: the session mint (canopy-security)
-
token_endpoint/request.rs:ExchangeParametersgainsresourceand bothrequested_*;identifyandjudge(G1);ExchangeForm::Delegate(DelegateForm { subject, target, narrowing }). -
New
token_endpoint/delegation.rs: dispatch byrequested_token_typebefore federation’s client and profile checks; the session form in G1’s order, then G5, G4 and G3; signing with the active key; release throughreleaseonly after thedelegatedrow commits,expires_inrecomputed there. Its processing deadline is the first phase and its audit’sAUDIT_BUDGET, compile-asserted equal toDELEGATION_AUDIT_RESERVE. The metadata lists token exchange always;FederationUnconfiguredanswersinvalid_request.canopy_identity_delegations_issued_total{form}(session,onward) counts released tokens; refusals stay incanopy_identity_token_refusals_total. -
Tests: new binary
tests/identity_delegation_test.rs: against EphemeralSchema and the mock issuer, a session opened by federation minting for every canopy-web delegation edge, narrowed and widened requests, revoked and suspended sessions. In-process: the grammar’s evil-input table and a proptest that no form panics the parser; every refusal’s code, reason andcanopy_refusal; ended and stale sessions over a scripted store; a delayed audit (a scriptedIssuanceAudit) across the session-end boundary, a 5 s-left mint released with a recomputedexpires_inand a 4 s-left mint refused; the clock-step 503; I2c’s no-profile tests now assertinginvalid_request. -
Docs:
api/canopy-security.adoc(the delegation forms, answer and errors);security.adoc;services.adocandauthorization-inventory.adocgain the mint. -
Erratum (2026-10-06): the dispatch by
requested_token_typeisMinting::token_exchangeintoken_endpoint.rs, which identifies the form byExchangeParameters::kind(ExchangeKind::{Federation, Delegation}) and hands it tofederateordelegate; the delegation grammar isjudge_delegation, returning theDelegateForm, and U6 addsDelegationKind::OnwardbesideFromSession. The delayed audit is tested by releasing a committed grant whoseexplies a second behind and two ahead, since the release reads the wall clock and tests never sleep; over a scripted store a session ending in 10 s caps the token at its end and one ending in 4 s is refused, the 5 s edge itself beingdelegation_expiry's fixed-instant test; a row that does not commit withholds the token.
U6: the onward mint (canopy-security)
-
token_endpoint/delegation.rs: the onward form per G1 and G6, the chain extended (G3), the sets intersected with the session’s (G4), the session read bysid(G5), the subject’sjtilogged (G7). -
TokenEndpoint::newtakes aTokenEndpointPartsstruct, since an eighth argument would tripclippy::too_many_arguments.main.rshoists theJwksMemointo oneArcshared by the JWKS route and aMemoKeySourcein those parts. -
Tests (
tests/identity_delegation/onward.rs, a#[path]module ofidentity_delegation_test): a three-hop chain canopy-web → eligibility → applications → persons, each token’sact,client_id,expcap andsubject_token_jti; a token for another service; a subject past itsexpinside the receiver’s leeway;actor_repeated; a target with no edge; a renewal’s narrowing reaching the next hop; a revoked session refusing the next hop; a stalled key source refused by the 2.5 s deadline; a system token as subject; a delayed audit across the subject-expboundary. -
Erratum (2026-10-06): the cases needing a crafted subject token or a stalled key source are in-process tests (
token_endpoint/delegation/onward_tests.rs), signed with the endpoint’s key over scripted published keys: a subject past itsexpinside the leeway, a system token, an actor with no edge,actor_repeatedandactor_chain_too_deep, the subject-expboundary (10 s capped, 4 s refused), and the stalled source on a paused clock, refused at the first phase and not before.tests/identity_delegation/onward.rskeeps the chain, the repeated actor through the eligibility ↔ applications cycle, the narrowing, the revocation and another service’s token against the store and the registry’s keys, its ring nowtests/common/ring.rs, shared withcommon.
U7: per-client limits (canopy-security)
-
identity/clients.rs: the optionalrate_limit_rpm(G10), refused at boot outside its bounds with the entry named. Newtoken_endpoint/client_limit.rs: one directgovernorlimiter per registered client (canopy-security gains the workspacegovernor), checked right after authentication in all three grants;Cause::ClientRateLimitedanswers 429 withRetry-Afterand is logged under its grant. -
Tests: the field’s bounds and default; one client’s exhaustion leaving another’s budget whole; one client’s budget shared across client credentials, federation and delegation; burst then refill on governor’s fake clock; the 429’s body,
Retry-Afterand row; a limited request reaching no subject lookup, session read or signing (scripted spies); revocation unaffected. -
Docs:
configuration-reference.adoc[#identity-clients]. -
Erratum (2026-10-06): the budget is spent right after authentication, before
requested_token_typeis read, so a limited token exchange is logged astoken_exchangewhatever its form (G7’s boundary), and a limited client-credentials request with itsresourceandscope. The budgets areClientLimitsovergovernor's direct limiter; a client without one, which authentication never yields, holds none. The endpoint-level tests are indelegation/flow_tests.rs(its harness) andrevocation/flow_tests.rs, the fake-clock tests inclient_limit/tests.rs.
U8: the sender (canopy-auth)
-
New
identity_client/delegation.rsper G9, besideSystemTokenSource, through the sameClientAssertionMinterandIdentityHttpClient. -
Tests (an axum mock endpoint, as
identity_client/tests.rsserves): both forms' bodies, field by field; a hit, and a near-expiry miss; distinct narrowings and subjects never sharing an entry; a foreign cache refused and two sources never sharing tokens; each malformed answer; onwardexppast the subject’s refused; a correct cap accepted with the sender’s clock 6, 30 and 60 s ahead and behind; refusal codes andcanopy_refusal; a proptest over the answer parser;DelegationToken's compile-time probes. -
Docs:
shared-crates.adoc.
U9: the in-process proof (canopy-security)
-
services/canopy-security/tests/identity_delegation/end_to_end.rs: the token router on a loopback listener; a registry with test keys for canopy-web, eligibility and applications (persons is only a receiver); a session opened by federation against the mock issuer; U6’s chain driven throughDelegationTokenSourceand checked at each hop byIdentityTokenValidatoroverMemoKeySource; then the session revoked, after which the next hop is refusedsession_ended. -
Docs: ADR-049 Amendment 7 gains its as-built record. The plan closes here: Status
Done (YYYY-MM-DD) — !N; the page moved todocs/modules/ROOT/pages/plans/archive/, every xref following; the nav group removed and the archived entry appended, suffixed— DONE YYYY-MM-DD, as the last line of the Completed Plans Archive group;cargo xtask plan-lint --done docs/modules/ROOT/pages/plans/archive/identity-plane-split-i2d.adocwith--allow-openfor 2720 to 2728 and 1448; and #1448 commented: its token and audit criteria met here, its route andX-Canopy-Actorcriteria left to I3.
Conventions every unit follows
-
Every parser has an evil-input table and a proptest (the narrowing, the delegation forms, the sender’s answer); JWS validators keep
jws_evil_cases!. Errors are thiserror enums that never echo input; logs carry canopy subject and session ids, never a token, credential, upstreamsubor username. -
The issuer, receivers and senders read
chrono::Utc::now()(D14); tests inject times or script the store, and never sleep. Database tests live intests/. -
Every
serde_json::Valueundersrc/carries// PARTNER-EDGE-UNTYPED:on the line before. -
Every unit ships its
CHANGELOG.adocbullet and the canonical page for the surface it changes.
Units
-
U1 (w3) —
feat(auth): narrow, expire and extend delegations (#2720). -
U2 (w3) —
feat(auth): validate delegation tokens at receivers (#2721). -
U3 (w5) —
feat(security): log delegations in the issuance log (#2722). -
U4 (w3) —
feat(security): read a session for a mint (#2723). -
U5 (w5) —
feat(security): mint delegation tokens from a web session (#2724). -
U6 (w5) —
feat(security): delegate onward from a subject token (#2725). -
U7 (w3) —
feat(security): rate-limit token requests per client (#2726). -
U8 (w5) —
feat(auth): request delegation tokens as a sender (#2727). -
U9 (w3) —
test(identity): prove delegation end to end in process (#2728).
Verification
-
Per unit: fmt; clippy in both profiles; nextest for canopy-auth and canopy-security;
rustdoc-private;quality-budgets;feature-builds;migrations-lintanddb-pools(U3, U4);http-clients audit-timeoutsandaudit-redirects(U8); the named database tests withCANOPY_TEST_INFRA=requiredagainst a reloaded devstack. -
End to end: U9 proves federation, the session mint, two onward hops, validation at each receiver, and a revocation stopping the chain.
-
Per MR:
cargo xtask dev reload, thengit push(the pre-push battery).
Review log
| round | vendor | resolved model | verdict |
|---|---|---|---|
1 (2026-10-05) |
Anthropic |
claude-opus-5-5 |
no-ship. One blocker, fixed: v2’s per-grant CHECKs bind version 2 only, so G7 restates them for versions 2 and 3, and the session-or-onward rule for |
2 (2026-10-05) |
human-run |
not stated |
no-ship. Eleven findings, all fixed: the issuer’s grant matrix and boot probe; the sender’s cap compares issuer-clock times only; a 5 s mint floor and |