Identity plane split, plan I2a: the call graph, the client model and the delegation token layout (epic &132)

Status: Done (2026-10-04) — !1566
Epic: &132 (stage I2 of &130)
Issues: #2641 (w3), #2642 (w5), #2643 (w5), #2644 (w3), #2645 (w5)
MR: feat/identity-call-graph: U1–U5 in order, titled "canopy-identity clients, call graph and delegation layout (#2641, #2642, #2643, #2644, #2645)". Its description relates #1447 and #1448.

The five issues are one deliverable, the compiled policy every later I2 plan 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. U5’s commit closes the plan.

This is a Design + Scope plan. GitLab owns tracking. The plan freezes when U1 starts.

Context

ADR-049 D4 makes policy code: two compiled tables in canopy-auth, the call graph (which caller may delegate to which target) and the purpose registry. Plan I1b (archive) built the purpose registry for one client, the portal (crates/canopy-auth/src/identity_policy.rs). Stage I2 (&132) builds the user plane on the call graph, so the graph and the clients it names come first.

In the tree today:

  • SystemClient has one variant, CanopyPortal. No type names canopy-web, canopy-cli or a service as a client, and no type names a receiving service: audiences are strings built by service_audience.

  • The edges exist only as deployment settings. Each service’s config module carries one <peer>_url field per service it calls (services/canopy-snap/src/config.rs: rules_url, verification_url, persons_url, enrollment_url, security_url); canopy-eligibility also reads CANOPY_PROGRAM_URL_<PROGRAM> (services/canopy-eligibility/src/registry.rs), and canopy-cli its tools/canopy-cli/src/config.rs profile. Together they name 75 service edges and 12 canopy-cli edges.

  • The one written record, the caller manifest in authorization inventory, is prose, is gated by nothing, and misses at least 22 edges.

  • Only the system token has a pinned layout (SystemTokenClaims, Amendment 3 A4). The delegation token D3 describes has no type.

Scope

In scope: U1–U5 below. Nothing mints, validates a delegation token or serves a route.

Out of scope:

  • upstream profiles and id_token verification (I2b);

  • subjects, sessions and federation (I2c);

  • the delegation mint, its receiver validator and its client (I2d);

  • revocation and security administration (I2e);

  • the device flow and DPoP (I2f);

  • the capacity test (I2g);

  • purposes for any sender but the portal, which arrive with each sender’s I3 cut-over (A2), and wiring any sender or receiver (I3, &133).

Design

Decisions (recorded in ADR-049 Amendment 4, which lands with U1)

# Decision

B1

Clients.

  • SystemClient becomes ConfidentialClient, with no alias. Its 15 variants: canopy-web, canopy-portal and the 13 services that call another service (appeals, applications, caps, eligibility, enrollment, medicaid, notices, renewals, reporting, snap, tanf, verification, wic).

  • NativeClient has one variant, canopy-cli. A native client is public: it has no registry keys and is bound by DPoP (D7).

  • Client is Confidential(ConfidentialClient) or Native(NativeClient), serialized as the bare id string.

  • Only a confidential client authenticates with private_key_jwt (D10). ClientAssertionClaims.iss and .sub are ConfidentialClient, so a native id never parses as an assertion, and the client registry (identity-clients.yaml) refuses one as an unknown client.

B2

Receivers. CanopyService names the 16 services that serve another canopy caller: appeals, applications, caps, eligibility, enrollment, medicaid, notices, persons, renewals, reporting, rules, security, snap, tanf, verification, wic. canopy-exchange joins when it serves a route. audience() is its A3 URI, and from_audience the exact inverse. ConfidentialClient::service() is the service a client runs as (Some for the 13 services). D5’s "aud equals the authenticated client" means the subject token’s aud equals client.service()?.audience().

B3

The call graph. One compiled table, one row per (caller, target): Edge { caller: Client, target: CanopyService, kind: EdgeKind }, with EdgeKind one of Delegation, System and Both.

  • D4’s delegation edges are the Delegation and Both rows. The System and Both rows are the only (client, audience) pairs a purpose may name.

  • Edges only: no per-edge cap on roles or programs. A mint narrows per request (I2d).

  • An edge to a program service holds in every deployment; a profile without the program carries no traffic on it (ADR-005).

B4

Classifying an edge (D3’s routing rule). Every call on the edge is traced to its origin:

  • a call inside a worker’s or a native client’s request, on that user’s data, is delegation, synchronous retries inside that request included (they reuse its bearer);

  • a call from a background task, a detached task, a durable or background retry (an outbox, saga or scheduler leg that outlives the request), boot, or a request the portal made (a system token, no user) is system;

  • the origin is traced transitively: when a background caller calls a service whose handler calls onward, that onward edge carries system work too;

  • an edge with both is Both.

