Identity plane split, plan I3c: canopy-identity receivers (epic &133)

Status: Done (2026-10-09) — !1583
Epic: &133 (stage I3 of &130)
Issues: #2792 (U1, w2); #2793 (U2, w2); #2794 (U3, w3); #2795 (U4, w3); #2796 (U5, w3); #2797 (U6, w2); #2798 (U7, w2). Plan I3c2’s issue is #2799 (L7). Each unit relates to #1448, whose X-Canopy-Actor criterion L4 builds.
MR: feat/identity-receivers, "canopy-identity receivers (#2792 … #2798)".

One MR, one commit per issue, under the maintainer’s one-MR-per-related-group ruling: U7’s devstack proof exercises U2–U6 together. U1’s commit adds this page and its nav entry, and U7 closes it. The MR merges once the pre-push battery passes, the maintainer’s standing rule while CI is broken upstream. This is a Design + Scope plan: GitLab owns tracking, and the plan freezes when U1 starts. L1–L7 are this plan’s decisions (ADR-049 Amendment 14).

Context

ADR-049 Amendment 11 stages the cut-over. I3c is "receivers: an axum layer and principal around IdentityTokenValidator, the guard set replacing Claims and ReceiverContract, receiver settings; unwired" (plan I3a, The stage).

In the tree today:

  • The validator is canopy_auth::IdentityTokenValidator (identity_token.rs), built for one compiled CanopyService. validate(token, request_start) returns VerifiedBearer::{System, Delegation} and verifies once (G8).

    • It checks a delegation token’s last hop with may_delegate.

    • It checks nothing equivalent for a system token.

  • The key source HttpJwksKeySource holds D9’s numbers through the shared key_cache.rs: refresh at 300 s, a 30 s debounce, fail-closed at 720 s.

    • Refresh happens only on a lookup, and a lookup that finds a fetch due, or one in flight, waits for it.

    • So a hung canopy-security stalls every receiver for up to the 10 s fetch timeout, every 30 s, while its keys are trusted until 720 s.

    • The Keycloak path refreshes on a timer from boot (jwks.rs start_refresh_task).

  • No principal or generic layer exists. canopy-security’s admin-only SecurityAdmin (identity/admin/guard.rs) is the precedent for the refusal shape.

  • Today’s path has three parts: AuthLayer + auth_middleware, inserting Claims, SubjectBearer and ApplicantOwnership; each service’s ReceiverContract + exchanged_gate; and about 20 bars on Claims, ReceiverContract and EffectiveUser, inside handlers.

  • Many service-only routes are reached in a worker’s request on a service token. After the switch these calls carry delegation tokens: canopy-web’s edges and canopy-cli’s are delegation only, and B4 makes every in-request service call delegation. The round-2 inventory found about 50 canopy-web routes, 18 in-request service-to-service routes and 34 canopy-cli calls whose bars refuse a user (L7).

  • Settings. canopy-identity’s issuer settings exist only in canopy-security (IssuerConfig, validated by identity_url). Its config is partitioned against ServiceSettings under deny_unknown_fields (#1773).

Decisions (ADR-049 Amendment 14, L1–L7; land with U1)

  • L1. The principal. Principal::{User(UserPrincipal), System(SystemPrincipal)}, built from VerifiedBearer.

    • UserPrincipal holds the VerifiedDelegation, for plan I3d’s onward sender. It exposes the subject, session, roles, programs, actor chain, current actor, auth_time, jti and exp, and oidc_subject() → Result<OidcSubject, ApiError>.

    • SystemPrincipal holds the SystemTokenClaims. It exposes the client, purpose, scopes, jti and exp.

    • Principal exposes:

      • user() and system() (Options);

      • client() → Client: the system token’s client, or the current actor;

      • has_role(role), false for a system caller;

      • actor() → Result<Actor, ApiError>, for Actor consumers: Human with the canopy subject’s hyphenated form, which K8 keeps equal to the realm ids rows hold, or Service with the client id;

      • attribution_sub() → String, for the string consumers (idempotency keys, ledgers, export and FTI records): the canopy subject, or a system token’s sub, which is its client id (A4). Today a service’s value is its Keycloak service-account sub.

    • Programs are carried but not enforced.

  • L2. One composable guard: Admission. principal.admit(&admission) → Result<(), ApiError>.

    • Construction. An Admission is const-constructible and never empty. It starts from one arm and adds others:

      • starts: Admission::system(), ::system_from(&[ConfidentialClient]), ::portal(scope), ::user_roles(roles) and ::user_roles_via(&[Client], roles);

      • additions: .and_system(), .and_portal(scope), .and_user_roles(roles) and .and_user_roles_via(..).

    • The arms:

      • system: any confidential client but the portal, or the listed ones. L3 has already held it to an edge.

      • portal: canopy-portal’s system token, holding the scope.

      • user: a delegation token holding a listed role, from any actor G8 admits.

      • user via: the same, only when its current actor is listed. It is the arm for a route a service reaches inside a worker’s request: it carries the user without opening the route to every delegation caller.

    • Refusals (403, ReceiverDenial), in order:

      1. A portal caller: no portal arm → portal_on_non_portal_route; no scope → portal_scope_missing.

      2. A system caller: no system arm → service_class_on_user_only if a user arm exists, else portal_only_route; not in system_from → service_not_allowlisted.

      3. A user: no user arm → system_caller_required if a system arm exists, else portal_only_route. An actor that no user arm admits → actor_not_allowed. An admitted actor holding none of the roles → required_role_missing.

        Every code is today’s except system_caller_required and actor_not_allowed.

    • Ownership stays a step after admission: require_owned_{application,household,person}(ownership, id). Only the portal needs a binding claim (D11).

  • L3. A system token’s edge. The validator refuses a system token whose client has no System or Both edge to the receiver (may_hold_system_token), with Rejection::SystemEdge, checked last. This is the system counterpart of D4’s last-hop re-check. Purposes and scopes stay the issuer’s.

  • L4. The layer. IdentityReceiver (state) and identity_receiver_middleware (axum from_fn_with_state) insert a Principal. In order:

    1. The bearer: exactly one Authorization header, scheme Bearer compared case-insensitively, and one non-empty token (RFC 6750 §2.1).

    2. X-Canopy-Actor is refused, before any key lookup.

    3. Validation at the wall clock (D14), within RECEIVER_KEY_BUDGET (2 s).

    4. X-Canopy-Applicant: for the portal only, verified through the existing ApplicantClaimVerifier, and inserted as ApplicantOwnership.

      401 is only for a token, always with its RFC 9110 §15.5.2 challenge:

      Condition Answer WWW-Authenticate

      No usable bearer

      401 token_missing

      Bearer

      X-Canopy-Actor present

      400 actor_header_retired (RFC 6750 §3.1 invalid_request)

      —

      Rejected by the validator

      401 token_rejected

      Bearer error="invalid_token"

      Keys unavailable, or the budget passed

      503 keys_unavailable

      —

      Applicant claim from a non-portal caller

      403 applicant_claim_not_portal

      —

      Applicant claim, no verifier configured

      403 applicant_claim_unverifiable

      —

      Applicant claim invalid

      403 applicant_claim_invalid

      —

      A refusal logs its validator rule at info, never the token.

  • L5. A receiver’s keys refresh on a timer, and wait only without evidence of an outage. HttpJwksKeySource::start_refresher(&self) → bool spawns a task.

    • Each tick is 30 s (FETCH_DEBOUNCE) apart, the first at once. It stamps the cache’s refresher_tick (monotonic). It starts a fetch, through the single flight and debounce, when no set is held or the set is at least REFRESH_AHEAD (240 s) old.

    • The task holds the cache weakly and ends when it is dropped. A drop guard owned by the task clears refresher_tick when the task ends for any reason: abort, runtime shutdown or panic. It clears only its own generation’s tick.

    • Starting. start_refresher does nothing while a refresher is live (ticked within REFRESHER_LIVE, 60 s), and sets nothing when there is no runtime to spawn on.

    • The cache records each completed fetch’s outcome.

    • The no-wait rule. A lookup answers from a set aged 300–720 s that holds the kid without waiting only while the refresher is live and the latest completed fetch failed. Otherwise today’s rule holds: a fresh set answers, a stale one fetches and waits. The upstream key source (C5) starts no refresher, so it is unaffected.

    • Bounds.

      • While the JWKS answers, the refresher’s fetch lands before the set reaches 280 s. So a revoked key stops verifying within 300 s, idle or busy.

      • While it fails, the bound is 720 s.

      • A refresher that dies, cleared or not, stops granting no-wait within 60 s.

      • These are D9’s bounds as stated.

  • L6. Receiver settings are a typed value now; ServiceSettings fields come at the switch.

    • Shared URL rules. identity_url, IDENTITY_PATH and IdentityUrlError move to canopy-auth (identity_url.rs). canopy-security’s config.rs calls them and re-exports IDENTITY_PATH. A 1:1 From<IdentityUrlError> for IssuerConfigError keeps its error type, messages, importers and tests.

    • ReceiverSettings::new(issuer, internal_url, development) (identity_receiver/settings.rs) validates both by those rules and derives jwks_uri. Its errors name identity_issuer and identity_internal_url, the names I3g gives the ServiceSettings fields (CANOPY_<SVC>__IDENTITY_ISSUER, __IDENTITY_INTERNAL_URL); canopy-security mirrors them then, as it mirrors rulesets_dir.

    • Why not now. An unread key accepted now would be silently ignored (#1773).

  • L7. Route re-authorization is plan I3c2’s (maintainer ruling, 2026-10-09; #2799). Every route a delegation caller reaches whose bar refuses a user gets an Admission with a user arm, under two rules:

    • Visibility is preserved. A user arm admits the roles canopy-web shows that surface to. A reader bar is CASEWORKER_OR_ABOVE_ROLES plus analyst and studio_admin wherever canopy-web shows them the surface.

    • In-request service routes admit users via. A route that services reach inside a worker’s request admits users only through the arm listing those services, plus canopy-web or canopy-cli where they call it.

      I3c2 holds the per-route inventory, including canopy-security’s admin-only reads that canopy-web shows to auditors and case roles, and the deliberate service-only bars it must judge (hearing view, the signed determination record). The switch waits on I3c2.

Translating today’s bars (for I3c2 and I3g)

Today I3c

Extension<Claims> + Extension<ReceiverContract>

Extension<Principal>

claims.require_service_caller(), contract.require_service_only(&claims)

Admission::system(), only where I3c2 finds no delegation caller; otherwise I3c2’s admission

require_dual / require_service_or_exchanged(&claims, roles), require_service_or_caseworker{,_writer}_or_above()

Admission::system().and_user_roles(roles), the CASEWORKER_* constants where they apply

require_user_only(&claims, roles), require_supervisor_or_above() / require_admin() / require_admin_or_quality_control()

Admission::user_roles(roles)

require_dual_or_portal / require_service_or_exchanged_or_portal(&claims, roles, scope)

Admission::system().and_portal(scope).and_user_roles(roles)

receiver::require_service_or_portal(&claims, scope)

Admission::system().and_portal(scope), plus I3c2’s user arm where a delegation caller reaches it

policy::require_portal_only(&claims, scope)

Admission::portal(scope)

exact claims.service_id() == Some(X)

Admission::system_from(&[X]), plus I3c2’s via arm

canopy-web’s service arms (eligibility’s resolve_effective_worker, require_all_feed_caller)

retired; canopy-web calls as the user, and the handler’s user arm governs (I3c2 confirms each)

snap’s orchestrator_caller

principal.client() == Client::Confidential(ConfidentialClient::Eligibility)

applicant::require_owned_*(&claims, ownership, id)

principal.require_owned_*(ownership, id)

EffectiveUser::actor() / .attribution_sub()

principal.actor() / principal.attribution_sub()

WIC’s Actor::Human { subject } destructure

principal.user() → UserPrincipal::oidc_subject()

.user_claims(), claims.has_role(r), SubjectBearer

principal.user(), principal.has_role(r), UserPrincipal::delegation()

Units

Every commit goes through the J1–J8 review. Each subject is at most 72 characters with its ` (#N). Every new `.rs starts with the SPDX line.

  1. U1 (w2) docs(adr): record canopy-identity’s receivers (#2792).

    • ADR. ADR-049 Amendment 14 (L1–L7) before == References, plus the Status line.

    • Plan page. This page (In progress), with an Identity Plane Split (epic &130) nav group above the archive line.

    • I3c2’s issue (#2799), filed under &133 and related to #2792. It carries L7’s rules and the round-2 inventory’s counts and pointers. Its acceptance: plan I3c2 inventories every route a delegation caller reaches whose bar refuses a user, and names each route’s Admission.

  2. U2 (w2) feat(auth): refuse a system token with no edge to its receiver (#2793, L3).

    • identity_token.rs. Rejection::SystemEdge, last in the system path.

    • canopy-security. subject_token_reason gains subject_token_system_edge.

    • Tests. a_system_token_passes_only_along_a_system_edge: every ConfidentialClient × CanopyService. Fixtures that use a pair with no edge move onto a real edge.

    • Docs. shared-crates.adoc.

  3. U3 (w3) feat(auth): refresh a receiver’s keys on a timer (#2794, L5).

    • key_cache.rs. REFRESH_AHEAD, REFRESHER_LIVE, refresher_tick with its generation, the drop guard, each fetch’s recorded outcome, KeyCache::start_refresher, and the no-wait rule. The module docs gain them.

    • HttpJwksKeySource::start_refresher delegates to it.

    • Tests (tokio time paused, the injected IdentityClock advanced with it). The existing cache tests stay as they are and pass.

      • an_idle_receiver_refreshes_before_its_set_reaches_300_s;

      • a_revoked_key_stops_verifying_within_300_s_while_the_jwks_answers;

      • a_jwks_outage_is_served_without_waiting_until_720_s;

      • a_set_past_720_s_fails_closed;

      • an_unknown_kid_still_waits;

      • a_source_kept_past_its_runtimes_shutdown_waits_as_before: the refresher started, the runtime dropped, and a 300 s+ lookup on a new runtime fetches and waits;

      • an_aborted_refresher_clears_at_once;

      • a_refresher_that_stops_ticking_stops_granting_within_60_s;

      • start_refresher_is_idempotent_and_restarts_after_its_task_ends;

      • start_refresher_without_a_runtime_sets_nothing.

    • Docs. shared-crates.adoc.

  4. U4 (w3) feat(auth): add the canopy-identity principal and its guards (#2795, L1, L2).

    • New module. crates/canopy-auth/src/identity_receiver.rs, with principal.rs, admission.rs and denial.rs under identity_receiver/. Re-exported at the crate root.

    • xtask. role_vocabulary_scan learns, in FN_CHECKS, user_roles (0) and user_roles_via (1), and in METHOD_CHECKS, and_user_roles (0) and and_user_roles_via (1). Its fixture test covers each.

    • Tests.

      • admission_refusals_follow_their_order: one case per refusal rule, and one per admitting arm, over U+/U−, a listed and an unlisted actor, a listed and an unlisted system client, canopy-web, and P+/P−.

      • actor_and_attribution_map_users_and_clients.

      • client_is_the_system_client_or_the_current_actor.

      • ownership_binds_only_the_portal.

      • principal_debug_never_prints_the_token.

    • Docs. shared-crates.adoc.

  5. U5 (w3) feat(auth): add the canopy-identity receiver layer (#2796, L4).

    • identity_receiver/layer.rs. IdentityReceiver::new(validator) (any IdentityKeySource, MemoKeySource included) and with_applicant_verifier; identity_receiver_middleware and parse_bearer; the refusal type; RECEIVER_KEY_BUDGET.

    • Dev-dependency. canopy-auth adds canopy-test-lib, as canopy-db and canopy-api do.

    • Tests, through a probe router with tower::ServiceExt::oneshot:

      • each L4 row, in L4’s order;

      • a principal inserted for a user, a system caller and the portal;

      • the budget passing on a stalled key source;

      • jws_evil_cases! through the layer;

      • no_token_reaches_an_emitted_log_line: each refusal and an admitted request under canopy_test_lib::observability::emitted_log_while(Level::TRACE, …) on a current_thread runtime, asserting on the serialized output;

      • a proptest for parse_bearer: it never panics, Bearer <t> over the b64token alphabet round-trips in any scheme case, and any other scheme is refused.

    • Docs. shared-crates.adoc.

  6. U6 (w2) feat(auth): build a receiver from its settings (#2797, L6).

    • canopy-auth. identity_url.rs (moved); ReceiverSettings::new and jwks_uri(); IdentityReceiver::over_http(&ReceiverSettings, CanopyService, IdentityHttpClient), which builds an HttpJwksKeySource and calls start_refresher.

    • canopy-security. config.rs uses the moved function through the 1:1 From, and re-exports IDENTITY_PATH. Its IssuerConfig tests, the proptest issuer_validation_accepts_only_the_rule included, are unchanged and still pass.

    • Tests. each_identity_url_defect_is_named, and a proptest that identity_url accepts only the rule; receiver_settings_name_the_defective_setting; the_jwks_uri_sits_under_the_internal_url; over_http_starts_the_refresher.

    • Docs. shared-crates.adoc.

  7. U7 (w2) test(auth): prove the receiver on the devstack identity plane (#2798).

    • New test file. crates/canopy-test-lib/tests/identity_receiver_test.rs (skips when the devstack is down, like identity_broker_test.rs). It runs a probe router behind IdentityReceiver::over_http for CanopyService::Persons, from the broker’s BrokerConfig: the issuer, security_url + /identity, and development = true.

      • a_caseworker_delegation_reaches_the_probe_as_its_realm_subject: the subject is SeedPerson::realm_subject, and the roles are the cast’s.

      • a_token_for_another_receiver_is_token_rejected.

      • a_portal_system_token_reaches_the_probe_as_the_portal: system(ConfidentialClient::Portal, CanopyService::Persons, Some("portal:persons:read")).

      • no_bearer_is_token_missing.

    • Close.

      • CHANGELOG.adoc Added: one entry per unit U2–U7, citing ADR-049 Amendment 14 Ln, plan I3c Un and the issue.

      • Amendment 14’s as-built, with its plan xref repointed to plans/archive/.

      • Plan I3c becomes Done (YYYY-MM-DD) — !N and moves to plans/archive/. Its nav entry moves to Archive, and the emptied nav group goes.

      • cargo xtask plan-lint --done <i3c> --allow-open 1448 --allow-open 2648 --allow-open 2799, plus one --allow-open per U-issue.

      • After the merge, epic &133 is updated.

Outcomes

  • Done when U1–U7 merge and U7’s devstack proof passes.

  • I3c2 then re-authorizes the delegated routes (L7).

  • The switch (I3g) installs the layer and translates each handler’s bars by the table and I3c2’s inventory.

Scope

In: the principal, Admission, the system-edge check, the layer, the keys' refresher, the receiver settings value, the devstack proof, and filing I3c2.

Out:

  • I3c2 (#2799): the per-route inventory and every route’s admission.

  • I3g: wiring canopy-api’s router, AppState, idempotency, ServiceSettings and /readyz; deleting AuthLayer, ReceiverContract, the Claims bars, exchanged_gate, the hop-2 pair and the three rollout settings; qc_write_gate_sweep_test's adoption.

  • I3d: senders, other clients' purposes, client keys, #2648.

  • Not now: program enforcement, and canopy-exchange as a receiver.

Risks

  • L5’s no-wait rule depends on positive evidence: a live refresher and a failed latest fetch. A dead refresher reverts within 60 s, and a cleared one at once. U3 pins the idle, shutdown, abort and outage cases.

  • Admission's via arm is only as narrow as I3c2 writes it. L7 states the rule, and I3c2’s review checks each row.

  • L6 touches canopy-security’s boot config. The 1:1 From and the re-export keep it unchanged.

  • Unwired code can drift from its consumers. The translation table and I3c2 are the contract. U7 proves the layer against the real issuer.

Verification

  • Per unit: fmt; clippy with validate’s flags; nextest for the touched crates (canopy-auth always; canopy-security for U2, U3 and U6; xtask for U4; canopy-test-lib for U7 with CANOPY_TEST_INFRA=required); quality-budgets, plan-lint and check-docs.

  • Per MR: the pre-push battery.

Review log

Round Vendor Resolved model Verdict

1

Anthropic

Claude Opus 5.5 (fresh subagent)

no-ship. Five blockers, fixed in-plan:

  • L5’s lookup-driven refresh left an idle receiver serving a revoked key past 300 s;

  • the guard × caller codes;

  • U7’s subject length;

  • U7’s --allow-open list;

  • the settings' names.

Notes folded in.

2

not stated (the maintainer’s other vendor)

not stated

5 findings (1 P1, 4 P2), fixed in-plan:

  • P1: the blanket require_service_caller → require_system broke delegated routes. They were inventoried (≈50 canopy-web, 18 service, 34 canopy-cli) and staged to plan I3c2 by maintainer ruling with R+ visibility (L7), and the guard became Admission with a via arm;

  • P2: attribution_sub() split from actor();

  • P2: the refresher’s lifecycle: generation-owned cleanup, liveness, an outage-evidence rule, shutdown and abort tests;

  • P2: the log test uses emitted_log_while over serialized output;

  • P2: every 401 carries a challenge; the actor header is 400 and the applicant claims 403.

Edit this page · default