Identity plane split, plan I2f: native clients, the device flow and DPoP-bound refresh (epic &132)
Status: Done (2026-10-06) — !1574
Epic: &132 (stage I2 of &130)
Issues: #2740 (w3), #2741 (w5), #2742 (w5), #2743 (w5), #2744 (w5), #2745 (w3), #2746 (w5), #2747 (w5), #2748 (w5), #2749 (w5), #2750 (w3)
MR: feat/identity-native: U1–U11 in order, titled "canopy-identity native clients: device flow and DPoP refresh (#2740 … #2750)".
The eleven issues are one deliverable, D7’s issuer side, and each unit builds on the one before, so they ship as one MR under the maintainer’s one-MR-per-related-group ruling, one commit per issue. U1’s commit adds this page and its nav entry: the group Identity Plane Split (epic &130) holding * Identity plane split, plan I2f — native clients: the device flow and DPoP-bound refresh (epic &132), placed just above ** Completed Plans Archive in docs/modules/ROOT/nav.adoc, as plans I2a–I2e did. U11’s commit closes the plan.
This is a Design + Scope plan. GitLab owns tracking. The plan freezes when U1 starts. "Plan I3" always means the stage; N1–N11 are this plan’s decisions.
Context
ADR-049 D7 gives native clients (canopy-cli: Client::Native(NativeClient::Cli), public, no registry keys) an RFC 8628 device flow approved in canopy-web under D6’s step-up. The result is a native session: a rotating refresh credential bound to a device key by DPoP (RFC 9449), from which per-target delegation tokens come through the refresh grant with an RFC 8707 resource. canopy-web re-federates the session’s dedicated upstream grant like a web session, at least every 900 s; the session ends after at most 8 h (24 h in code). Access tokens stay bearer; only the refresh credential is sender-constrained. D5’s DPoP row: verified against the embedded JWK, its thumbprint the session’s binding, htm and htu matching, iat within 60 s, jti single-use.
In the tree today:
-
Sessions are web-only:
identity_sessionsCHECKskind = 'web'andkind <> 'web' OR client = 'canopy-web'(services/canopy-security/migrations/20261214000000_identity_subjects_sessions.sql), and the store bindsWEB_KIND/WEB_CLIENTin open, revoke and every log row and typescurrent()toConfidentialClient(services/canopy-security/src/identity/sessions.rs).MintLookup::Credential { opener: Client },MintView,judgeandActorChainalready accept a native opener (opens_sessions(),crates/canopy-auth/src/identity_policy/clients.rs). The window CHECK (≤ 86 400 s) is D7’s 24 h cap. Web credentials never rotate (F2); identity tables are INSERT-only. -
The token endpoint serves client credentials and token exchange only (
identity/token_endpoint/request.rs). Client authentication, client status, the per-client budget and the jti store areConfidentialClient-typed (client_auth.rs,client_status.rs,token_endpoint/client_limit.rs), so canopy-cli can be neither authenticated, budgeted nor disabled, a gap against D12’s "every mint checks client disablement". The admin guard refuses native actors (admin/guard.rs). -
CompactJwsadmits exactly{alg, kid, typ}and refusesjwk(A9;crates/canopy-auth/src/identity_jws.rs), so a proof needs its own parser.PublicJwk::from_coordinatesandKid::rfc7638(crates/canopy-signing) give RFC 9449’s key and thumbprint. -
The issuance log is version 3 (
20261215000000, closed sets; its version-keyed CHECKs, the revocation-error one among them, exempt any other version).identity_purge_sessionsdeletes only validations, revocations and sessions. The issuer pool is 18 (identity/registry.rs).CanopyRefusalis a closed set.
Scope
In scope: U1–U11 below.
Out of scope:
-
plan I3: canopy-web’s code-entry, describe, confirm, step-up and deny pages, its dedicated-grant storage and single-flight re-federation, its revoke-this-device UI, and a check that the describing and approving worker are one; edge forwarding of
/identity/device_authorization,/identity/tokenand/identity/revokewithDPoPpassed through and canopy-web inCANOPY_TRUSTED_PROXIES; canopy-cli’s key, proofs, serialized refreshes and storage; retiring the password grant and amending ADR-007; a Kanidm-lane device proof; the external security review; -
plan I2g: sizing the pool and the per-IP, native and attempt budgets; the capacity test;
-
not built: DPoP-bound access tokens, DPoP nonces (RFC 9449 §8),
verification_uri_complete, a TUI.
Design
Decisions (recorded in ADR-049 Amendment 9, which lands with U1)
| # | Decision |
|---|---|
N1 |
Device authorization (RFC 8628 §3.1–3.2). A form at |
N2 |
Code entry (§5.1, §5.4). |
N3 |
The device-approval grant (D6). canopy-web’s RFC 8693 exchange that verifies the step-up id_token as a federation open does (C7–C9), requires |
N4 |
Revalidation (adds a D5 row). The native revalidation credential (32 CSPRNG bytes) is the session’s |
N5 |
Redemption: the device_code grant (§3.4–3.5). Binds the session to the proof’s RFC 7638 thumbprint and issues refresh credential version 1 and a delegation token for |
N6 |
The refresh grant (RFC 6749 §6, RFC 9700 §4.14.2). The current version rotates under the session’s lock and mints ( |
N7 |
DPoP proofs (a third exact-header validator beside A9’s two). Header exactly |
now − iat |
≤ 60 s`; the signature verifies under the embedded key; |
N8 |
Native revocation (RFC 7009). |
N9 |
Disablement, budgets, administration (D12, G10). Runtime disablement and the admin client routes cover canopy-cli; every native grant and N2–N3 refuse a disabled canopy-cli. canopy-cli has one per-replica budget, |
N10 |
Issuance log version 4 (below). Every native state change commits its row in its transaction (F3); every poll answer is logged (D13). |
N11 |
Budgets and pool. Device authorization, verification and native revocation: 5 s. Approval and native renewal: F9’s 13 s. device_code and refresh: |
Wire surface
Errors are RFC 6749 §5.2 JSON (error, and canopy_refusal when set) at the token endpoint’s status for each code; every 429 carries Retry-After and is logged. parameter_refused covers scope, resource on N1 and any client assertion on a native form.
| Surface (caller) | Parameters | Success | Refusals: error [canopy_refusal] (log reason) |
|---|---|---|---|
N1 device authorization (canopy-cli) |
|
200, §3.2 body |
|
N2 device verification (canopy-web, |
assertion, |
200 |
|
N3 approval (canopy-web) |
token exchange: |
200, F2’s body with the revalidation credential |
the federation open’s refusals; |
N4 renewal, grace (canopy-web) |
as F5 and F6, both token types native-revalidation |
200, F2’s body, the credential echoed |
F5’s and F6’s; an unredeemed session |
N5 device_code (canopy-cli, |
|
200 |
|
N6 refresh (canopy-cli, |
|
as N5 |
|
N8 revocation (canopy-web or canopy-cli) |
canopy-web: assertion and a web or revalidation credential; canopy-cli: |
200; an unknown, ended, revoked or foreign token 200 |
RFC 7009’s four, as today; an assertion naming another client than |
Metadata gains each entry in the unit that serves it, the two auth-method lists becoming separate constants: device_authorization_endpoint (U7); the device_code grant in grant_types_supported, none in token_endpoint_auth_methods_supported and dpop_signing_alg_values_supported: ["ES256"] (U9); refresh_token in grant_types_supported and none in revocation_endpoint_auth_methods_supported (U10).
Issuance log version 4
grant_type gains device_authorization, device_verification, device_code and refresh_token; outcome gains described and denied; columns device_id (uuid) and refresh_version (bigint); TokenErrorCode gains the six RFC codes. CHECKs v4_events, _v4_session, _v4_token, _v4_device, _v4_refresh; v4_new_rows NOT VALID; schema version 4; ISSUANCE_INSERT_COLUMNS grows by two. Every version-3 CHECK keyed to its version (identity_issuance_log_v3_revocation_error among them) is replaced to cover version 4 or restated in the matching _v4* CHECK, so version-4 revocation, delegation and client_credentials rows keep version 3’s rules.
| Grant, outcome | Required | Forbidden |
|---|---|---|
|
|
token, session, subject, |
|
|
the same |
|
|
token, |
|
|
token |
|
version 3’s |
|
|
token jti, kid and expiry, |
|
|
as |
|
|
|
token |
Schema
Two migrations on the established template (owner transfer, REVOKE ALL, exact grants, -- global-ddl: markers, a closing audit; global_ddl.rs grows by two and xtask’s pin goes from 11 to 13): 20261218000000_identity_issuance_log_v4.sql, then 20261219000000_identity_native_sessions.sql.
-
identity_sessions: the two kind CHECKs become(kind = 'web' AND client = 'canopy-web') OR (kind = 'native' AND client = 'canopy-cli');credential_hash's comment states N4. -
INSERT-only (
identity_registry_immutable; DELETE left to the owner’s purges):identity_device_authorizations(device_idUUID v7 PK;device_code_hashanduser_code_hashUNIQUE, 32 bytes;client=canopy-cli;created_at;expires_at, at most 600 s later; an index onexpires_at);identity_device_decisions(device_idPK and FK;decisionIN (approved,denied);decided_at;subject_idFK;session_idUNIQUE FK;(decision = 'approved') = (session_id IS NOT NULL));identity_native_refresh_credentials(credential_idUUID v7 PK;credential_hashUNIQUE, 32 bytes;session_idFK;version≥ 1;jktthumbprint CHECK;issued_at; UNIQUE (session_id,version));identity_dpop_proofs(jkt,jtiof 1–128,expires_at, PK (jkt,jti)), the jti-store shape ofidentity_client_assertions(column INSERT only; a replay is zero rows). -
Revocation reasons gain
refresh_reused,device_code_reusedandunredeemed, written only by the native functions; the issuer’sidentity_revoke_sessionallowlist stands.
Owner functions are SECURITY DEFINER with a pinned search_path; those that lock refuse anything but READ COMMITTED; expiry is judged at the caller’s p_now (Utc::now()), the purges at clock_timestamp(). Answers in precedence, the first that holds:
| Function | Locks | Answers |
|---|---|---|
|
— |
|
|
the decision PK |
|
|
the denying subject (KEY SHARE), then the decision PK |
|
|
the subject (KEY SHARE), then the session (FOR UPDATE), when approved |
|
|
the same |
|
|
the same |
true, inserting |
|
devices FOR UPDATE SKIP LOCKED |
deletes up to |
|
as |
rows deleted |
|
as today |
also deletes the doomed sessions' refresh credentials, decisions and devices first |
Lock order stays subject before session, and every decision function holds its subject’s lock before it claims a decision PK (approval through identity_open_session, denial explicitly), so no transaction waits on a subject while holding a decision another waits for. Device rows are locked only by the purge and the decisions' FK. The token is signed before the rotation’s transaction and released only after it commits with its log row; reused commits its revocation and refused row, and every other answer but rotated rolls back. The issuer gets SELECT on the three readable tables, INSERT (jkt, jti, expires_at) on the proofs and EXECUTE on the eight functions; the admin’s matrix is unchanged; REGISTRY_TABLES, REGISTRY_FUNCTIONS and the issuer probe follow.
Conventions every unit follows
-
Every new parser has its evil-input table and a proptest; errors never echo input; logs carry canopy subject, session and device ids, never a token, credential, code, proof, upstream
subor username. -
Times come from
chrono::Utc::now()(D14); tests inject clocks and never sleep. Database tests live intests/; each race test is checked by hand to fail with its lock removed. -
Every unit ships its
CHANGELOG.adocbullet and its surface’s canonical page.
Units
-
U1 (w3) —
feat(auth): add device codes, user codes and native limits (#2740).DeviceCode,RefreshCredential,UserCode; the grant, token-type and parameter constants;DEVICE_APPROVAL_MAX_AGE_SECONDSandNATIVE_BUDGET;SessionLimitsgains the native maximum (identity_native_session_max_secondsinconfig.rs) andSessionTerms::opentakes it;CanopyRefusal::UserCodeInvalid. Tests: the user-code evil table (vowels, digits, 7 and 9 symbols, lookalikes, NUL, separators); proptests (render, then parse; no panic); the limits' and the setting’s bounds. Docs: ADR-049 Amendment 9, this page and its nav entry,shared-crates.adoc,configuration-reference.adoc. Erratum (2026-10-06):SessionTerms::opentakes aSessionKindand reads that kind’s maximum fromSessionLimits, which gains it throughwith_native_session_max, soSessionLimits::newkeeps its two arguments; the three 32-byte opaque credentials shareidentity_session's spelling, parsing and hashing. -
U2 (w5) —
feat(auth): verify and mint DPoP proofs (#2741)(crates/canopy-auth/src/identity_dpop.rs). Tests: the evil corpus (alg none, HS256, ES384;d, RSA, OKP, another curve, off-curve and non-canonical coordinates; extra and duplicate members, a badtyp; missing and extra claims,ath,nonceandexpamong them;htmGET andpost;htuof another host, path or scheme, with a query or fragment, and normalized equivalents accepted, an explicit:443among them;iat±61 s; a badjti; signed by another key; truncated, padded, oversized); zero or two headers; proptests (verification never panics; a minted proof verifies; its thumbprint is the signer’s). Erratum (2026-10-06):htuand the target are normalized by the URL parser (WHATWG, a superset of RFC 3986 §6.2.2 and §6.2.3) and by RFC 3986 §6.2.2.2’s percent-escape rule; the embedded key must be a JSON object (JsonObject, moved besidejson_objectinidentity_jws), and every segment is decoded before any is judged. -
U3 (w5) —
feat(security): record native grants in the issuance log (#2742). Tests: each row of the table and each violation; version-4revocationrows held to RFC 7009’s four errors anddelegationandclient_credentialsrows to version 3’s rules; the version 2 and 3 revocation negatives kept; a new version-3 row refused; stored version 1–3 rows and digests intact; a mixed batch; rollback. Docs:data-models/canopy-security.adoc,authorization-inventory.adoc. -
U4 (w5) —
feat(security): store native sessions and devices (#2743). Tests (database, issuer login): every CHECK; every function’s answers in precedence;did_revoketrue on a first replay and false on a later one and after an administrative revocation, for redemption and rotation;jktcopied on rotation;user_code_taken; each purge with the new rows present; direct writes and other isolation levels refused. Docs:data-models/canopy-security.adoc,security-operations.adoc. -
U5 (w5) —
feat(security): serve native sessions from the store (#2744).NativeSessionsandPgNativeSessions,PgDpopJtiStore;current()by kind; revocation by credential hash withRevokeRecord.by: Client; the sweepers' new calls; the pool at 22. Tests (two or three pools): approve × approve, approve × deny, approval (subject A) × re-link (B, then A) × denial (by B) with B < A, redeem × redeem, redeem × suspension, redeem × administrative revocation, rotate × rotate, rotate × administrative revocation, rotate × suspension, redeem × revoke-unredeemed at the expiry edge, purge-devices × approve, re-link × redeem and renewal × rotate (no deadlock), the DPoP jti across pools; a revalidation credential passes neither web renewal nor delegation from a session. Docs:configuration-reference.adoc. -
U6 (w3) —
feat(security): disable and budget native clients (#2745). Client status, the disabled set andClientLimitskeyed byClient;client_namedaccepts canopy-cli;GET clientsgainskind(confidential,native), canopy-cli’s rowregistered: false, enabled: true(a native client needs no registration; only runtime disablement applies); the guard’s comment cites N9. Tests: canopy-cli disabled by route takes effect within 5 s on a manual clock; budget isolation and refill; the guard still refuses canopy-cli chains. Docs:configuration-reference.adoc,api/canopy-security.adoc,security-operations.adoc. -
U7 (w5) —
feat(security): start device flows and verify user codes (#2746). N1, N2, the URI setting, the attempt budget,device_authorization_endpoint. Tests: form evil tables and a parser proptest; every refusal with its row; a collision retried and exhausted; ten attempts, then a logged 429, describes, denials and approvals (U8) drawing on one budget;no-store; 503 unconfigured. Docs:api/canopy-security.adoc,configuration-reference.adoc,services.adoc,authorization-inventory.adoc. -
U8 (w5) —
feat(security): approve devices and renew native sessions (#2747). N3, reusing federation’s verification (identity/token_endpoint/federation.rs); N4, generalizing renewal, grace and revocation by kind; the unredeemed rule. Tests: approval per profile kind;auth_time600 s accepted and 601 s refused; the attempt budget at approval; a refused approval leaves no subject, session or decision; renewal, grace andupstream_changed; unredeemed after expiry answerssession_ended; the form evil table. Docs:api/canopy-security.adoc,idp-integration.adoc(the contract plan I3’s canopy-web follows). -
U9 (w5) —
feat(security): redeem device codes with DPoP (#2748).DPoPread before the body; the grant in the request grammar; the slow_down limiter; I2d’ssignwithact [canopy-cli]; its metadata. Tests (manual clock): a poll 4.9 s after the last answersslow_downand one 5 s afterpending, and aslow_downanswer does not restart the 5 s; denied, expired, unknown; redemption issues the token and version 1; reuse revokes; a token whose transaction does not commit is never released; DPoP refusals mapped; the form evil table. Docs:api/canopy-security.adoc,security.adoc. -
U10 (w5) —
feat(security): refresh and revoke native sessions (#2749). N6, N8 and their metadata. Tests: a rotation chain; narrowing leaves the session’s sets; another key refused, nothing revoked; a superseded version revokes; stale, ended, suspended; G3’s 5 s floor at the session’s end; fault injection: a rotation whose log row is refused or misses its deadline rolls back, and the same version then rotates with nothing revoked; canopy-cli revocation by current and superseded versions, and 200ignoredfor foreign tokens; canopy-web revocation by the revalidation credential; a disabled canopy-cli refused; form evil tables. Docs:api/canopy-security.adoc,security.adoc,authorization-inventory.adoc. -
U11 (w3) —
test(identity): prove the device flow end to end in process (#2750)(services/canopy-security/tests/identity_native/end_to_end.rs). Device authorization, describe, pending andslow_down, approval through the mock upstream (an 11-minute step-up refused), DPoP redemption, the token at its receiver, a refresh for another target, an onward hop, a native renewal, a superseded credential revoking, and canopy-web’s next renewal answeringsession_ended; a second test, canopy-cli’s logout. Docs: Amendment 9’s as-built record. The plan closes here: StatusDone (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;cargo xtask plan-lint --donewith--allow-openfor 2740 to 2750.
Maintainer calls embedded in the decisions
-
No security administration from native sessions (N9), narrowing D6, which implies 10 minutes of it after approval.
-
Strict refresh-reuse detection (N6, RFC 9700): a lost response or a CLI racing itself ends the session, and every per-target token costs a rotation.
-
Describe needs the worker’s web session (N2), so the attempt budget is per worker, not one global limit any worker could exhaust.
-
Accepted residuals: one step-up id_token may approve several devices within its 300 s federation window; user-code hashes do not resist a database reader (34.6 bits); CLI hosts more than 60 s off fail DPoP (nonces deferred); per-replica budgets multiply with replicas; anyone may create pending device authorizations within the per-IP limit (purged after expiry); every pending poll is logged.
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–U5); the database tests withCANOPY_TEST_INFRA=requiredon a reloaded devstack;plan-lint. -
End to end: U11 drives the native lifecycle through the token routes in process, the upstream mocked.
-
Per MR:
cargo xtask dev reload, thengit push(the pre-push battery).
Review log
| round | vendor | resolved model | verdict |
|---|---|---|---|
1 (2026-10-06) |
Anthropic |
claude-opus-5-5 |
no-ship. Seven blockers, all fixed: the version-4 row shapes (the table); open wire contracts (the wire table, the attempt keys, revocation’s |
2 (2026-10-06) |
human-run |
not stated |
Seven findings, all fixed: denial could deadlock with approval and re-linking (denial locks its subject before its decision; a three-way test); version-3 CHECKs keyed to their version let version-4 rows bypass them (replaced or restated, negative tests); redemption could not say whether it revoked ( |