canopy-cli is Delegation only (D7) and the portal System only (D11). Program services call canopy-rules as System: rules evaluates the facts it is sent and holds no user record.

B5

The delegation token layout.

  • Claims, in D3’s order without purpose and scope: iss sub aud exp iat nbf jti client_id sid roles programs act auth_time. Header typ: at+jwt. nbf = iat, and exp − iat is 1–300.

  • sub is a canopy subject UUID (D8) and sid the session’s public UUID, never its credential. Both parse from any UUID version: the issuer mints v7, and the seeded subjects are not v7.

  • roles is a non-empty, sorted, duplicate-free set of names matching ^[a-z_]{1,64}$; the issuer, not the parser, holds the vocabulary, so a rolling deploy survives a new role. programs is a non-empty, duplicate-free set of canopy_reference::Program, sorted by wire id in byte order (caps, chip, medicaid, snap, tanf, wic).

  • act is required (RFC 8693 §4.1). Its outermost sub is the current actor and equals client_id; its innermost names the session’s opener (canopy-web or canopy-cli); every other actor is a confidential client that runs as a service. No actor repeats, and the chain holds at most MAX_ACT_DEPTH actors.

  • Both layouts deny unknown fields, so a system token never parses as a delegation token, nor the reverse.

B6

The depth bound. MAX_ACT_DEPTH is the most actors a chain can hold along compiled delegation edges: the longest sequence of distinct clients that starts at a session opener, in which each client has a delegation edge to the next and the last has one to some target. A test computes it by depth-first search and pins it. The graph has cycles (applications and eligibility call each other), so the no-repeat rule, not acyclicity, keeps chains finite; the target may be an earlier actor.

B7

The census. Edges are observed from the deployment settings that hold peer URLs. A service can call only a peer it has a URL for. The census scans every non-test source file of every service and canopy-cli (not just config.rs), and fails on any url field or CANOPY*_URL* variable it cannot classify. So a new peer setting that follows the naming convention cannot escape it. A setting named outside the convention would; the convention is recorded in canopy’s coding-conventions.adoc overlay, and that is the limit of the guarantee. Route-level authority stays in the receivers' role bars and, for system tokens, purpose scopes.

U1: compiled clients and receivers (crates/canopy-auth)

  • crates/canopy-auth/src/identity_policy.rs becomes a module root over a new identity_policy/clients.rs, as crates/canopy-auth/src/identity_client.rs sits over its directory. It holds ConfidentialClient, NativeClient, Client, CanopyService (each with as_str, FromStr and serde as the id; strum::EnumIter on the three flat enums only), Client::all(), Client::opens_sessions() (canopy-web and the native clients) and ConfidentialClient::service(). Client wraps the other two, so a derived EnumIter would yield only its two outer variants with default payloads; Client::all() instead chains ConfidentialClient::iter() and NativeClient::iter() into all 16 identities.

  • SystemPurpose.client, SystemTokenClaims.sub and .client_id, and ClientAssertionClaims.iss and .sub become ConfidentialClient. The rename runs through every Rust user (git grep -l SystemClient — '*.rs'), canopy-portal’s tokens.rs and canopy-security’s identity module included. The CHANGELOG.adoc Unreleased bullet naming SystemClient is amended to the new types; archived plans stay frozen.

  • Tests:

    • every id round-trips, and near-misses (case, whitespace, a prefix) are refused;

    • Client::all() yields 16 distinct ids, every confidential and native variant exactly once;

    • the three id sets are disjoint except where service() maps a client to its own service’s id, which a test asserts for all 13;

    • from_audience is exact;

    • the registry refuses canopy-cli as an unknown client;

    • the refusals a second client makes reachable, each with a test: ClientAuthRefusal::ClientMismatch (services/canopy-security/src/identity/client_auth.rs) and the validator’s Rejection::Subject (crates/canopy-auth/src/identity_token.rs);

    • the existing tests that use canopy-web as an unknown id switch to an id no enum compiles.

  • Docs: ADR-049 Amendment 4 (B1–B7) and its Status line; shared-crates.adoc; the registry’s client row in configuration-reference.adoc (a compiled confidential id; a native id is refused). This page and its nav entry.

