IdP Integration

For an operator or identity-provider administrator standing up, checking or swapping the identity provider behind a canopy deployment.

canopy-identity, a module of canopy-security, is the one issuer every canopy service trusts (ADR-049). Workers sign in at one upstream OpenID Connect provider, Kanidm by default, or Keycloak or ZITADEL, the tested alternatives (ADR-050; The supported upstreams), and canopy-identity federates that sign-in into a canopy session. No service ever sees an upstream token: every call carries a canopy-identity token. The services once trusted Keycloak directly; ADR-049 records the move.

The shape

  • The upstream signs workers in at canopy-web, and nowhere else. canopy-web is its one relying party, a confidential client (crates/canopy-auth/src/upstream/relying_party.rs).

  • canopy-identity verifies the upstream’s id_token again under the deployment’s upstream profile, projects its claims to roles, programs and a username, links the upstream identity to a canopy subject, and opens a web session (canopy-identity’s federation grant). From that session it mints canopy-web a delegation token per target service (at most 300 s), and a service one onward from a delegation addressed to it. It mints each confidential client a system token for its compiled edges (600 s), the portal’s scoped portal:*, and serves canopy-cli’s device flow (Device approval and native sessions).

  • The receivers. Every service’s /v1 validates canopy-identity tokens against the issuer’s published keys and admits each route’s callers by name (Security › The identity receiver).

  • Applicants have no identity-provider account. The applicant portal sends its own system tokens and its signed applicant claim (ADR-026).

Setting Home

The issuer identifier and its internal URL

CANOPY_<SVC>IDENTITY_ISSUER, CANOPY_<SVC>IDENTITY_INTERNAL_URL on every service (Configuration Reference › Baseline variables); CANOPY_PORTAL__… on the portal

The upstream profile

<CANOPY_CONFIG_ROOT>/identity-upstream.yaml, read by canopy-security and canopy-web (Configuration Reference › the upstream identity profile)

The client registry

<CANOPY_CONFIG_ROOT>/canopy-security/identity-clients.yaml (Configuration Reference › the client registry)

Each client’s private key

CANOPY_<SVC>__IDENTITY_CLIENT_PRIVATE_KEY, reserved, read through the secret provider with no file fallback (Configuration Reference › Secrets)

canopy-web’s upstream client secret and public origin

CANOPY_WEBUPSTREAM_CLIENT_SECRET (reserved), CANOPY_WEBPUBLIC_ORIGIN (Configuration Reference › canopy-web)

canopy-cli’s device page

CANOPY_SECURITY__IDENTITY_DEVICE_VERIFICATION_URI (Configuration Reference › web sessions)

A jurisdiction’s idp.toml holds only its [roles.*] composition role catalog (ADR-022). The upstream is deployment configuration, not ruleset data (ADR-050).

The issuer identifier and metadata

The issuer identifier is canopy-web’s public origin plus /identity: https://web.canopy.test:<port>/identity on the devstack. It must be an absolute https URL whose path is exactly /identity, written in canonical form; boot names the canonical spelling when it is not (crates/canopy-auth/src/identity_url.rs). Every token’s iss is that exact string, and every client assertion’s aud.

  • The public routes reach canopy-security through canopy-web. canopy-web is the only internet-facing service, so its edge (EdgeForwarder, crates/canopy-auth/src/identity_edge.rs) forwards POST /identity/token, /identity/revoke and /identity/device_authorization, and GET /identity/jwks and the metadata, to their twins under the internal URL. The edge holds no credential and parses no form. It forwards only the body, Content-Type and DPoP, and sets X-Forwarded-For to the one client it resolves, overwriting any the client sent (Deployment Guide › The proxy chain).

  • Inside the network every service uses the internal URL, http://canopy-security:8012/identity on the devstack: a receiver fetches {internal}/jwks, a sender posts {internal}/token.

  • The metadata is GET /.well-known/oauth-authorization-server/identity (RFC 8414 §3.1). It names the issuer, token_endpoint, jwks_uri and revocation_endpoint; the grants client_credentials, the RFC 8693 grant, device_code and refresh_token; the token endpoint’s client authentication, private_key_jwt or none (canopy-cli, which proves its key by DPoP instead); ES256 for client assertions and DPoP proofs; and device_authorization_endpoint while the device flow is served (services/canopy-security/src/identity/token_endpoint.rs). While the issuer is unconfigured it answers 503 temporarily_unavailable.

  • The tokens are ES256 compact JWS with typ at+jwt. A token’s aud is the one receiving service’s URI, urn:canopy:service:<service>, such as urn:canopy:service:canopy-persons (service_audience, crates/canopy-auth/src/identity_policy.rs).

The upstream profile

The deployment’s one upstream (ADR-049 §1) is described by one file, <CANOPY_CONFIG_ROOT>/identity-upstream.yaml (ADR-049 Amendment 5). Its fields and refusals are in Configuration Reference › the upstream identity profile. canopy-security and canopy-web read the same file, mounted read-only:

  • canopy-security’s federation grant verifies and projects the upstream’s id_tokens under it (canopy-identity’s federation grant). With no file, canopy-security logs one warning and serves no federation (federation_unconfigured).

  • canopy-web’s relying party signs workers in under it, and canopy-web refuses to boot without it (services/canopy-web/src/auth/boot.rs).

