Identity plane split, plan I3e1: canopy-web’s upstream relying party (epic &133)

Status: Done (2026-10-09) — !1587
Epic: &133 (stage I3 of &130)
Issues: #2813 (U1, w2); #2814 (U2, w3); #2815 (U3, w5); #2816 (U4, w3); #2817 (U5, w2). Each relates to #2344 and #2345, which close when canopy-web’s sign-in moves to this library at the switch.
MR: feat/identity-relying-party, "canopy-web’s upstream relying party (#2813 … #2817)".

One MR, one commit per issue, under the maintainer’s one-MR-per-related-group ruling. It merges once the pre-push battery passes. This is a Design + Scope plan: GitLab owns tracking, and the plan freezes when U1 starts. W1–W7 are this plan’s decisions (ADR-049 Amendment 17); R1 and R2 are the maintainer’s rulings.

Context

I3a’s stage list gives I3e all of canopy-web’s cut-over: * the confidential upstream client with a nonce (#2344); * federation and re-federation; * the refresh lead (#2345); * delegation for every backend call; * the panel cache (#2647); * logout, AC-8 and step-up; * device approval and the security-admin UI; * edge forwarding.

That is far beyond one plan.

The maintainer’s rulings (2026-10-09): * R1. Split I3e into sequential sub-plans, each planned when its predecessor lands; this is the first. * R2. The architecturally correct staging, with no shortcuts, no backward compatibility and no fig leaves. Protocol code is library code in canopy-auth, wherever it lands, proven now against the devstack’s identity plane as I3c and I3d were. That covers the upstream relying party, canopy-web’s sender, the device-approval and admin clients, and the edge forwarder. canopy-web’s own integration replaces its Keycloak path; it is not an addition. That covers its session store, extractors, handlers, pages, AC-8, step-up, logout, forwarding mount and panel-cache key. It lands with the switch, which deletes that path. ** So canopy-web holds no dormant module, no pub-for-dead_code code, no devstack-only mount and no preparatory migration. The switch replaces its schema outright.

What exists: * canopy-auth’s upstream module (plan I2b): UpstreamProfile (C1–C3: issuer, client id, client_auth_method, claims source, RefreshRenewal, TLS anchors); UpstreamHttpClient (C4: 2 s connect, 2.5 s request, no redirects, GET only); UpstreamKeySource (C5, C6: discovery and JWKS fetched lazily, with userinfo_endpoint()); UpstreamIdTokenValidator (C7: VerifiedUpstreamIdToken::anchor() gives nonce() and auth_time() for canopy-web to judge). * canopy_auth::ServiceCredentials (introspection.rs, the RFC 6749 §2.3.1 encoder, #2427).

What is missing: * Discovery reads only jwks_uri and userinfo_endpoint. * No POST. * No authorization request, code exchange, nonce check, refresh, revocation or end-session. * The profile names no scopes, but Kanidm emits canopy’s role and program claims only under profile.

canopy-web today: * Its hand-rolled client is public: no secret, no nonce, no id_token validation (#2344, services/canopy-web/src/auth/mod.rs). * Its token client allows 2 s to connect and 10 s in total (#2535). * Its refresh outcomes are GrantOutcome (Amendment 2, services/canopy-web/src/auth/refresh.rs). * Its 360 s refresh lead is sized to the Keycloak exchanger (#2345, session.rs).

The devstack’s Kanidm (verified 2026-10-09) advertises authorization_endpoint …/ui/oauth2 (a browser page), token_endpoint …/oauth2/token and revocation_endpoint …/oauth2/token/revoke. It has no end_session_endpoint, supports S256 only, and offers client_secret_basic/client_secret_post.

Decisions (ADR-049 Amendment 17, W1–W7; land with U1)

  • W1. Staging (R2). Amendment 11 is re-cut as it allows.

    • The I3e plans are canopy-auth library stages: this relying party, then canopy-web’s sender and session engine, then the device-approval and security-admin clients, then the edge forwarder. Later plans may re-cut these.

    • canopy-web’s integration lands with the switch, replacing its Keycloak path. That includes reading the profile and the secret at boot, and documenting the secret in configuration-reference.adoc.

  • W2. The relying party’s endpoints. The profile gains four optional overrides, authorization_endpoint, token_endpoint, revocation_endpoint and end_session_endpoint. They are held to the same endpoint rule as jwks_uri, and each one named wins over discovery, as the existing overrides do (configuration-reference › Endpoints on another origin). That keeps a provider whose endpoints sit off the issuer’s origin usable.

    • Lenient reading: discovery reads the four members in a separate, lenient pass, never in WireDiscovery, so no value of theirs ever refuses the document or canopy-security’s key fetch.

    • Judged on request: each is judged only when UpstreamKeySource::endpoints(request_start: SystemTime) → Result<UpstreamEndpoints, UpstreamKeysUnavailable> is asked. The result is the override when named; otherwise absent, or a string that passes the endpoint rule and sits on the issuer’s origin; otherwise an EndpointFault (null, not a string, repeated, failing the rule, off-origin).

    • Shape: UpstreamEndpoints { authorization, token, revocation, end_session }, each a Result<Option<Url>, EndpointFault>; a fault fails closed in the relying party (EndpointRefused).

  • W3. Form posts. UpstreamHttpClient::post_form(&self, url: &Url, form: &[(&str, &str)], auth: ClientAuth<'_>, timeout: Duration) → Result<UpstreamResponse, UpstreamRequestError>.

    • It keeps the client’s 2 s connect bound, redirect refusal and TLS anchors; timeout replaces the 2.5 s request bound for this call.

    • ClientAuth::{Basic(&ServiceCredentials), Post(&ServiceCredentials)} follows the profile’s method. Basic sends ServiceCredentials::authenticate; Post adds client_id and client_secret to the form, through a new ServiceCredentials::client_secret_for_body() → &str.

  • W4. Scopes. The profile gains scopes: UpstreamScopes, a YAML list of RFC 6749 scope tokens: non-empty, holding openid, with no duplicates and no malformed token.

    • The request sends them space-joined.

    • The kanidm preset is [openid, profile], and a kanidm file stating scopes is refused (C2); oidc-generic must state it.

    • canopy-security parses and ignores it (C1: both readers parse one file).

  • W5. The relying party, canopy_auth::upstream::relying_party (types below). It is canopy-web’s client of the one upstream (D1, D6). Its operations:

    Operation What it does

    UpstreamRelyingParty::new(&UpstreamProfile, UpstreamHttpClient, UpstreamClientSecret, development: bool) → Self

    No I/O. It holds an UpstreamKeySource and an UpstreamIdTokenValidator built from the profile.

    authorization(&self, redirect_uri: &Url, options: &AuthorizationOptions) → Result<(Url, PendingAuthorization), RelyingPartyError>

    The discovered authorization_endpoint with response_type=code, client_id, redirect_uri, the profile’s scope, a fresh 256-bit base64url state and nonce, an S256 code_challenge over a fresh 43-character verifier, claims={"id_token":{"auth_time":{"essential":true}}} on every request (OIDC Core §5.5; a provider sends auth_time only when asked, §2, and C7 requires it, I2b), and prompt=login and max_age only when options asks (D6, F4, Amendment 8 H2, Amendment 9 N3).

    redeem(&self, pending: PendingAuthorization, returned_state: &str, code: &str, redirect_uri: &Url) → Result<UpstreamGrant, RelyingPartyError>

    One deadline, UPSTREAM_TOKEN_TIMEOUT (10 s, today’s canopy-web bound, #2535), covers discovery, the grant and the id_token’s key fetch (Deadline). In order: returned_state equals the pending state in constant time, before any request; the authorization_code grant with the verifier, as W3; the answer is held to RFC 6749 §5.1 and must carry an id_token, validated by UpstreamIdTokenValidator at Utc::now() (D14); its nonce is present and equal in constant time (#2344); with max_age asked, auth_time is within max_age plus C7’s 60 s leeway (id_token.rs's LEEWAY_SECS, made pub(crate)). canopy-identity re-validates the id_token at federation (C7); canopy-web alone checks the nonce (D5).

    refresh(&self, token: &UpstreamRefreshToken, within: Duration) → Result<UpstreamGrant, RefreshFailure>

    One deadline, the lesser of within (the caller’s remaining budget) and UPSTREAM_TOKEN_TIMEOUT, covers discovery and the refresh_token grant (W3, given what remains). Discovery unfinished at the deadline is NotProcessed, since the token was never presented. The 2 s connect bound stays below the remainder, so a stalled connect is a connect timeout (Amendment 2). Under ReissuesIdToken the answer must carry an id_token, which is not validated here: canopy-identity judges it at renewal (F5), and canopy-web reads nothing from it.

    revoke(&self, token: &UpstreamRefreshToken) → Result<(), RelyingPartyError>

    Within one UPSTREAM_LOGOUT_TIMEOUT (2 s, today’s sign-out bound, services/canopy-web/src/auth/revoke.rs) covering discovery: RFC 7009 at the revocation_endpoint, token_type_hint=refresh_token, authenticated as W3 (Kanidm accepts Basic though it advertises none). A 200 is success; none advertised is EndpointNotAdvertised(Revocation).

    end_session(&self, id_token_hint: Option<&str>, post_logout_redirect_uri: &Url) → Result<Option<Url>, RelyingPartyError>

    Within UPSTREAM_LOGOUT_TIMEOUT covering discovery: the end_session_endpoint with post_logout_redirect_uri, client_id and, when given, id_token_hint (RP-Initiated Logout §2). canopy-web omits the hint without a live, CSRF-checked session, so the issuer asks the user to confirm (services/canopy-web/src/auth/mod.rs). With no endpoint, None, and D6 has canopy-web revoke and send prompt=login next.

    The types: UpstreamClientSecret: from_secrets(&dyn SecretProvider) → Result<Self, ClientSecretError> reads CANOPY_WEB__UPSTREAM_CLIENT_SECRET (UPSTREAM_CLIENT_SECRET), with no file fallback; unset is Missing, blank is Blank, a provider failure is Unreadable. AuthorizationOptions { prompt_login: bool, max_age: Option<Duration> }. PendingAuthorization: the state, nonce and verifier, and max_age, for canopy-web’s flow store (a Postgres row any replica reads). * expose_for_store(&self) → StoredAuthorization<'_> gives &str views and max_age. * PendingAuthorization::restore(state, nonce, verifier: Zeroizing<String>, max_age) → Result<Self, MalformedAuthorization> checks each value’s length and base64url alphabet. * The raw state is kept: redeem compares it itself. UpstreamRefreshToken: restore(Zeroizing<String>) → Result<Self, MalformedRefreshToken> (1–8192 bytes) and expose_for_store(&self) → &str. UpstreamGrant: * id_token() → Option<&str>: always Some from redeem, and from refresh under ReissuesIdToken; * access_token() → &str; * take_refresh_token() → Option<UpstreamRefreshToken>; * expires_in() → Duration; * received_at() → DateTime<Utc>; * verified() → Option<&VerifiedUpstreamIdToken>, Some from redeem; * refresh_due() (W6).

    + These are what FederationClient::open(id_token, upstream_access_token) and RenewalEvidence::{IdToken, UpstreamAccessToken} take.

    • RelyingPartyError:

      • DiscoveryUnavailable;

      • Deadline;

      • EndpointNotAdvertised(Endpoint) and EndpointRefused(Endpoint, EndpointFault), where Endpoint is Authorization, Token, Revocation or EndSession;

      • StateMismatch;

      • Request(UpstreamRequestError);

      • Refused { status: u16, error: OAuthErrorCode } (RFC 6749 §5.2’s codes, any other Unrecognized, never kept);

      • Malformed(AnswerDefect): body, token_type, expires_in missing or zero, an id_token too large;

      • NoIdToken;

      • IdToken(UpstreamIdTokenError);

      • NonceMissing, NonceMismatch, AuthTimeTooOld.

    • RefreshFailure, Amendment 2’s partition, named as today’s GrantOutcome:

      • NotProcessed(NotProcessedReason): the token was never presented, so it grants grace. The reasons are discovery unavailable or unfinished at the deadline, the token endpoint not advertised or refused, UrlRefused/Connect/Tls/ConnectTimeout, or a 408, 425 or 429.

      • Ended(EndReason): never present the token again. EndReason is Refused { status, error } (any other 4xx), AcceptedUnreadable(AnswerDefect) (a 2xx it cannot read, or missing a required id_token or expires_in), or Ambiguous (Timeout, ConnectionLost, any 5xx, a 3xx, any other status).

    • No Debug leak: UpstreamClientSecret, PendingAuthorization, UpstreamRefreshToken and UpstreamGrant have no Debug, Display, Serialize or Clone, held by compile-time probes (crates/canopy-auth/src/identity_client/delegation/tests.rs's, crate-visible since plan I3d). No error carries a token, code, secret, verifier, state or nonce.

  • W6. The refresh lead (#2345). UpstreamGrant::refresh_due() → RefreshDue, derived from the grant’s own lifetime, expires_in.

    • RefreshDue::At(DateTime<Utc>) = received_at + lifetime − lead, the lead a quarter of the lifetime clamped to [MIN_REFRESH_LEAD, MAX_REFRESH_LEAD] = [30 s, 300 s].

    • RefreshDue::ShortLived { lifetime } when the lifetime is at most MIN_REFRESH_LEAD: a named condition the caller logs once, never a refresh storm. So At is always strictly after received_at.

    • The session engine (a later I3e plan) takes the earlier of this and canopy-identity’s fresh_until lead (D6, F4).

  • W7. The devstack redirect. The proof reads the code from Kanidm’s redirect without following it, at the registered https://web.canopy.test/auth/callback, as the broker does (K7). The browser-reachable redirect for canopy-web’s sign-in is the switch’s.

Units

Erratum (2026-10-09): U2’s fetch-level test sets discovery’s body directly, so mock_issuer.rs's Advertised needed no new members. W5’s Refused carries the existing TokenEndpointError (RFC 6749 §5.2 and RFC 8707’s codes, any other Unrecognized) in place of a new OAuthErrorCode. AnswerDefect gains MissingIdToken for a reissuing profile’s refresh. The relying party’s AnswerDefect and Endpoint stay under canopy_auth::upstream, since the crate root’s AnswerDefect is the delegation sender’s.

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

  1. U1 (w2) docs(adr): record canopy-web’s upstream relying party.

    • ADR-049 Amendment 17 (R1, R2, W1–W7), plus the Status line.

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

  2. U2 (w3) feat(auth): discover the upstream’s endpoints and post forms (W2–W4).

    • canopy-auth:

      • upstream/keys.rs: the lenient read of the four members, UpstreamEndpoints, EndpointFault, endpoints();

      • upstream/client.rs: post_form, ClientAuth;

      • introspection.rs: client_secret_for_body;

      • upstream/profile.rs: the four endpoint overrides; UpstreamScopes, the preset, the oidc-generic requirement;

      • re-exports in upstream.rs and lib.rs.

    • Fixtures: every oidc-generic profile gains scopes. That covers canopy-auth’s id_token, keys and projection tests, canopy-test-lib’s tests and mock_issuer.rs (Advertised and its advertise_* builders gain the four members), and canopy-security’s tests/identity_federation_test.rs.

    • Tests:

      • each endpoint absent, present, off-origin, repeated and null, each fault refusing only endpoints()'s member, never the key fetch; an override winning over an off-origin discovered endpoint. In crates/canopy-test-lib/tests/upstream_keys_test.rs, where discovery’s fetched tests live;

      • Basic and Post requests read back whole (head and body) by a new loopback in client/tests.rs; no redirect followed; timeout replacing the request bound;

      • scopes: preset, generic stated, missing, without openid, duplicate, malformed, and stated on kanidm;

      • proptests: no panic on any scopes value, and any valid set round-trips through its space-joined form.

    • Docs:

      • shared-crates.adoc;

      • configuration-reference.adoc (the profile’s scopes and the four endpoint overrides);

      • CHANGELOG.adoc Changed: oidc-generic profiles must state scopes.

  3. U3 (w5) feat(auth): authorize and redeem as canopy-web’s relying party (W5’s secret, options, pending, grant, authorization, redeem; #2344).

    • New module: upstream/relying_party.rs (+ tests.rs), with a scripted loopback IdP (discovery, JWKS, token endpoint minting ES256 id_tokens). It is built from the id_token tests' signing helpers, made pub(crate).

    • Tests:

      • the authorization URL’s parameters: each once; the essential auth_time claim on every request; prompt and max_age only when asked;

      • a scripted provider that omits auth_time unless asked still redeems, because it is asked;

      • fresh state/nonce/verifier per call;

      • S256 against RFC 7636 Appendix B’s vector;

      • restore round-trips expose_for_store, and refuses malformed values;

      • a mismatched state sends nothing;

      • a stalled endpoint ends redemption at its deadline (Deadline);

      • the code exchange’s form under both client-auth methods;

      • each RelyingPartyError the redemption names: no id_token, a forged one (wrong key, wrong aud), NonceMissing, NonceMismatch, AuthTimeTooOld, Refused with a known and an unrecognized code, Malformed;

      • the secret’s Missing, Blank and Unreadable;

      • the probes;

      • a proptest: no panic on any token-endpoint body.

    • Docs: shared-crates.adoc.

  4. U4 (w3) feat(auth): refresh, revoke and end sessions upstream (W5’s refresh, revoke, end_session; W6; #2345).

    • Tests:

      • each UpstreamRequestError variant, discovery unavailable, a missing token endpoint, and 408/425/429 against other statuses, each in its class;

      • within under the connect bound, which turns a stalled connect into Ambiguous;

      • discovery stalled past within → NotProcessed, with nothing posted;

      • ReissuesIdToken without an id_token → AcceptedUnreadable; Userinfo without one → granted;

      • revocation’s form, and EndpointNotAdvertised(Revocation);

      • end_session's URL with and without the hint, and None;

      • refresh_due's bounds (30 s exactly is ShortLived), plus a proptest over lifetimes and receipt times: At is strictly after receipt and never later than expiry less MIN_REFRESH_LEAD, and ShortLived holds exactly at or under the floor;

      • a proptest: no panic on any refresh body.

    • Docs: shared-crates.adoc; idp-integration.adoc's refresh-outcomes table names the library’s classes beside GrantOutcome.

  5. U5 (w2) test(auth): prove the relying party against devstack Kanidm.

    • canopy-test-lib:

      • the Kanidm driver gains authorise_query(&self, uat: &Secret, query: &str) → Result<Authorization, KanidmError>, which replays a relying party’s authorization query at /oauth2/authorise with the UAT, as a browser does at the UI page;

      • TokenBroker gains upstream_sign_in(&self, person: &str) → Result<Secret, BrokerError>, a UAT obtained under the broker’s per-person sign-in spacing (identity_broker/cache.rs), so no TOTP code is used twice.

    • The test file: crates/canopy-test-lib/tests/upstream_relying_party_test.rs.

      • It skips only when infrastructure_available() is false, which the battery refuses.

      • Its relying party is built from a profile written from Kanidm’s Credentials and kanidm_ca, as idp_conformance_kanidm.rs's write_profile does, through UpstreamHttpClient::resolving(.., "idm.canopy.test", kanidm_addr), with the client secret from those credentials.

    • The tests, with jane.doe:

      • sign-in: authorization → driver → redeem validates the id_token and its nonce, and the grant’s id_token opens a canopy-identity session through a FederationClient keyed as canopy-web from the devstack’s key, as the broker builds one;

      • refresh, once past the opening id_token’s iat second (a 1.1 s wait, as idp_conformance_kanidm.rs does), returns a grant whose id_token renews that session (RenewalEvidence::IdToken), and the renewal’s fresh_until is later than the open’s: a real renewal, not a replay;

      • after revoke, refreshing is Ended;

      • end_session is None on Kanidm;

      • a wrong state is refused.

    • Close:

      • CHANGELOG.adoc Added;

      • Amendment 17’s as-built record;

      • the plan Done and archived;

      • plan-lint --done with --allow-open for U1–U5, #2344 and #2345;

      • after merge, comment on #2344 and #2345 (they close at the switch) and update the epic.

Scope

In: discovery’s endpoints, form posts, the profile’s scopes, the relying party (authorize, redeem, refresh, revoke, end-session), the refresh lead, the devstack proof.

Out: * The switch: canopy-web’s flow store, callback, session store, extractors, logout, the browser-reachable Kanidm redirect, reading the profile and the secret at boot. * Later I3e plans: the session engine and canopy-web’s sender, the device-approval and admin clients, the edge forwarder. * #2521: encrypting session grants at rest, including the stored authorization and refresh token.

Risks

  • Kanidm and the claims parameter. Kanidm always sends auth_time (I2b). U5 proves it accepts the essential-claim request; if it refused the parameter, that would be an erratum, sending claims only to providers that need it.

  • A lost refresh answer ends the session. Amendment 2 accepts this; W5 moves the classifier into the library unchanged.

  • The code exchange keeps canopy-web’s 10 s bound rather than the shared client’s 2.5 s, since an upstream’s token endpoint answers a human sign-in, not a hot path.

Verification

  • Per unit: fmt; clippy with validate’s flags; quality-budgets, plan-lint, check-docs and private rustdoc.

  • nextest:

    • canopy-auth (U2–U4);

    • canopy-test-lib’s and canopy-security’s affected tests (U2’s fixtures);

    • cargo xtask test --integration --host -p canopy-test-lib (U2, U5).

  • Per MR: the pre-push battery.

Review log

Round Vendor Resolved model Verdict

1

Anthropic

Claude Opus 5.5 (fresh subagent)

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

  • B1 U5’s subject over 72 characters;

  • B2 no CHANGELOG Changed for the scopes requirement and the discovery refusal;

  • B3 no proptests for the new parsers;

  • B4 PendingAuthorization could not round-trip the flow store, and max_age was lost;

  • B5 a refresh that never left the process was Ended;

  • B6 undefined types and errors;

  • B7 U5’s profile input did not exist, and its sign-in skipped the broker’s TOTP spacing.

  • Notes folded in: U2’s and U3’s file lists; the per-call timeout; ServiceCredentials' home; oidc-generic; Amendment 9’s N3; revocation’s auth; the secret’s docs at the switch; the probes; Google’s origins.

2

not stated (the maintainer’s other vendor)

not stated

6 findings (P2), fixed in-plan:

  • the essential auth_time claim on every authorization;

  • endpoint overrides plus lenient, on-request judgment, so off-origin providers stay usable and canopy-security’s fetch is untouched;

  • one deadline covering discovery and the grant, with NotProcessed before sending;

  • an optional id_token_hint;

  • ShortLived at exactly 30 s;

  • U5 waits past the open’s iat and asserts fresh_until advances.

The maintainer shipped after round 2 (2026-10-09).

Edit this page · default