U2: the observed census (xtask)

  • cargo xtask call-graph census prints the observed edges, sorted by sender then target, each with its evidence (file, line, setting). xtask/src/cmd/call_graph.rs holds the Args and the subcommands census, check and doc (U4); xtask/src/cmd/call_graph/observed.rs the extraction. Registered in xtask/src/cmd/mod.rs and xtask/src/main.rs beside MqTopology.

  • Sources, parsed with syn over every non-test .rs file under services/<service>/src/ and tools/canopy-cli/src/ (nested modules such as services/canopy-eligibility/src/bulk/config.rs included), test code excluded through crate::test_scope as xtask/src/cmd/mq_topology.rs does:

    • every struct field named <x>_url, where canopy-<x> is a CanopyService id (U1); self_base_url is the sender’s own service;

    • every string literal naming a CANOPY_*URL* variable, such as eligibility’s CANOPY_PROGRAM_URL<P>, mapped through canopy_reference::Program to its service (CHIP to canopy-medicaid).

  • The naming convention the census relies on (a peer’s base URL is a <peer>_url field or a CANOPY_*_URL* variable) is recorded in docs/modules/ROOT/pages/coding-conventions.adoc.

  • Not peers, each with a reason in a compiled list: redirect_url, portal_base_url, oidc_internal_url, identity_internal_url, redis_sessions_url, keycloak_url, and canopy-security’s internal_url (the issuer’s in-cluster base URL), chain_verify_database_url, chain_verify_tanf_database_url and chain_verify_medicaid_database_url. Any other url struct field or CANOPY*_URL* literal fails the run, naming its file and line.

  • Tests (in-memory sources): a peer field yields an edge, in config.rs and in a nested module; an unclassified field or variable fails with its location; a #[cfg(test)] field is ignored; the CHIP mapping; the non-peer list; a stable order; a proptest that no field name panics the extractor.