The rules every upstream meets:

  • Profiles. Each vendor profile presets everything but the issuer, the client and the optional endpoints and trust anchors (ADR-049 Amendment 26, AL1):

    • kanidm, the default upstream (ADR-050), and keycloak: ES256, claims from the id_token, a refresh that reissues it, client_secret_basic, the scopes openid and profile, and the claim pointers /roles, /primary_programs and /preferred_username. The roles and programs claims are canopy’s provisioning convention for each product, not built-ins, so the deployment must provision them under those names (The supported upstreams).

    • zitadel: RS256, the same claim source, refresh and client authentication, ZITADEL’s project-roles and organisation scopes, and ZITADEL’s own claims. Roles and programs are the keys of the project-roles claim that the profile’s organisation granted, the programs as program_<wire id> (AL3). A zitadel file also names project_id and organization_id.

    • oidc-generic states every field, for a jurisdiction’s own OpenID Connect provider.

  • The issuer is one exact string. An id_token’s iss and discovery’s issuer must equal the configured issuer byte for byte, so write it as the IdP publishes it. A bare origin may omit its trailing /.

  • Name each endpoint the IdP publishes on another origin. canopy-identity uses discovery’s jwks_uri and userinfo_endpoint only when they pass the endpoint rule and share the issuer’s origin (scheme, host and port); if either fails, the whole key fetch fails and the upstream’s keys are unavailable, even for a profile that reads nothing from userinfo. Google, for example, publishes its JWKS on www.googleapis.com and its userinfo endpoint on openidconnect.googleapis.com, off its issuer https://accounts.google.com, so a Google profile names both (Configuration Reference › Endpoints on another origin).

  • TLS trust anchors. A deployment that fronts its IdP with an internal PKI names a PEM bundle in tls_trust_anchors, beside the profile. The upstream client then trusts only that bundle, never the built-in public roots, so a mis-issued public certificate cannot stand in for the IdP (ADR-049 Amendment 5; ADR-050 Amendment 2). Without one, it trusts the built-in roots.

  • No request at boot. Boot validates the profile and makes no request to the upstream (ADR-049 §2): discovery and keys are fetched when first needed.

  • Userinfo answers plain JSON for the verified subject. canopy-identity calls the IdP’s userinfo endpoint (the profile’s userinfo_endpoint, else discovery’s) with the upstream access token canopy-web forwards, as an RFC 6750 Bearer credential, and accepts only a 200 application/json answer of at most 64 KiB that is a JSON object in which no object, at any depth, names a member twice, and whose sub is the verified id_token’s, byte for byte (OIDC Core §5.3.2). A signed application/jwt answer is refused, so the IdP must serve userinfo unsigned. Every other result is one of three outcomes (ADR-049 Amendment 5): unavailable (no connection, any timeout, the connection lost after sending, 408, 425, 429, a 5xx, or discovery down when the profile names no endpoint) lets an existing session renew within its grace and fails a sign-in; refused (any other 4xx) and invalid (any other answer, or no userinfo endpoint anywhere) end the session.

  • The claims project to roles, programs and a username, or to a refusal code. canopy-identity reads the claims from the verified id_token, or from userinfo when the profile’s claims_from says so, through the profile’s three pointers (ADR-049 Amendment 5; canopy_auth::upstream::project). An id_token or userinfo answer in which any object, at any depth, names a member twice is refused before anything is read, so a nested pointer such as /realm_access/roles cannot resolve to either of two values. The roles claim must be an array of strings, or under zitadel an object whose counted keys are its names: the names in canopy’s role vocabulary (ROLE_VOCABULARY, crates/canopy-auth/src/roles.rs) are granted, a name starting service: never is, and every other name, such as an IdP default group, is ignored. The programs claim must be an array of program wire ids (snap, tanf, medicaid, chip, caps, wic), chip and medicaid distinct and never canonicalized into each other. The username claim must be a string of 1 to 256 bytes with no control character. A name listed twice is granted once; an object names each key once. A refusal carries a code, the first that applies in this order:

    Code Cause

    no_role

    The roles claim is absent, is not an array of strings (under zitadel, not an object), or holds no vocabulary role (service markers, unknown names and keys another organisation granted do not count).

    missing_primary_programs

    The programs claim is absent, or an empty array (under zitadel, no counted program_ key) (ADR-044). Kanidm omits a claim-map claim for a person in none of its groups, so a worker with no program group lands here.

    malformed_primary_programs

    The programs claim is not an array (null included), or holds an element that is not a program wire id: another case (SNAP), a padded or unknown slug, or a non-string (ADR-044). Under zitadel, a counted program_ key whose remainder is no wire id.

    no_username

    The username claim is absent, not a string, empty, longer than 256 bytes, or holds a control character.

  • A cache in front of the upstream must send Age. canopy-identity refreshes the upstream’s discovery and keys every 300 s, sends Cache-Control: no-cache on each fetch, dates a key set by its fetch start less the response’s Age, and fails closed once the set is 720 s stale (ADR-049 Amendment 5; crates/canopy-auth/src/key_cache.rs). That bound holds only if every HTTP cache or CDN between canopy and the IdP sends Age on a response it serves from storage, as RFC 9111 §5.1 requires. A cache that omits Age makes a stored key set look fresh, so a key the IdP removed could keep verifying past 720 s. Sending Age is the deployment’s requirement.

What an upstream must deliver

