Identity plane split, plan I3a: the devstack identity plane and the token broker (epic &133)
Status: Done (2026-10-08) — !1578
Epic: &133 (stage I3 of &130)
Issues: #2761 (w3), #2762 (w5), #2763 (w3), #2764 (w3), #2765 (w3), #2766 (w5), #2767 (w3), #2768 (w5), #2769 (w3)
MR: feat/identity-devstack-plane: U1–U9 in order, titled "canopy-identity devstack plane and token broker (#2761 … #2769)".
The nine issues ship as one MR under the maintainer’s one-MR-per-related-group ruling, one commit per issue. The plane, the client and the broker are one deliverable the later plans and the switch consume, and no unit is usable alone. U1’s commit adds this page (Status In progress) and its nav entry. U9’s commit closes the plan.
This is a Design + Scope plan. GitLab owns tracking. The plan freezes when U1 starts. K1–K9 are this plan’s decisions; A, B, C, F, H, N and P name earlier amendments' decisions.
Context
Stage I2 (&132) is complete. canopy-identity issues sessions, delegation tokens, system tokens and native sessions, and the client and receiver libraries exist: IdentityTokenValidator, HttpJwksKeySource, ClientAssertionMinter, SystemTokenSource, DelegationTokenSource and the compiled call graph. Nothing is wired. Stage I3 is the cut-over: every service onto canopy-identity, Kanidm the default upstream, no shims and no half-states on main, and an external security review before it merges.
In the tree today:
-
The switch is atomic. canopy-web cannot hold a canopy-identity session and a Keycloak token at once, and the call graph connects every service (canopy-web calls 14, canopy-eligibility 10). A receiver flipped alone refuses every unflipped sender; a sender flipped alone is refused by every unflipped receiver. Without dual trust, which is a shim, there is no per-service flip.
-
Everything runs on Keycloak. 18 services boot their receivers through
canopy_api::bootstrap_requiring(Keycloak discovery, broad audiences); 15 senders hold Keycloak client secrets; canopy-web exchanges at Keycloak (about 40 sites) or uses its service token (about 73). The battery gets Keycloak tokens in 152 Rust test files (crates/canopy-test-lib/src/auth.rs, the password grant in 89), 36 e2e files and k6; Playwright fills Keycloak’s login form. -
The devstack’s identity plane is empty. canopy-security’s issuer is on (
CANOPY_SECURITY__IDENTITY_ISSUER) but has no client registry and no upstream profile, so it federates no sign-in, and no client key exists. Kanidm runs only under the opt-inidp-kanidmprofile forcargo xtask identity conformance: a tmpfs database,kanidmd cert-generate's 30-day CA and 5-day leaf, three persons. A headless sign-in driver with PKCE and TOTP exists (crates/canopy-test-lib/src/upstream/kanidm/login.rs), as does REST provisioning (admin.rs). -
Seeded data keys on today’s subjects. The seed assigns households to the realm ids of jane.caseworker (
…000a) and bob.smith (…0002), the Keycloaksub(tools/canopy-seed/src/actors.rs). D8 makes the seed’s fixed ids canopy subjects linked to the upstream’s persons, as audited security-admin writes; Amendment 8 H7 left those links to I3, since no admin action creates a subject. -
No federation client exists. Only the capacity harness builds federation forms, by hand (
xtask/src/cmd/perf/identity/senders.rs).
The stage
I3 ships as sequential plans, each authored when its predecessor lands; a later plan may re-cut 3–6, and K1 is the rule they keep.
-
I3a (this plan): the devstack identity plane and the token broker.
-
I3b: issuer readiness, #2759 (delegation p99) and #2760 (the pool at the peak).
-
I3c: receivers: an axum layer and principal around
IdentityTokenValidator, the guard set replacingClaimsandReceiverContract, receiver settings; unwired. -
I3d: senders: every sender’s purposes (A2), client-key loading and settings, the shared clients' token plumbing, the verification adapter routes (#2648); unwired.
-
I3e: canopy-web: the confidential upstream client with a nonce (#2344), federation and re-federation, the refresh lead (#2345), delegation for every backend call, the panel cache (#2647), logout, AC-8, step-up, device approval, the security-admin UI, edge forwarding.
-
I3f: the portal, canopy-cli’s device flow, the operator tools, the TypeScript broker and Playwright sign-in, k6.
-
I3g: the switch, one MR wiring every receiver and sender, moving the battery to the broker and deleting the Keycloak path; merged after the external security review.
Scope
In scope: U1–U9 below. No service is wired.
Out of scope:
-
wiring any receiver, sender, canopy-web, the portal or canopy-cli; purposes for senders but the portal (I3d);
-
the TypeScript broker, Playwright, k6 and the battery’s migration (I3f, I3g);
-
Kanidm’s canopy-web redirect for browser sign-in and the device verification URI (I3e);
-
the worker directory’s re-key (D8); removing Keycloak (I3g); #2759 and #2760 (I3b); retention (#1303).
Design
Decisions (recorded in ADR-049 Amendment 11, which lands with U1)
| # | Decision |
|---|---|
K1 |
Staging. Until the switch, an I3 plan lands only additive code and devstack infrastructure: library code no service wires, proven in process or against the devstack’s identity plane. The switch is one MR that wires every receiver and sender, moves the battery to the broker and deletes the Keycloak path; it merges only after the external security review (Consequences), #2759 and #2760. Main never holds a receiver trusting two issuers or a sender holding two credentials. |
K2 |
Kanidm in the default devstack. The
|
K3 |
The cast. Every human worker of
|
K4 |
The devstack issuer’s configuration is generated, never committed (the repository ships none, D10): an ES256 PKCS#8 key per |
K5 |
Subjects by route. A security-admin action creates a subject with a given non-nil UUID: |
K6 |
The federation client. |
K7 |
The token broker. canopy-test-lib’s |
K8 |
Seed links. After provisioning, the bring-up signs |
K9 |
CI. A prebuilt Kanidm image (ADR-050 §3), pushed from main and pulled by the Docker-in-Docker jobs through |
The bring-up
ensure_identity_plane() (xtask/src/devstack_identity.rs) has two phases around every compose up that starts or recreates the devstack: dev start, reload, restart and refresh, and devstack_guard::ensure_ready's cold start and auto_refresh (the path cargo xtask test, e2e, coverage and CI take).
-
Files, before the
up: TLS (U2) and the issuer’s files (U5). -
Provisioning and links, once the
upis healthy: the cast (U4) and the seed links (U9). It reaches published ports atdocker::published_host(): the host of atcp://DOCKER_HOST(CI’s Docker-in-Docker daemon,docker), else127.0.0.1, since a DinD daemon’s published ports live in its own network namespace.
Conventions every unit follows
Workspace lints hold (typed errors, short functions, overflow-safe arithmetic). Devstack-dependent tests are infrastructure tests: they skip without the stack, and CANOPY_TEST_INFRA=required makes the battery’s lanes require it. Every unit ships its CHANGELOG.adoc bullet and its doc pages.
Units
-
U1 (w3)
docs(adr): record the cut-over staging and devstack plane(#2761). Amendment 11 (K1–K9, the stage list) and ADR-049’s Status line; this page and its nav entry. -
U2 (w5)
feat(devstack): run Kanidm in every devstack profile(#2762). K2 and the bring-up’s two phases.-
docker-compose.yml:kanidmin every devstack profile (imagecanopy-kanidm:1.11.2);KANIDM_DOMAIN,KANIDM_ORIGINandKANIDM_BINDADDRESSon P; published${P}:${P}; aliasidm.canopy.test;/dataoncanopy_kanidm_data,/tlsonkanidm-tls; a healthcheck onkanidmd scripting healthcheck. The opt-in service becomeskanidm-conformance(docker::OPT_IN_SERVICESnames it), renamed throughout: its port variable, the TLS volumekanidm-conformance-tls,.devstack/idp/kanidm-conformance-ca.pemand.devstack/idp/kanidm-conformance.json. -
xtask/src/devstack_tls.rs: when.devstack/idp/tls/{chain.pem, key.pem}are absent or expire within 30 days, generate the CA and leaf (leaf key 0600, CA key never written); install chain and key intokanidm-tlswith a one-offdocker compose run --rm --no-deps --user 0ofkanidm(owner 10001, key 0600), so CI’s prebuilt override supplies the image; write the CA to.devstack/idp/kanidm-ca.pem; on a regeneration, restart kanidm and canopy-security (trust anchors load at boot). -
xtask/src/docker.rs: kanidm keeps itsPORT_MAPPINGSentry and variableCANOPY_PORT_KANIDM_8443, but its reserved host port P is also its container port, so discovery asks compose for P;published_host();CANOPY_TEST__KANIDM_ADDR(127.0.0.1:<P>frompush_derived_vars,kanidm:${CANOPY_PORT_KANIDM_8443}incanopy-integration);PORTS_ENV_VERSIONbumped;dev cleanremoves both volumes,.devstack/idpand.devstack/identity. -
xtask/src/devstack_guard.rs:INFRA_EXCLUDEDlosesdevstack/kanidm; its pinned test becomes one that a change there marks the infrastructure stale. -
Tests: the leaf verifies through rustls against only the CA for
idm.canopy.testand fails for another name; regeneration at 31 and 29 days; same-port rendering and discovery;published_hostfortcp://docker:2375, a unix socket and noDOCKER_HOST; the infrastructure marker. Docs:local-dev.adoc,tooling/xtask-catalog.adoc. -
Erratum (2026-10-08):
published_host()landed with U4, its first caller;dev cleanremoves the devstack’s own identity files (.devstack/idp/tls, the CA, the credentials and.devstack/identity) rather than all of.devstack/idp, so the conformance server’s files stay;deployment-guide.adocandtesting.adocchanged too.
-
-
U3 (w3)
chore(ci): build and pull a prebuilt Kanidm image(#2763). K9. The tag is$CI_REGISTRY_IMAGE/devstack/kanidm:1.11.2-<h>,<h>the first 12 hex digits ofgit ls-files -s devstack/kanidm | sha256sum, so a replacement never overwrites a tag a running pipeline pulls. The jobkanidm-imageextends.image-build-base, takes the union of its consumers' rules, and exits early whendocker manifest inspectfinds the tag, otherwise building and pushing it.integration-tests,validate-in-networkandfixture-smokeneed it, compute the tag and exportCANOPY_PREBUILT_KANIDM_IMAGE, whichdocker-compose.prebuilt.yml'skanidm.imagereads. Tests:cargo xtask ci-config-lint, extended to require the edge;docker compose configwith the override. Docs:developer-guide.adoc. Erratum (2026-10-08):<h>is the first 12 hex digits ofsha256sum devstack/kanidm/Dockerfile;kanidm.imagedefaults to the source build’scanopy-kanidm:1.11.2instead of requiring the variable, so the deploy runbooks' use of the override keeps working; the docs went todeployment-guide.adoc, which describes the override; the unit was committed before U2, so no CI job builds Kanidm in its daemon; validate-in-network’s--with-devstackstill builds it from source (#2771). -
U4 (w3)
feat(devstack): provision the devstack’s Kanidm cast(#2764). K3.devstack/kanidm/migrations/00-canopy.hjsonholds the 20 persons, a group per role the cast uses (11) and per program (6), and the claim maps.upstream::kanidm::{PERSONS, GROUPS}follow, pinned by the agreement test, andverify_clientreads its claim-map rows fromGROUPS. The provisioning phase, alsocargo xtask dev identity, provisions when the credentials file is absent, itscast_digest(a new required field; absent or unparseable reads as changed) differs from the cast file’s, or itsidm_adminpassword no longer signs in (adown -vwiped the volume). It then recreates kanidm on an empty volume, recoversidm_admin, runsadmin::provisionand writes the file; a changed origin alone only rewritesoriginandport. Tests: the decision table (absent, unchanged, new digest, missing digest, volume wiped, new origin). Docs:local-dev.adoc. Erratum (2026-10-08):docker::published_host()(U2’s) landed here, where provisioning first reaches a published port. -
U5 (w3)
feat(devstack): configure the devstack issuer with Kanidm and clients(#2765). K4. The files phase writes.devstack/identity/:keys/<client-id>.pem(0600, only when absent),identity-clients.yaml,identity-upstream.yaml(profile: kanidm,client_id: canopy-web,tls_trust_anchors: identity-upstream-ca.pem, re-rendered from P) and the CA copy, rewritten in place (single-file bind mounts); a port change duringupre-renders and restarts canopy-security. Compose mounts them read-only at/app/config/identity-upstream.yaml,/app/config/identity-upstream-ca.pemand/app/config/canopy-security/identity-clients.yaml, and canopy-security’s directory mount becomes per-file mounts ofdefault.yamlanddev.yaml, so no mount point sits inside a read-only bind. Tests: each key loads throughcanopy_signing::load_provisioned_keyand matches its registry entry; the registry parses withClientRegistry::parse(15 enabled); the profile parses with the I2b loader. Docs:local-dev.adoc,configuration-reference.adoc. -
U6 (w5)
feat(security): create canopy subjects by route(#2766). K5.-
Migration
20261220000000_identity_admin_create_subject.sql:create_subjectinidentity_admin_actions' action and target CHECKs (the target subject only), andidentity_admin_create_subject(p_subject, p_actor_subject, p_actor_session, p_actor_token_jti, p_actor_token_kid, p_actor_client, p_reason, OUT action_id, OUT changed)under20261216000000_identity_admin.sql's conventions (isolation check, owner transfer, the exact grant tocanopy_identity_admin, the closing audit matrices extended). -
The runtime inventories admit it:
identity/registry.rs'ADMIN_SIGNATURES(7 → 8) andREGISTRY_FUNCTIONS(30 → 31), which the issuer and admin boot probes read;crates/canopy-test-lib/src/global_ddl.rs' security list (13 → 14). -
POST /identity/admin/subjects, body{subject_id, reason}, answers 201{action_id, changed}behind the admin write guard. -
Tests (
tests/identity_admin*pattern): a create returnschanged: trueand one action row with the actor’s kid, a secondfalse; a non-admin or staleauth_timeis refused; a malformed or nil UUID is a 400; after a link, a federation open of the pair opens as the created subject. Docs:api/canopy-security.adoc,data-models/canopy-security.adoc,security-operations.adoc,authorization-inventory.adoc. -
Erratum (2026-10-08): the link-then-open proof calls
identity_link_or_mint_subject, through which a federation open resolves its subject, rather than a MockIssuer open; the replay inventory’s always-locked count (xtask/src/cmd/perf/ephemeral_schema.rs, 13 → 14) followed in a fix commit.
-
-
U7 (w3)
feat(auth): federate web sessions as a client(#2767). K6,crates/canopy-auth/src/identity_client/federation.rs.-
FederationClient::new(Arc<ClientAssertionMinter>, token_endpoint, revocation_endpoint, IdentityHttpClient), the client from a newIdentityHttpClient::for_federation()whose whole-request bound isTOKEN_EXCHANGE_DEADLINE(13 s) plus 2 s, notnew()'s 10 s;open(id_token, upstream_access_token)returning aFederatedSession(credential,sid,sub,auth_time,session_ends_at,fresh_until, roles, programs, username);renew(&SessionCredential, RenewalEvidence);revoke(&SessionCredential). -
FederationError, classified by the answer’s OAutherrorandcanopy_refusal(the endpoint answers every OAuth error buttemporarily_unavailablewith 400):Refused(CanopyRefusal),ClientRejected(invalid_client),InvalidRequest,Limited(429),Unavailable(503), transport and answer defects. -
Tests: the F1 forms; F2 parsed; every refusal code and class; over-cap and malformed bodies; no redirect followed; with a paused clock an answer after 11 s is received and one after 16 s times out; a no-panic proptest of the F2 parser; canopy-security’s
tests/identity_federation_test.rsopens, renews and revokes through the client against the real router, and a disabled client isClientRejected. Docs:shared-crates.adoc. -
Erratum (2026-10-08):
newtakes the minter by value, asSystemTokenSourceandDelegationTokenSourcedo; the 15 s bound,FEDERATION_REQUEST_TIMEOUT, is set on each request, which overrides the client’s own, so there is nofor_federation(), and its test asserts the built request’s timeout, since a paused clock timed out the connect itself; the real-routerClientRejectedpresents a key the registry does not hold; fix commits made every call’s futureSend, pinned by a compile-time test, and unlinked a private item from a public doc.
-
-
U8 (w5)
feat(test-lib): add the canopy-identity token broker(#2768). K7,crates/canopy-test-lib/src/identity_broker.rs.-
Configuration:
TokenBroker::new(BrokerConfig)(issuer, canopy-security’s URL, the Kanidm credentials file, CA file and address, the keys and cache directories), which xtask calls;from_env()readsCANOPY_TESTIDENTITY_ISSUER,SECURITY_URL,KANIDM_CREDENTIALS,KANIDM_CA,KANIDM_ADDR,IDENTITY_KEYSand__IDENTITY_BROKER_CACHE, which both providers set. -
API, a person being its Kanidm name and each call returning the compact token as a
String:delegation(person, CanopyService, &Narrowing);stepped_up(person, CanopyService)(a sign-in at most 300 s old);system(ConfidentialClient, CanopyService, scope);session(person)returning theFederatedSession. -
Shared sessions: one 0600 entry per person in the cache directory, under an exclusive
std::fs::Filelock, holding everyFederatedSessionfield, the Kanidm refresh token and the last sign-in. Reuse whilefresh_untilis at least 120 s ahead; renew through Kanidm’s refresh and the federation renewal; reopen when renewal fails, a person’s sign-ins at least 30 s (one TOTP step) apart; drop and reopen once on a delegation refusedsession_ended, renew once onsession_stale. U9 deletes the entries of the persons it links. -
The driver trusts the configured CA, and
upstream::kanidm::http_clienttakes a resolved address: the broker looks the configured address up and pinsidm.canopy.testto it. -
In-network: the
canopy-integrationservice runs as uid 1000, soDockerfile.integrationcreates/app/.identity-inputsand/app/.identity-brokerowned byapp, as for/app/target. Before it runs, xtask streams the credentials, CA and keys as a tar into the volumecanopy_identity_inputsthrough a one-offdocker compose run -T canopy-integration(files 0600). The service mounts it read-only and the cache volumecanopy_identity_broker_cacheread-write, and its environment names those paths.validate-in-network'sdocker runrunner mounts the workspace as the host user: its table adds the keys at/app/.devstack/…andCANOPY_TEST__KANIDM_ADDR=kanidm:<P>, under its parity test. -
Tests (infrastructure,
crates/canopy-test-lib/tests/identity_broker_test.rs): every cast person butjane.unscopedopens a session; jane.doe’s canopy-persons token validates withIdentityTokenValidatorover the devstack JWKS with her roles, programs andact; the portal’s canopy-applications system token validates with its purpose’s scope; eight brokers on one cache get onesid; a second broker’ssession()reads an existing entry without signing in; after sec.admin revokes jane.doe’s cached session by route, her next delegation succeeds under a newsid; jane.unscoped isRefused(missing_primary_programs). Unit: the decision at its margins, the entry’s mode, a no-panic proptest of its parser. Docs:testing.adoc,shared-crates.adoc,validate-in-network.adoc. -
Erratum (2026-10-08): keys load with
ProvisionedP256Key::from_pkcs8_pemfrom their files. Host paths are relative to the workspace root holding.ports.env(config::ports_env_root), format v5. Dropping a session keeps the entry’s last sign-in (forget), which is stamped again once each sign-in ends, so the spacing counts from after its TOTP code. The inputs travel as a shell script of base64 heredocs on the one-off’s stdin, not a tar (the tree has no tar crate), ande2e.rsstarts nocanopy-integration, so onlytest.rsinstalls them. validate-in-network’s runner is root, not the host user, so its cache stays in the container. A minting grant answered 503 is retried for up to 90 s, since the issuer’s first signing key signs 60 s after it boots.Driver::with_clientbuilds the pinned driver (http_clientalready took an address). The revocation test uses jane.tanf-worker, and a renewal-in-place test joins the list.
-
-
U9 (w3)
feat(xtask): link the devstack cast to its seeded subjects(#2769). K8. The provisioning phase’s last step builds aTokenBrokerover the.devstackpaths and takesstepped_up("sec.admin", canopy-security). For each other cast person it readsGET /identity/admin/subjects?upstream_iss=…&upstream_sub=…; when that does not answer the realm id, it callscreate_subjectat the realm id, then the link, then deletes the person’s cache entry. A 429 (the admin limit, 60 a minute) waits itsRetry-After, else 1 s, within 120 s overall; a failure fails the bring-up, naming the person. Tests (infrastructure,crates/canopy-test-lib/tests/devstack_identity_test.rs): jane.caseworker’s delegationsubis…000a, bob.smith’s…0002; a second run adds noidentity_admin_actionsrow. Docs:local-dev.adoc,testing.adoc. Closes the plan. Erratum (2026-10-08): the linking is canopy-test-lib’sTokenBroker::link_cast(the realm id fromSeedPerson::realm_subject), which the provisioning phase calls, so the test drives it directly; it forgets a re-linked person’s session rather than deleting the entry; the second-run proof is the run’s emptyLinkReportand an unchanged count of creation and link rows.
Risks
-
Cold build. Kanidm builds from source once per machine (about 11 minutes, about 6 GB while linking); CI pulls U3’s image.
-
TOTP reuse. Whether Kanidm 1.11.2 refuses a reused TOTP code is unrecorded; the broker spaces a person’s sign-ins a step apart and caches sessions.
-
Port drift. A port recovery that rebinds P changes the issuer string; the bring-up re-renders the profile, restarts canopy-security and links under the new issuer, and links under the old one stay inert.
-
Browser sign-in. Kanidm refuses to mix secure and insecure origins, so canopy-web’s browser sign-in against it (http on localhost) needs TLS or a localhost allowance: I3e’s to settle. The broker reads the code from
Locationand needs neither. -
CI. CI is broken upstream, so U3 is verified by lint until it recovers.
-
Bring-up. Every bring-up now depends on Kanidm and canopy-security being healthy before tests run.
Maintainer calls embedded in the decisions
-
K1’s staging: additive preparation on main and one switch MR held for the external review, rather than an integration branch the pre-push battery could not pass mid-switch. Arranging the review is the maintainer’s.
-
Kanidm in every devstack profile from now, beside Keycloak until the switch (K2).
-
The cast’s departures from the realm: no
applicant.test,sec.adminadded, programs forfti.auditoranddata.steward(K3). -
A route that creates subjects with chosen ids, usable in production for adoption, rather than an owner-only seed function outside the admin record (K5).
-
Still open from plan I2g: whether retention (#1303) precedes the switch.
Verification
-
Per unit: fmt; clippy in both profiles; nextest for each touched crate;
rustdoc-private;quality-budgets;secret-loads; U6’smigrations-lintand migration checks;plan-lint. -
The devstack:
cargo xtask dev clean && cargo xtask dev startbrings kanidm up healthy and provisions and links the cast; after anotherdev clean, a coldcargo xtask test --integration(theensure_readypath) does the same before its tests run, with the integration volumes removed first so they are new;cargo xtask dev identityrun twice changes nothing;https://idm.canopy.test:<P>/statusanswers over the CA from the host and from canopy-security’s container; canopy-security’s boot logs the upstream profile and 15 clients. -
Infrastructure tests: U8’s and U9’s pass with
CANOPY_TEST_INFRA=requiredon the host lane and in-network (cargo xtask validate-in-network). -
Per MR: the full pre-push
cargo xtask validatebattery.
Review log
| Round | Vendor | Resolved model | Verdict |
|---|---|---|---|
1 |
Anthropic |
Claude Opus 5.5 (fresh subagent) |
no-ship; eight blockers fixed in-plan: Kanidm reserves |
2 |
not stated (the maintainer’s other vendor) |
not stated |
11 findings (4 P1, 7 P2), fixed in-plan: CI’s DinD daemon owns the published ports ( |