Erratum (2026-10-04): the non-peer list above, taken as written, left 54 production settings unclassified, because it was drawn from the config.rs view before the scan was widened to every source file. As built, the census also classifies a <peer>_base_url field as a peer field (like self_base_url), classifies the environment form of the sender’s own setting (CANOPY_<SENDER>__<SETTING>) by the field rules, and lists twelve more non-peers, each with its reason (HTTP-client base_url copies, canopy-security’s identity_database_url, canopy-web’s template links and two of its fields, and canopy-notices' kill_url). All but identity_database_url are values built at run time, not settings: such an entry covers only a field of an item that does not derive Deserialize, never an environment form, and the three single-site ones only in their own file. No pair changes: the census lists 87 pairs. Its output adds a non-peer summary after the pairs, and names each sender by its crate id, so U4 maps a sender to a Client and reports one that is not compiled.

U3: the compiled call graph (crates/canopy-auth/src/identity_policy/call_graph.rs)

  • One documented const slice per caller (const CANOPY_WEB: &[Edge], …), each doc comment naming the call sites behind its kinds, and const CALLERS: [&[Edge]; 16] over them; doc comments on array elements do not compile (unused_doc_comments). pub const MAX_ACT_DEPTH: usize. Functions: edges() → impl Iterator<Item = &'static Edge>, edge(caller, target) → Option<EdgeKind>, may_delegate(caller, target), may_hold_system_token(client, target) and delegators_of(target).

  • The rows start from the table below. The implementer traces every row’s call sites against B4; where a trace contradicts a row, B4 wins, and the commit body names the row and the call site.

    Caller Delegation System Both

    canopy-web

    appeals, applications, caps, eligibility, enrollment, medicaid, notices, persons, renewals, reporting, snap, tanf, verification, wic

    —

    security

    canopy-cli

    applications, caps, eligibility, medicaid, notices, persons, renewals, rules, security, snap, tanf, wic

    —

    —

    canopy-portal

    —

    applications, eligibility, enrollment, notices, persons, renewals, security, snap, verification

    —

    eligibility

    caps, tanf, wic

    eligibility, rules, security

    applications, enrollment, medicaid, persons, renewals, snap, verification

    applications

    renewals

    —

    eligibility, persons, verification

    appeals

    snap

    —

    applications, enrollment

    enrollment

    applications

    —

    —

    notices

    —

    applications, persons

    —

    renewals

    —

    enrollment, persons

    eligibility

    reporting

    —

    applications, caps, enrollment, persons, renewals

    medicaid, snap, tanf

    snap

    —

    rules, security, verification

    enrollment, persons

    tanf

    —

    persons, rules, security

    —

    medicaid

    —

    persons, rules, security

    —

    caps, wic

    —

    rules, security

    —

    verification

    —

    —

    applications, persons

    Two rows carry system work only because a background caller reaches them transitively (B4): applications' postponement saga calls verification, whose handler reads the parent application (services/canopy-verification/src/api/requests.rs ~158), so verification → applications is Both; reporting’s background worker calls TANF’s service-only batch endpoint, which resolves children’s birth dates through persons (services/canopy-tanf/src/participation/week_standard.rs ~133), so tanf → persons is System. The census cannot see a kind, so U3’s doc comments must name the originating background caller for every System and Both row reached this way.

    Erratum (2026-10-04): a call-site trace of all 87 edges, done before U3 started, moved five rows of the table above to what the code does (B4 wins). tanf → persons and renewals → enrollment are System: no worker or native-client request reaches them. eligibility → caps, tanf and wic are Delegation: the order arm dispatches to any program an order names, but no producer names these three, so a future producer adds the system side as a compiled edge, and until then a system token for them fails closed. The rules carve-out in B4 covers eligibility → rules too: its one call, a corpus-hash read in the admin bulk-run routes, carries no user’s data. More generally, a service’s own bookkeeping inside a user’s request — a call that carries no user’s data to a receiver that admits no user, such as eligibility’s JWKS read and audit ingest, canopy-web’s exchange-audit ingest, and medicaid’s admin sweep — is system work.

  • Tests, exhaustive over Client × CanopyService:

    • each pair appears at most once;

    • no Delegation or Both self-edge;

    • canopy-cli’s rows are Delegation and the portal’s System;

    • every compiled purpose names a System or Both pair;

    • every caller of a Delegation or Both row is reachable from a session opener along Delegation and Both rows, so it can hold a subject token;

    • MAX_ACT_DEPTH equals B6’s depth-first count;

    • the functions agree with the table;

    • every compiled client calls at least one service.

U4: the gate and the generated table (xtask)

  • cargo xtask call-graph check (the default subcommand) runs in validate beside mq-topology (xtask/src/cmd/validate.rs), with its own STAGES entry in xtask/src/validate_report.rs (call-graph, Blocking, ErrorChainOnly, placed after mq-topology). The report’s checkpoint and recording methods skip an id the inventory doesn’t list, so without the entry the gate would run unreported and a failure would lose its diagnostics. The inventory count pins and testing.adoc's stage table follow, and a test asserts a failing check records its diagnostics. It fails on:

    • an observed pair that is not compiled;

    • a compiled pair that is not observed (authority nothing uses);

    • drift, in either direction, between edges() and the table in a new "Compiled call graph" section of authorization-inventory.adoc (| caller | target | kind |, one row per edge, sorted as the census sorts). cargo xtask call-graph doc prints that table for pasting; xtask/src/cmd/call_graph/doc.rs renders and parses it.

  • It prints, without failing, each *_AUTHORIZED_EXCHANGER_AZPS entry and canopy-eligibility’s EXCHANGE_TARGETS in docker-compose.yml that is not a compiled delegation edge. An azp maps to its client by removing the -exchanger suffix (canopy-web-exchanger is canopy-web); any other azp prints as unmapped. I3 deletes those settings.

  • There is no allowlist: an exception is a compiled edge with its doc comment.

  • Tests: fixture diffs in each direction; a proptest that the table renders and parses back to the same edge set; a malformed row fails with its line; the advisories never fail.

  • Docs: the existing prose caller manifest stays, labelled as the running Keycloak-era record until I3 replaces it; testing.adoc's gate list.

Erratum (2026-10-04): as built, the gate’s comparison and the compose advisories live in xtask/src/cmd/call_graph/check.rs beside doc.rs. The table must also be in census order with one row per pair, the advisories read every CANOPY_<SENDER>__EXCHANGE_TARGETS (canopy-eligibility’s is the only one set), and EdgeKind gains as_str, Display and FromStr for the table’s kind cell, written in lower case. The table’s header row is | Caller | Target | Kind, and a row has exactly three cells, so a trailing pipe is refused.

U5: the delegation token layout (crates/canopy-auth/src/identity_policy/delegation.rs)

  • DELEGATION_TOKEN_MAX_LIFETIME_SECS: i64 = 300. The header typ is the existing SYSTEM_TOKEN_TYP constant, renamed ACCESS_TOKEN_TYP with no alias, its CHANGELOG.adoc mention amended.

  • Newtypes: SubjectId(Uuid), SessionId(Uuid), RoleName, RoleSet, ProgramSet and ActorChain (current actor first). ActorChain serializes as RFC 8693’s nested {"sub": …, "act": {…}} through a typed RawActor { sub: Client, act: Option<Box<RawActor>> } that denies unknown fields; there is no serde_json::Value. The innermost actor carries no act member at all (#[serde(skip_serializing_if = "Option::is_none")]), since RFC 8693 §4.1 defines act as an object: the leaf fixture is pinned as {"sub":"canopy-web"}, and an explicit "act": null is refused on parse.

  • DelegationTokenClaims holds B5’s claims (client_id: Client) and is built through TryFrom<RawDelegationClaims>, so every context-free B5 invariant is a parse error: client_id is the current actor; nbf equals iat; the chain’s length, opener, middle actors and no-repeat rule; canonical, non-empty sets. Lifetime, iss, aud and the last hop’s edge are the I2d validator’s.

  • canopy-auth gains canopy-reference = { workspace = true }. That brings rust_decimal and utoipa into canopy-auth’s build, both already workspace dependencies; no new crate enters the workspace.

  • Tests: the serialization pinned against a fixture; purpose, scope, cnf and unknown claims refused; the pinned system token never parses as a delegation token and the reverse; each invariant refused on its own; proptests that the claims and ActorChain round-trip and that arbitrary input never panics.

  • Docs: shared-crates.adoc. The plan closes here: Status Done (YYYY-MM-DD) — !N, the page moved to docs/modules/ROOT/pages/plans/archive/ with the nav moved as the header says, Amendment 4’s link repointed, and cargo xtask plan-lint --done docs/modules/ROOT/pages/plans/archive/identity-plane-split-i2a.adoc --allow-open for U1–U5, 1447 and 1448.

Erratum (2026-10-04): as built, client_id and nbf are wire claims but not stored fields. DelegationTokenClaims::client_id() is the chain’s current actor and nbf() is iat, so no value can disagree with them; parsing still refuses a payload whose client_id or nbf differs. The private RawDelegationClaims is the wire form, so only checked claims serialize. Building a part directly returns a typed error: ClaimSetError (empty, repeated or unsorted) for either set, ActorChainError for the chain; a payload’s refusal is the deserializer’s error, whose message names the broken rule. CHANGELOG.adoc never named SYSTEM_TOKEN_TYP, so the rename amends no bullet.

Conventions every unit follows

  • No clock reads, no database and no network in I2a, so every test is a deterministic unit test.

  • Every parser gets a proptest (the census extractor, the ids, ActorChain, the claims). Errors are thiserror enums in canopy-auth and anyhow with context in xtask.

  • Every unit ships its CHANGELOG.adoc Added bullet and the doc pages its section names.

Units

  1. U1 (w3) — feat(auth): compile canopy-identity clients and receivers (#2641). identity_policy/clients.rs, the rename, ADR-049 Amendment 4, this page and its nav entry.

  2. U2 (w5) — feat(xtask): observe the call graph from peer settings (#2642). xtask/src/cmd/call_graph.rs, xtask/src/cmd/call_graph/observed.rs.

  3. U3 (w5) — feat(auth): compile the D4 call graph (#2643). identity_policy/call_graph.rs.

  4. U4 (w3) — feat(xtask): gate the call graph against the census (#2644). check and doc, xtask/src/cmd/call_graph/doc.rs, validate.rs, authorization-inventory.adoc.

  5. U5 (w5) — feat(auth): pin the delegation token claim layout (#2645). identity_policy/delegation.rs, the plan close.

Verification

  1. Per unit: fmt; clippy in both profiles; nextest for canopy-auth, canopy-security, canopy-portal and xtask; rustdoc-private; quality-budgets; feature-builds.

  2. Per MR: every validate stage, then git push (the pre-push battery).

  3. After merge: git grep -n SystemClient — '*.rs' is empty; cargo xtask call-graph census lists 87 pairs; cargo xtask call-graph check passes on main.

Review log

round vendor resolved model verdict

1 (2026-10-03)

Anthropic

claude-opus-5-5

no-ship. Five blockers, all fixed: the census used a type a later unit created, so the clients unit now comes first; the census missed canopy-security’s internal_url; the rename’s greps reached frozen files; programs had no defined order; three cites would fail plan-lint --done. Also taken: per-caller documented consts (doc comments on array elements do not compile), nbf = iat as a parse rule, imperative subjects, a render/parse proptest and a doc subcommand, the azp-to-client mapping, and the CHANGELOG mentions amended.

2 (2026-10-04)

OpenAI

gpt-6-astra

no-ship. Five findings and one clarification, all fixed: verification → applications and tanf → persons are Both, because background callers reach them transitively, and B4 now traces origins transitively; synchronous retries inside a user request keep delegation, and only durable or background retries are system; Client::all() replaces a derived EnumIter on the wrapper enum, with a 16-distinct-ids test; the call-graph gate gets its STAGES entry, since unknown stage ids are silently unrecorded; the census scans every non-test source file, not just config.rs, and B7’s guarantee is narrowed to the documented naming convention; the innermost act omits the member rather than serializing null. No round 3.

Edit this page · default