Whatever the product, the upstream must deliver all of the following. Kanidm, Keycloak and ZITADEL, provisioned as The supported upstreams describes, do; each one’s conformance suite proves it against a disposable server (Local Development › The conformance server, Keycloak’s and ZITADEL’s).

  1. Discovery. A document at {issuer}/.well-known/openid-configuration whose issuer is exactly the profile’s, naming authorization_endpoint, token_endpoint and jwks_uri on the issuer’s origin, or the profile names them (The upstream profile). A userinfo_endpoint too when the profile reads claims or renewals from userinfo.

  2. The authorization code flow for one confidential client. The client is canopy-web’s (Registering canopy’s clients), authenticating at the token endpoint by the profile’s client_auth_method, client_secret_basic or client_secret_post. canopy-web sends a fresh 256-bit state and nonce, an S256 PKCE challenge and the profile’s scopes, which hold openid (UpstreamRelyingParty::authorization). The upstream must accept PKCE S256 and return the nonce in the id_token.

  3. Registered redirects. {origin}/auth/callback for every canopy-web public origin (CANOPY_WEB__PUBLIC_ORIGIN), and {origin}/login as the post-logout redirect when the upstream has an end-session endpoint. Register them exactly; a production deployment registers a static list.

  4. id_tokens canopy can verify (ADR-049 Amendment 5; crates/canopy-auth/src/upstream/id_token.rs). Signed with an algorithm the profile allows, under a kid the JWKS publishes, with a header typ, when present, of JWT or application/jwt. aud is exactly the client id (a string, or an array holding only it), and azp, when present, is the client id. A zitadel profile admits one more aud: an array of exactly the client id and its project_id, with azp the client id. sub is stable, 1 to 255 ASCII bytes with no control character. exp, iat and auth_time are present, and iat is at most 300 s old when canopy verifies it. amr and acr are never read.

  5. auth_time, prompt=login and max_age. canopy-web asks for auth_time as an essential id_token claim on every authorization request (the OIDC Core §5.5 claims parameter), because OIDC lets a provider omit it otherwise. None of the three verified upstreams depends on the request: each sends auth_time unasked, and Keycloak only through its basic client scope, which the request does not replace (Keycloak (keycloak)). The upstream must honour two more parameters:

    • prompt=login, sent on the first sign-in after a sign-out and on the one retry after a stale sign-in. canopy-identity refuses to open a session that would end within 900 s, auth_time_too_old: a web session ends IDENTITY_WEB_SESSION_MAX_SECONDS (12 h by default) after auth_time, so an upstream single sign-on session within 900 s of that age must re-authenticate the worker.

    • max_age, sent on a step-up: 300 s (STEP_UP_MAX_AGE, step_up_options() in crates/canopy-auth/src/identity_admin/client.rs). canopy-web refuses an id_token whose auth_time is outside max_age plus 60 s, and restarts the flow once with prompt=login. canopy-security’s security-admin routes and the device approval accept a sign-in at most 600 s old (SECURITY_ADMIN_MAX_AGE_SECONDS, DEVICE_APPROVAL_MAX_AGE_SECONDS). ZITADEL ignores max_age (ZITADEL (zitadel)), so on ZITADEL that refusal and retry are what enforce a step-up’s freshness.

  6. The claims, mapped in the IdP. Worker roles, spelled as canopy’s role vocabulary, at the profile’s roles pointer; the worker’s programs as wire ids at its programs pointer; a username at its username pointer. canopy maps no roles or programs itself (ADR-044): map the upstream’s groups onto canopy’s names in the IdP. On Kanidm, roles and programs are groups (canopy_role_*, canopy_program_*) projected into the id_token by the canopy-web client’s claim maps (Local Development › Upstream IdP: Kanidm).

  7. A refresh token. A session is fresh for 900 s after its last upstream validation (ADR-049 §6), and canopy-web renews it only from an upstream refresh. Without a refresh token a session cannot be renewed, so it ends when that freshness lapses. Under refresh: reissues_id_token, every refresh answer carries a new id_token with the session’s iss, sub and original auth_time and a newer iat; under refresh: userinfo, userinfo answers for the refreshed access token (canopy-identity’s federation grant). A rotating refresh token is safe: canopy-web never presents one twice (Keeping a session fresh).

  8. Optional endpoints. An RFC 7009 revocation_endpoint, where canopy-web revokes the upstream refresh token at sign-out, and an RP-Initiated Logout end_session_endpoint. Without the latter, canopy-web signs the worker out locally and sends prompt=login on the next sign-in, so the upstream’s single sign-on session cannot sign the worker straight back in. Kanidm advertises no end-session endpoint (ADR-050).

Four obligations canopy cannot check:

  1. Multi-factor authentication for every worker. canopy reads no acr or amr claim. Where each supported upstream enforces it is in The supported upstreams (AL4).

  2. sub stability. canopy links each exact (issuer, sub) pair to one canopy subject, so a new sub, or a renamed issuer, is a new subject until a security administrator re-links it (Security Operations › Re-linking an upstream identity).

  3. Deprovisioning. A worker removed upstream must have their next refresh refused: the upstream’s refusal ends the session, and canopy-web renews at least every 900 s. To end access sooner, suspend the worker’s subject and revoke their sessions at canopy-web’s /admin/security; a delegation token already minted lives at most 300 s more (Security Operations › Subjects and web sessions).

  4. Role and program mapping in the IdP, as above.

The supported upstreams

Three products are verified upstreams, each with its profile and conformance suite (ADR-050, Amendments 3, 5 and 6; ADR-048 Amendment 2). Each runs at the version its suite verified; a version bump is a change with its suite (cargo xtask identity conformance --idp <idp>). For each: a setup checklist, the profile skeleton, where MFA is enforced, and what it does that canopy relies on knowing. The devstack provisions all three this way (Local Development › The devstack’s upstream), so its provisioning code is a working reference.

