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_endpointandend_session_endpoint. They are held to the same endpoint rule asjwks_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 anEndpointFault(null, not a string, repeated, failing the rule, off-origin). -
Shape:
UpstreamEndpoints { authorization, token, revocation, end_session }, each aResult<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;
timeoutreplaces the 2.5 s request bound for this call. -
ClientAuth::{Basic(&ServiceCredentials), Post(&ServiceCredentials)}follows the profile’s method. Basic sendsServiceCredentials::authenticate; Post addsclient_idandclient_secretto the form, through a newServiceCredentials::client_secret_for_body() → &str.
-
-
W4. Scopes. The profile gains
scopes: UpstreamScopes, a YAML list of RFC 6749 scope tokens: non-empty, holdingopenid, with no duplicates and no malformed token.-
The request sends them space-joined.
-
The
kanidmpreset is[openid, profile], and akanidmfile statingscopesis refused (C2);oidc-genericmust 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) → SelfNo I/O. It holds an
UpstreamKeySourceand anUpstreamIdTokenValidatorbuilt from the profile.authorization(&self, redirect_uri: &Url, options: &AuthorizationOptions) → Result<(Url, PendingAuthorization), RelyingPartyError>The discovered
authorization_endpointwithresponse_type=code,client_id,redirect_uri, the profile’sscope, a fresh 256-bit base64urlstateandnonce, an S256code_challengeover a fresh 43-character verifier,claims={"id_token":{"auth_time":{"essential":true}}}on every request (OIDC Core §5.5; a provider sendsauth_timeonly when asked, §2, and C7 requires it, I2b), andprompt=loginandmax_ageonly whenoptionsasks (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_stateequals the pendingstatein constant time, before any request; theauthorization_codegrant with the verifier, as W3; the answer is held to RFC 6749 §5.1 and must carry anid_token, validated byUpstreamIdTokenValidatoratUtc::now()(D14); itsnonceis present and equal in constant time (#2344); withmax_ageasked,auth_timeis withinmax_ageplus C7’s 60 s leeway (id_token.rs'sLEEWAY_SECS, madepub(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) andUPSTREAM_TOKEN_TIMEOUT, covers discovery and therefresh_tokengrant (W3, given what remains). Discovery unfinished at the deadline isNotProcessed, 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). UnderReissuesIdTokenthe answer must carry anid_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 therevocation_endpoint,token_type_hint=refresh_token, authenticated as W3 (Kanidm accepts Basic though it advertisesnone). A 200 is success; none advertised isEndpointNotAdvertised(Revocation).end_session(&self, id_token_hint: Option<&str>, post_logout_redirect_uri: &Url) → Result<Option<Url>, RelyingPartyError>Within
UPSTREAM_LOGOUT_TIMEOUTcovering discovery: theend_session_endpointwithpost_logout_redirect_uri,client_idand, 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 sendprompt=loginnext.The types:
UpstreamClientSecret:from_secrets(&dyn SecretProvider) → Result<Self, ClientSecretError>readsCANOPY_WEB__UPSTREAM_CLIENT_SECRET(UPSTREAM_CLIENT_SECRET), with no file fallback; unset isMissing, blank isBlank, a provider failure isUnreadable.AuthorizationOptions { prompt_login: bool, max_age: Option<Duration> }.PendingAuthorization: thestate,nonceand verifier, andmax_age, for canopy-web’s flow store (a Postgres row any replica reads). *expose_for_store(&self) → StoredAuthorization<'_>gives&strviews andmax_age. *PendingAuthorization::restore(state, nonce, verifier: Zeroizing<String>, max_age) → Result<Self, MalformedAuthorization>checks each value’s length and base64url alphabet. * The rawstateis kept:redeemcompares it itself.UpstreamRefreshToken:restore(Zeroizing<String>) → Result<Self, MalformedRefreshToken>(1–8192 bytes) andexpose_for_store(&self) → &str.UpstreamGrant: *id_token() → Option<&str>: alwaysSomefromredeem, and fromrefreshunderReissuesIdToken; *access_token() → &str; *take_refresh_token() → Option<UpstreamRefreshToken>; *expires_in() → Duration; *received_at() → DateTime<Utc>; *verified() → Option<&VerifiedUpstreamIdToken>,Somefromredeem; *refresh_due()(W6).+ These are what
FederationClient::open(id_token, upstream_access_token)andRenewalEvidence::{IdToken, UpstreamAccessToken}take.-
RelyingPartyError:-
DiscoveryUnavailable; -
Deadline; -
EndpointNotAdvertised(Endpoint)andEndpointRefused(Endpoint, EndpointFault), whereEndpointisAuthorization,Token,RevocationorEndSession; -
StateMismatch; -
Request(UpstreamRequestError); -
Refused { status: u16, error: OAuthErrorCode }(RFC 6749 §5.2’s codes, any otherUnrecognized, never kept); -
Malformed(AnswerDefect): body,token_type,expires_inmissing or zero, anid_tokentoo large; -
NoIdToken; -
IdToken(UpstreamIdTokenError); -
NonceMissing,NonceMismatch,AuthTimeTooOld.
-
-
RefreshFailure, Amendment 2’s partition, named as today’sGrantOutcome:-
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.EndReasonisRefused { status, error }(any other 4xx),AcceptedUnreadable(AnswerDefect)(a 2xx it cannot read, or missing a requiredid_tokenorexpires_in), orAmbiguous(Timeout,ConnectionLost, any 5xx, a 3xx, any other status).
-
-
No
Debugleak:UpstreamClientSecret,PendingAuthorization,UpstreamRefreshTokenandUpstreamGranthave noDebug,Display,SerializeorClone, 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,stateornonce.
-
-
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 mostMIN_REFRESH_LEAD: a named condition the caller logs once, never a refresh storm. SoAtis always strictly afterreceived_at. -
The session engine (a later I3e plan) takes the earlier of this and canopy-identity’s
fresh_untillead (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)`.
-
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.
-
-
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, theoidc-genericrequirement; -
re-exports in
upstream.rsandlib.rs.
-
-
Fixtures: every
oidc-genericprofile gainsscopes. That covers canopy-auth’s id_token, keys and projection tests, canopy-test-lib’s tests andmock_issuer.rs(Advertisedand itsadvertise_*builders gain the four members), and canopy-security’stests/identity_federation_test.rs. -
Tests:
-
each endpoint absent, present, off-origin, repeated and
null, each fault refusing onlyendpoints()'s member, never the key fetch; an override winning over an off-origin discovered endpoint. Incrates/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;timeoutreplacing the request bound; -
scopes: preset, generic stated, missing, withoutopenid, duplicate, malformed, and stated onkanidm; -
proptests: no panic on any
scopesvalue, and any valid set round-trips through its space-joined form.
-
-
Docs:
-
shared-crates.adoc; -
configuration-reference.adoc(the profile’sscopesand the four endpoint overrides); -
CHANGELOG.adocChanged:oidc-genericprofiles must statescopes.
-
-
-
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, madepub(crate). -
Tests:
-
the authorization URL’s parameters: each once; the essential
auth_timeclaim on every request;promptandmax_ageonly when asked; -
a scripted provider that omits
auth_timeunless asked still redeems, because it is asked; -
fresh
state/nonce/verifier per call; -
S256 against RFC 7636 Appendix B’s vector;
-
restoreround-tripsexpose_for_store, and refuses malformed values; -
a mismatched
statesends nothing; -
a stalled endpoint ends redemption at its deadline (
Deadline); -
the code exchange’s form under both client-auth methods;
-
each
RelyingPartyErrorthe redemption names: noid_token, a forged one (wrong key, wrongaud),NonceMissing,NonceMismatch,AuthTimeTooOld,Refusedwith a known and an unrecognized code,Malformed; -
the secret’s
Missing,BlankandUnreadable; -
the probes;
-
a proptest: no panic on any token-endpoint body.
-
-
Docs:
shared-crates.adoc.
-
-
U4 (w3)
feat(auth): refresh, revoke and end sessions upstream(W5’srefresh,revoke,end_session; W6; #2345).-
Tests:
-
each
UpstreamRequestErrorvariant, discovery unavailable, a missing token endpoint, and 408/425/429 against other statuses, each in its class; -
withinunder the connect bound, which turns a stalled connect intoAmbiguous; -
discovery stalled past
within→NotProcessed, with nothing posted; -
ReissuesIdTokenwithout anid_token→AcceptedUnreadable;Userinfowithout one → granted; -
revocation’s form, and
EndpointNotAdvertised(Revocation); -
end_session's URL with and without the hint, andNone; -
refresh_due's bounds (30 s exactly isShortLived), plus a proptest over lifetimes and receipt times:Atis strictly after receipt and never later than expiry lessMIN_REFRESH_LEAD, andShortLivedholds 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 besideGrantOutcome.
-
-
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/authorisewith the UAT, as a browser does at the UI page; -
TokenBrokergainsupstream_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
Credentialsandkanidm_ca, asidp_conformance_kanidm.rs'swrite_profiledoes, throughUpstreamHttpClient::resolving(.., "idm.canopy.test", kanidm_addr), with the client secret from those credentials.
-
-
The tests, with jane.doe:
-
sign-in:
authorization→ driver →redeemvalidates the id_token and its nonce, and the grant’s id_token opens a canopy-identity session through aFederationClientkeyed as canopy-web from the devstack’s key, as the broker builds one; -
refresh, once past the opening id_token’siatsecond (a 1.1 s wait, asidp_conformance_kanidm.rsdoes), returns a grant whose id_token renews that session (RenewalEvidence::IdToken), and the renewal’sfresh_untilis later than the open’s: a real renewal, not a replay; -
after
revoke, refreshing isEnded; -
end_sessionisNoneon Kanidm; -
a wrong
stateis refused.
-
-
Close:
-
CHANGELOG.adocAdded; -
Amendment 17’s as-built record;
-
the plan Done and archived;
-
plan-lint --donewith--allow-openfor 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
claimsparameter. Kanidm always sendsauth_time(I2b). U5 proves it accepts the essential-claim request; if it refused the parameter, that would be an erratum, sendingclaimsonly 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:
|
2 |
not stated (the maintainer’s other vendor) |
not stated |
6 findings (P2), fixed in-plan:
|
The maintainer shipped after round 2 (2026-10-09).