Kanidm (kanidm, the default)

  • Version: 1.12.2.

  • Checklist.

    • Persons, the groups canopy_role_<role> and canopy_program_<wire id>, and the canopy-web OAuth2 client, whose claim maps project the groups as roles and primary_programs (the devstack’s cast file, devstack/kanidm/migrations/00-canopy.hjson).

    • canopy-web’s origins' /auth/callback registered as the client’s redirects.

    • Each person’s password and TOTP.

  • Profile:

    profile: kanidm
    issuer: https://idm.example.org/oauth2/openid/canopy-web
    client_id: canopy-web
  • MFA: Kanidm’s credential policy for idm_all_persons requires it: Kanidm refuses to commit a password-only credential, which its suite tests.

  • Behaviour:

    • No end-session endpoint: canopy-web revokes the refresh token at sign-out.

    • A refreshed id_token repeats the nonce.

    • auth_time comes unasked, though Kanidm does not document it.

    • Refresh replay is judged in whole seconds (ADR-050 Amendment 1). Replaying a token superseded in an earlier second is refused and revokes the session. Replaying one that was issued and rotated within a single second is accepted, which forks the session. The suite pins both cases.

Keycloak (keycloak)

  • Version: 26.8.2.

  • Checklist (ADR-049 Amendment 26; the devstack’s realm, devstack/keycloak/realm.json, is a template with no secrets):

    • A realm with an ECDSA P-256 key provider and defaultSignatureAlgorithm: ES256.

    • A TOTP policy (the devstack uses HmacSHA256, 6 digits, 30 s). Keep Keycloak’s single-use default: only the devstack’s realm sets otpPolicyCodeReusable.

    • A browser flow, a copy of browser whose OTP Form is REQUIRED rather than conditional, bound as the realm’s browser flow. Also a direct-grant flow that requires the OTP, since Keycloak gives every realm admin-cli, whose password grant would otherwise skip it.

    • CONFIGURE_TOTP disabled. Otherwise an account without an OTP credential could enrol one on its password alone. Enrol each worker’s OTP credential administratively instead.

    • primary_programs declared in the user profile (Keycloak 24+ refuses unmanaged attributes), and realm roles named as canopy’s role vocabulary.

    • The client canopy-web:

      • confidential, standard flow only, PKCE S256 required;

      • redirect URIs each canopy-web origin’s /auth/callback, and post.logout.redirect.uris each origin’s /login;

      • default client scopes basic (sub and auth_time; never remove it, see the behaviour below), profile, and a canopy scope whose realm-role mapper writes roles and whose user-attribute mapper writes primary_programs, both multivalued, in the id_token and userinfo, never the access token.

  • Profile:

    profile: keycloak
    issuer: https://idm.example.org/realms/canopy
    client_id: canopy-web
  • MFA: in the server. The required OTP form refuses an account without an OTP credential ("credential setup required"), in the browser and by a password grant.

  • Behaviour:

    • RP-initiated logout returns to /login and ends the SSO session.

    • A refreshed id_token omits the nonce, which canopy accepts.

    • One session per browser sign-in: every token of one sign-in shares one Keycloak session, so revoking one refresh token ends the others. Revoking a device’s upstream token, which a native session holds from its step-up, also ends the web sign-in that step-up rode.

    • Keycloak has no account expiry: disable an account to end its refresh.

    • auth_time comes only from the basic client scope. Its session-note mapper is Keycloak 25+'s only source of auth_time, and of sub as well. A client without basic gets an id_token with neither, even though canopy-web asks for auth_time as an essential claim and discovery advertises claims_parameter_supported. Every sign-in then fails canopy's id_token check. The suite pins this (auth_time_comes_only_from_the_basic_scope_even_when_asked_as_essential, #3256).

ZITADEL (zitadel)

  • Version: v4.21.0, with Login V2 as the login client.

  • Checklist (AL3, AL4):

    • The login policy forces MFA, with TOTP an allowed second factor.

    • A project with projectRoleAssertion, whose roles are canopy’s role vocabulary plus program_<wire id> per program (program_snap).

    • An OIDC web application canopy-web in that project, and alone in it, so aud holds only the client and the project:

      • code flow with the refresh-token grant, client_secret_basic;

      • idTokenRoleAssertion and idTokenUserinfoAssertion on;

      • redirect URIs each canopy-web origin’s /auth/callback, and post-logout redirect URIs each origin’s /login.

    • Store the application’s client secret when it is created: ZITADEL shows it once.

    • Grant each worker its roles and programs in the organisation the profile names. A grant from another organisation counts for nothing.

    • Enrol each worker’s TOTP administratively at creation. With MFA forced, Login V2 sends an account with no second factor to set one up after its password, so whoever holds a new account’s initial password could enrol it.

    • Protect Login V2’s credential (its personal access token) as ZITADEL’s administrator credential. The core leaves factor sufficiency to its login client, so anything holding that token can finalize a sign-in without MFA.

  • Profile (the ids are strings, so quote them):

    profile: zitadel
    issuer: https://idm.example.org
    client_id: "312909075212468632"
    project_id: "312909075212402200"
    organization_id: "312909075212336664"
  • MFA: in Login V2, the trusted login client, never in ZITADEL’s core.

  • Behaviour:

    • RP-initiated logout returns to /login and ends the session, but its refresh tokens survive it. canopy-web therefore revokes the session’s refresh token at sign-out as well (#2905).

    • ZITADEL ignores max_age, in Login V2 and in the core (zitadel/zitadel#12258). A step-up whose max_age the worker’s ZITADEL session has outlived is answered from that session, with its earlier auth_time. canopy-web refuses that auth_time and retries once with prompt=login, which Login V2 honours. The worker signs in again, one redirect later than on Keycloak. The ZITADEL suite and browser spec pin this, and #2906 tracks the upstream fix. Do not rely on max_age alone in any other relying party on the same ZITADEL.

    • A TOTP code is single-use (TOTP-Auw0a).

    • A revoked refresh token, or a deactivated account’s, is refused invalid_request, and canopy ends the session on any 4xx.

    • Refresh tokens rotate. Each refresh answers a new refresh token, and the one it replaced is refused from then on: 400 invalid_request, Errors.OIDCSession.RefreshTokenInvalid. Unlike Kanidm's, a replay does not revoke the session, and the newest token still refreshes. The suite pins this (#3256). canopy-web never presents a refresh token twice (Keeping a session fresh).

    • auth_time comes unasked. ZITADEL documents it in its claims reference.

Registering canopy’s clients

At the upstream: canopy-web. Register one confidential client for canopy-web, with the redirects above. Its id is the profile’s client_id (on Kanidm the issuer’s last path segment too, /oauth2/openid/canopy-web; on ZITADEL the application’s generated client id), and its secret reaches canopy-web as CANOPY_WEB__UPSTREAM_CLIENT_SECRET, a reserved key read through the secret provider with no file fallback. No other canopy component is an upstream client. On the devstack, provisioning creates or declares the client and xtask registers its redirects at every bring-up, whichever upstream runs (Local Development › The devstack’s upstream).

At canopy-identity: the confidential clients. Fifteen confidential clients authenticate to the token endpoint with a private_key_jwt assertion (RFC 7523) signed by an ES256 key: canopy-web, canopy-portal, and the thirteen services that call another service. identity-clients.yaml registers each one’s public key, or two during a rotation, and its token-request rate (Configuration Reference › the client registry). Each client holds its private key as CANOPY_<SVC>__IDENTITY_CLIENT_PRIVATE_KEY and refuses to boot without it. canopy-cli is a native client: public, with no registry entry, its refresh credential bound to a DPoP key it holds.

Client ids, the call graph and each system token’s purpose are code, not configuration (crates/canopy-auth/src/identity_policy/). A client may mint only for a target its compiled edge names, and a receiver refuses a token whose last hop has no edge. cargo xtask call-graph check holds the compiled graph to the peer URL settings and to its generated table (Authorization Inventory › Compiled call graph).

canopy-web’s sign-in

canopy-web signs a worker in at the upstream through its relying party, has canopy-identity federate the answer into a session, and keeps that session with the upstream grant in its own database (services/canopy-web/src/auth/, web_session/).

Route Behaviour

GET /login

The sign-in page: the jurisdiction’s system-use notice (AC-8, [sign_in] system_use_notice in jurisdiction.toml) and a Continue link, or a refusal’s message.

GET /login/start

Creates a sign-in flow and redirects to the upstream. A plain navigation, as every step toward the upstream is: the CSP’s form-action 'self' blocks a redirect that follows a form submission.

GET /auth/step-up?return_to=…

Creates a step-up flow (step_up_options(), max_age 300 s) and redirects to the upstream.

GET /auth/callback

Takes the flow, completes it by kind (a sign-in, a step-up or a device approval) and answers the handoff page to the flow’s return path, never a redirect (Cross-site upstreams).

POST /logout

CSRF-checked. Ends the session row, revokes canopy-identity’s session and the upstream refresh token, then hands off to the upstream’s end-session endpoint with the id_token as its hint, or to /login, the next sign-in sending prompt=login. The revocation runs beside an end session too, since an end session need not end its refresh tokens (#2905).

A flow is a web_login_flow row, 900 s, holding the state hash, the nonce, the PKCE verifier, any max_age and the return path, and named by the __Host-canopy_login_flow cookie. The callback takes it once, with the state the upstream returned, redeems the code within 10 s (UPSTREAM_TOKEN_TIMEOUT, discovery and the key fetch included), checks the id_token and its nonce, and presents it to canopy-identity’s federation grant. A stale sign-in, auth_time_too_old, restarts the flow once with prompt=login.

A refused sign-in renders the sign-in page with one message, chosen by code (services/canopy-web/src/auth/refusal.rs):

Code Cause

no_role, missing_primary_programs, malformed_primary_programs, no_username

The projection’s refusals (The upstream profile), or canopy-web’s own admission finding no role or no scopable program. Fix the IdP’s claim mapping.

subject_suspended

A security administrator suspended the worker’s subject.

upstream_refused

The upstream refused the sign-in, or ended its grant.

auth_time_too_old

The upstream’s authentication stayed too old after the one prompt=login retry.

identity_unavailable

canopy-identity could not be reached, or answered unavailable.

user_code_invalid, approver_mismatch

A device approval’s code is not valid, or its step-up signed in as someone else (Device approval and native sessions).

sign_in_failed

Anything else: the upstream’s answer did not verify, or the flow named nothing to complete. canopy-web’s log names the failure.

Cross-site upstreams

canopy-web signs workers in through an upstream on any registrable domain: a hosted one (Login.gov, Entra ID, Okta, a state’s shared IdP) as well as one beside it (#2509). The upstream returns the browser to /auth/callback by a navigation its own page starts, which is cross-site when the upstream is on another registrable domain. A browser sends SameSite=Lax cookies on such a navigation and withholds SameSite=Strict ones, so sign-in depends on no Strict cookie:

  • The flow travels in the Lax flow cookie. __Host-canopy_login_flow is HttpOnly, SameSite=Lax, 900 s. The callback reads nothing from the session cookie. A device approval stores the approving worker’s session id in its flow for the same reason.

  • The callback answers a handoff page. A completed flow answers 200 text/html, never a redirect (services/canopy-web/src/auth/handoff.rs). The page sets the new session cookie and sends the browser on, by a <meta http-equiv="refresh"> and a Continue link, to the flow’s stored return path, validated again, or /. That navigation starts from canopy-web’s own page, so it is same-site and carries the session cookie. The page sends Cache-Control: no-store and Referrer-Policy: no-referrer.

The session cookie, __Host-canopy_session, stays SameSite=Strict: it is the CSRF control for the composition API. The e2e suite signs in through a second canopy-web on another registrable domain than the devstack’s Kanidm (Local Development › The cross-site sign-in instance).

Keeping a session fresh

A worker’s web session is canopy-identity’s federated session plus the upstream grant that keeps it fresh, one WebSessionRecord in canopy-web’s web_session row (ADR-049 Amendment 18; crates/canopy-auth/src/identity_web_session.rs). canopy-web maintains a session 120 s before canopy-identity’s fresh_until and at least every 780 s, so it is re-federated at least every 900 s. Maintenance refreshes the upstream grant, then renews canopy-identity’s session with the evidence the profile names (canopy-identity’s federation grant).

A refresh is sorted by whether the upstream may have processed it, and so spent the token, because a rotating issuer revokes the whole token family when a spent token comes back (ADR-049 Amendment 2; RefreshFailure, crates/canopy-auth/src/upstream/relying_party/session.rs):

  • Not processed keeps the session, which may take grace: the token was never presented (discovery or the token endpoint unavailable, no connection, a connect timed out at its 2 s bound), or the upstream answered 408, 425 or 429.

  • Ended ends the session, and its token is never presented again: a refusal (any other 4xx), a 200 it cannot read, a request timeout, a connection lost after it opened, a 5xx, a 3xx or any other status.

Single flight across replicas (#2224). A session’s refresh token is presented only under a claim committed in its row first, leased 60 s (CLAIM_LEASE), and a commit lands only under that claim. So across every replica a refresh token is presented at most once, and a rotating issuer never sees a replay. A claim whose lease lapsed is never cleared: the next request ends the session as refresh_lost, one sign-in rather than a replay. These guarantees assume acknowledged commits survive a failover (Deployment Guide › Worker sessions under replication).

canopy-identity’s federation grant

canopy-identity’s token endpoint serves an RFC 8693 grant by which canopy-web turns a sign-in at the upstream into a canopy web session, and keeps it fresh (ADR-049 §6, Amendment 6; the wire contract is canopy-security’s API › POST /identity/token). Without a profile the federation forms are invalid_request (federation_unconfigured); the grant itself stays served, and listed in the metadata, for the delegation mint.

  • Only canopy-web, by its own key. canopy-web authenticates with a private_key_jwt assertion signed by the key the client registry binds to canopy-web; any other authenticated client is unauthorized_client before canopy-identity looks anything up or calls the upstream.

  • The upstream is judged again. canopy-web presents the id_token it verified at sign-in; canopy-identity verifies it again under the profile, and, when the profile’s claims come from userinfo, calls userinfo with the access token canopy-web forwards, bound to the id_token’s sub. It projects the claims (The upstream profile), so the roles, programs and username a session carries are the ones the profile’s pointers read, refused with the projection’s code otherwise.

  • One canopy subject per upstream identity. The first open of an unseen pair of the profile’s exact issuer and the id_token’s sub mints a canopy subject (a UUID v7) and links the pair to it; every later open of that pair is that subject’s. A renamed IdP client that changes the issuer string therefore mints a new subject until a security administrator re-links it. A suspended subject’s open is refused (subject_suspended).

  • The session. It ends IDENTITY_WEB_SESSION_MAX_SECONDS after the upstream auth_time (default 12 h; Configuration Reference) and is fresh for 900 s from the id_token’s iat. A sign-in whose session would end within 900 s is refused auth_time_too_old, so canopy-web re-authenticates with prompt=login. The answer’s access_token is the session’s opaque credential, which canopy-identity stores only as its SHA-256; sub is the canopy subject, never the upstream’s.

  • Unavailability fails the sign-in. Unreachable discovery, keys or userinfo answer 503 temporarily_unavailable, and so does a userinfo endpoint named nowhere or refused by the client, a deployment defect logged as such. A refusal canopy-web must act on carries canopy_refusal (the projection codes, auth_time_too_old, subject_suspended, upstream_refused); upstream_refused names only the upstream’s own verdict (userinfo refused the access token, or answered invalidly), never canopy’s (ADR-049 Amendment 6). canopy-web allows the grant its whole deadline, 13 s (TOKEN_EXCHANGE_DEADLINE): a cold upstream may take three sequential 2.5 s calls before the answer.

  • Renewal. The session is fresh until its answer’s fresh_until, 900 s after the last upstream validation. canopy-web renews after each upstream refresh, and at least every 900 s, with the session’s credential and the evidence the profile’s refresh names: the refreshed id_token under reissues_id_token, or the upstream access token under userinfo. canopy-identity holds a refreshed id_token to the session’s upstream iss, sub and original auth_time, the original nonce or none, and an iat newer than the last it recorded; the same id_token again is a replay, which answers the session as it stands. A userinfo renewal is bound to the session’s upstream sub. Each recorded renewal re-projects, so the session’s roles and programs follow the upstream. A session belongs to the upstream issuer and client it opened under: a profile that names another revokes the session at its next renewal (upstream_changed), before any upstream call, and canopy-web signs the person in again.

  • Grace. When canopy-web could not process the upstream’s refresh (Keeping a session fresh), it sends upstream_outcome=not_processed in place of the evidence; canopy-identity grants the same grace when its own userinfo call or key fetch is unavailable. A grace holds the session fresh until the last successful upstream validation + 900 s + IDENTITY_SESSION_GRACE_SECONDS (default 1800, at most 3600), never past the session’s end, and a second grace before the next success ends where the first did. Each grace is recorded in the issuance log. Past that window a grace is refused grace_exhausted.

  • How canopy-web treats each renewal answer. A 200 carries the session’s terms: canopy-web keeps the credential (echoed, never rotated) and takes fresh_until, roles, programs and username from it. session_ended, upstream_refused, a projection code and subject_suspended end the session, and canopy-web signs the person in again (subject_suspended refuses that sign-in too). grace_exhausted changes nothing: the session lapses at its fresh_until, and a renewal with real evidence may still succeed. invalid_request with no canopy_refusal, or a 503, changes nothing either: canopy-web lets the session lapse at its recorded fresh_until and may renew again before then.

Device approval and native sessions

canopy-cli signs a worker in by RFC 8628’s device flow, and canopy-web approves it (ADR-049 §7, Amendment 9, Amendment 21; the wire contract is canopy-security’s API). Every route here needs an upstream profile; the two device routes need CANOPY_SECURITY__IDENTITY_DEVICE_VERIFICATION_URI too, canopy-web’s {origin}/device.

  • Code entry. canopy login prints the verification URI and a user code (XXXX-XXXX, case and separators ignored). The worker, signed in to canopy-web, enters it at /device (services/canopy-web/src/device.rs), which posts it to POST /identity/device_verification with canopy-web’s assertion and the worker’s web-session credential: action=describe answers the device’s client and times for the confirmation page, and action=deny records a denial, which canopy-cli’s polls then answer access_denied. A code no device holds, or one expired, decided or malformed, or canopy-cli disabled, is user_code_invalid; canopy-web shows one message for them all.

  • Step-up, then approval. To approve, canopy-web obtains a fresh sign-in for a dedicated upstream grant (step_up_options()) and presents its id_token, with the user code and the approving worker’s web-session credential, as the approval (requested_token_type=urn:canopy:params:oauth:token-type:native-revalidation). The issuer holds the approval to that worker (ADR-049 Amendment 21): a step-up signed in as anyone else is approver_mismatch, nothing is approved, and the device stays pending. A sign-in more than 600 s old is auth_time_too_old, so canopy-web asks again. A suspended subject is refused.

  • Attempts. Each describe, denial and approval spends one of the worker’s attempts: 10 at once and one more a minute, per replica, keyed by the worker’s upstream issuer and subject. Past it, each is a 429 with Retry-After, before the code is read; canopy-web tells the worker to wait.

  • The native session. The approval’s access_token is the revalidation credential: canopy-web keeps it with the dedicated grant, never hands it to canopy-cli, and presents it only to renew the session. canopy-cli gets its own DPoP-bound refresh credential when it redeems its device code. The session ends IDENTITY_NATIVE_SESSION_MAX_SECONDS after the step-up sign-in (default 8 h, at most 24 h).

  • Renewal and revocation. canopy-web re-federates the native session as it does a web session, from the dedicated grant’s refreshes, at least every 900 s (NativeSessions::sweep, every 30 s). A native session past its freshness mints nothing for canopy-cli (session_stale) until canopy-web renews it. A worker revokes a device at /device/sessions; canopy-cli’s canopy logout revokes the session by its refresh credential. A session canopy-cli never redeemed before its device code expired is revoked at its next renewal.

  • canopy-cli’s side (canopy_auth::DeviceClient, ADR-049 Amendment 23). canopy login polls per RFC 8628 until the worker decides, then stores the session in the profile’s owner-only device store; canopy token <SERVICE> prints a token for one service, refreshing under the store’s lock so concurrent invocations never present one credential twice; canopy logout revokes and removes the session. A profile names its issuer (identity_issuer, the public issuer), and a session stored under another issuer answers LoginRequired, so a moved issuer asks for canopy login again (canopy CLI Reference).

Gating a deploy: canopy-manage identity check

canopy-manage identity check --issuer <identifier> --internal <url> [--client <id>] is canopy-identity’s deploy gate (ADR-049 Amendment 23; tools/canopy-manage/src/identity_check.rs). It ships in the service image (canopy-manage Reference). It runs three checks against the internal URL, in order, and a failure names its check:

  1. metadata — the RFC 8414 document names the issuer identifier exactly and names the token, revocation and JWKS endpoints, and those three, with the device authorization endpoint when served, lie under the issuer identifier (the same origin, a path below it); other members are not read;

  2. keys — the JWKS holds at least one ES256 P-256 signing key whose kid is its RFC 7638 thumbprint;

  3. mint — one client-credentials grant by --client (default canopy-eligibility) for its first compiled purpose validates at that purpose’s receiver as a receiver validates it, and the principal is a system token naming that client, that purpose and exactly the purpose’s scopes.

A client with no compiled purpose is refused before anything is sent, and the grant is the gate’s only side effect, so it is safe against production. The client’s key is read through the audited secret provider from CANOPY_<SERVICE>__IDENTITY_CLIENT_PRIVATE_KEY (client_key_secret). There is no other source: the gate signs as that service, so run it where the service’s key already is, and an unset variable is refused by name. Both URLs must be https; http is admitted only when CANOPY_ENV=development, the rule a service’s own boot applies to the same two settings.

The upstream itself is checked by its conformance suite, all three by cargo xtask identity matrix before an identity push and on a release tag (Local Development › the identity matrix). canopy-web’s sign-in is checked by the e2e suite’s real redirect chain through each upstream’s own pages (Testing › The identity-plane project).

Keys and rotation

  • canopy-identity’s signing keys are per replica, held in memory only, and rotate on their own; receivers refresh the published set every 300 s, refetch on an unknown kid, and fail closed once their set is 720 s stale. Procedures, emergency revocation included: Security Operations › canopy-identity signing keys.

  • Client keys rotate by registering a second key: Security Operations › canopy-identity client keys.

  • The upstream’s keys need no canopy action. canopy-identity and canopy-web refetch the upstream’s keys on an unknown kid and every 300 s, and a key the IdP removes stops verifying within 720 s (The upstream profile).

  • canopy-web’s upstream client secret rotates at the upstream first, then reaches canopy-web as CANOPY_WEB__UPSTREAM_CLIENT_SECRET with a rolling restart (Secret Management).

Troubleshooting

Symptom Likely cause

A service refuses to boot naming IDENTITY_ISSUER or IDENTITY_INTERNAL_URL

The setting is missing, not https outside development, has another path than /identity, or is not in canonical form; the error names the canonical spelling.

A service refuses to boot naming CANOPY_<SVC>__IDENTITY_CLIENT_PRIVATE_KEY

The client key is unset, blank, or not an unencrypted PKCS#8 P-256 PEM. No file stands in, in any environment.

canopy-web refuses to boot naming the upstream profile, its trust anchors or CANOPY_WEB__UPSTREAM_CLIENT_SECRET

identity-upstream.yaml is absent or defective under the config root, its tls_trust_anchors file does not load, or the secret is unset (The upstream profile).

The sign-in redirect lands on a 404 or an unreachable host

The upstream’s authorization_endpoint, from discovery or the profile, is not reachable from the worker’s browser.

The upstream answers the authorization request with a redirect-URI error

{CANOPY_WEB__PUBLIC_ORIGIN}/auth/callback is not registered for canopy-web’s client, exactly (What an upstream must deliver).

Sign-in ends on no_role, missing_primary_programs, malformed_primary_programs or no_username

The IdP’s claim mapping: only vocabulary role names survive projection, programs must be wire ids, and the pointers must address where the IdP puts them (The upstream profile).

Sign-in ends on auth_time_too_old

The upstream ignored prompt=login, or its clock and canopy’s disagree.

Sign-in ends on sign_in_failed

The id_token did not verify: an issuer string that differs from the profile’s, an aud other than the client id, an algorithm outside the profile’s, a missing auth_time, or a nonce that is not the flow’s. canopy-web’s log names the rule.

canopy-web’s federation is answered federation_unconfigured

canopy-security has no upstream profile mounted at its config root.

A service’s calls fail with the token endpoint’s invalid_client

No registered key matches the client’s assertion kid, the client is disabled in the registry or at runtime (client_disabled), or the assertion was replayed. canopy-security’s issuance log names the reason.

Receivers answer 401 token_rejected or 503 keys_unavailable

Receivers refusing canopy-identity tokens.

A step-up on ZITADEL shows Login V2’s sign-in after an extra redirect

ZITADEL ignored the step-up’s max_age (ZITADEL (zitadel), #2906), and canopy-web retried with prompt=login: expected, not a fault.

Sign-out continues to /login instead of the IdP’s logout page

The upstream advertises no end_session_endpoint (Kanidm, some Okta plans). canopy-web ends its own session, revokes the upstream refresh token when revocation_endpoint is advertised, and sends prompt=login on the next sign-in: the documented fallback, not a bug.

Sign-out answers 403 CSRF token invalid

The page’s sign-out form carries a CSRF token that is no longer the session’s: the page was rendered before the worker signed in again in another tab. Reload the page and sign out again.

Implementation references

  • crates/canopy-auth/src/upstream/ — the upstream profile (profile.rs), its id_token validator (id_token.rs), userinfo, the projection (projection.rs), the key source and canopy-web’s relying party (relying_party.rs).

  • crates/canopy-auth/src/identity_web_session/ — canopy-web’s session engine and its store contract; crates/canopy-auth/src/identity_client/federation.rs — the federation client.

  • services/canopy-web/src/auth/ — the sign-in routes, the handoff page and the refusal codes; services/canopy-web/src/web_session/ — the session store; services/canopy-web/src/device.rs — device approval.

  • services/canopy-security/src/identity/token_endpoint.rs and token_endpoint/federation.rs — the token endpoint, its metadata and the federation grant.

  • crates/canopy-auth/src/identity_edge.rs — canopy-web’s edge forwarder; crates/canopy-auth/src/identity_url.rs — the issuer’s mount rules.

  • crates/canopy-auth/src/identity_policy/ — the compiled clients, call graph and purposes.

  • tools/canopy-manage/src/identity_check.rs — identity check (Gating a deploy: canopy-manage identity check); xtask/src/cmd/identity/conformance.rs and matrix.rs — the conformance runs and the identity matrix.

  • crates/canopy-test-lib/src/upstream/ — each supported upstream’s provisioning and headless sign-in; crates/canopy-test-lib/tests/idp_conformance_*.rs — the conformance suites.

Edit this page · default