Identity plane split, plan I3e3: canopy-web’s sender (epic &133)
Status: Done (2026-10-10) — !1589
Epic: &133 (stage I3 of &130)
Issues: #2824 (U1, w2); #2825 (U2, w3); #2826 (U3, w5); #2827 (U4, w3); #2828 (U5, w2).
MR: feat/identity-web-sender, "canopy-web’s sender (#2824 … #2828)".
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. X1–X8 are this plan’s decisions (ADR-049 Amendment 19); R5–R8 are the maintainer’s rulings.
Context
Amendment 18 V1 named I3e3, canopy-web’s sender; plan I3e2’s ruling R3 gave its scope: delegation for each backend call, the session_stale renew-and-retry, and system purposes. Plan I3e2 built the session engine this sender stands on.
The maintainer’s rulings (2026-10-10):
-
R5. A request’s concurrent calls share one per-request cache, with single-flight per target, and receive owned bearers.
-
R6. canopy-web’s sender is its own type,
WebSender.IdentitySenderstays the service-only sender E4 describes. -
R7. The sender renews a
session_stalesession itself, once per request. -
R8. On narrowing, the maintainer asked for the architecturally correct answer. That is X3: no narrowing.
What exists:
-
canopy-auth’s sender pieces:
-
DelegationTokenSource::from_session(&mut DelegationCache, &SessionCredential, target, &Narrowing)(identity_client/delegation.rs); -
SystemTokenSource, process-wide with single-flight slots (identity_client.rs), a precedent for per-key interior mutability; -
OwnedBearerandclient_key_secret(identity_sender.rs); -
SENDER_BUDGET(6.5 s).
-
-
The call graph (
identity_policy/call_graph.rs): canopy-web has 14Delegationedges and oneBothedge, to canopy-security. Its one system purpose iscanopy-web/canopy-security(identity_policy.rs). -
The engine:
WebSessionEngine::current(key, budget) → LiveSession(identity_web_session/engine.rs). It has no way to force maintenance.
canopy-web today (replaced at the switch):
-
Reads carry canopy-web’s own service token, and fail open without a page deadline (
services/canopy-web/src/clients.rs,with_service_identity). -
Writes use an RFC 8693 exchange.
-
The dashboard fans out up to 8 calls at once (
bounded_join,UPSTREAM_FANOUT_LIMIT). -
A backend 401 is treated as just another 4xx.
Decisions (ADR-049 Amendment 19, X1–X8; land with U1)
-
X1. Staging (R5–R8). I3e3 is canopy-auth library code, unwired until the switch, which moves canopy-web’s roster, its exchange wrappers and its panel-cache key (#2647) (W1).
-
X2.
WebSender(R6) is a new module,canopy_auth::identity_web_sender. It is a cheapClonehandle over anArc, holding aWebSessionEngine<S>, aDelegationTokenSourceand aSystemTokenSource, both minting with canopy-web’s key.-
WebSender::over_http(engine, &IdentitySettings, Arc<dyn KeySigner>, IdentityHttpClient). -
from_secrets(engine, &IdentitySettings, &dyn SecretProvider, IdentityHttpClient) → Result<_, SenderError>reads the key underclient_key_secret(ConfidentialClient::Web)(CANOPY_WEB__IDENTITY_CLIENT_PRIVATE_KEY, D10), with no file fallback (SenderError::Key).
-
-
X3. Routing; no narrowing. This amends B3’s "a mint narrows per request" to "a mint may narrow". canopy-web’s never does.
-
Inside a request (
WebOutbound), aDelegationorBothedge mints from the session (G1’s session form,act[canopy-web]). ASystemedge takes a system token. No edge isNoEdge, and nothing is sent. -
System calls:
system_bearer(target), on the outbound for M4’s in-request system call (the worker-name refill) and on the sender for detached tasks. It works onSystemandBothedges only; aDelegationedge isNoSystemEdge(E5). -
Mints never narrow: every mint takes G4’s base, the session’s current roles and programs.
-
Why not narrow: by G4, canopy-web’s narrowing becomes the ceiling for every onward hop. Narrowing at the edge would make canopy-web encode the transitive role needs of each downstream chain (eligibility → SOLQ, for example), and that would fail closed whenever a downstream policy changed. D4 keeps policy compiled and judged at every receiver against the session’s current roles. Least privilege comes from structure instead: one audience per token, at most 300 s, reuse within one request only, the
actchain, and freshness. A narrowing parameter can be added later, without breaking callers, for a locally known case.
-
-
X4. The session form’s sender-side check (D3, G9).
DelegationTokenSource::from_sessiontakes the&FederatedSession, not only its credential. A minted token must name the session’ssubandsid, and itsexpmust be no later thansession_ends_at, elseAnswerDefect::SubjectorOutlivesSubject. All are issuer-clock times. This mirrors the onward form’s check. Its callers update in the same diff:-
the token broker, which holds a
FederatedSession; -
web_session_engine_test.rs, which passes&record.session; -
identity_client/delegation/tests.rs's 11 call sites; -
canopy-security’s
identity_delegation/end_to_end.rsandidentity_admin/end_to_end.rs. These read only part of F2’s answer today. Their answer structs gain F2’s remaining fields (auth_time,session_ends_at,fresh_until,roles,programs,username), from which they build theFederatedSession, whose fields are public.
-
-
X5. The per-request outbound (R5).
-
Construction:
WebSender::calls(key, LiveSession, deadline: tokio::time::Instant) → WebOutbound<S>owns everything it needs, so it is'static,SendandSync, and canopy-web can share it through anArcextension at the switch. Compile-time probes hold this, along withbearer()'s future beingSend. -
The cache: a
parking_lot::Mutex<HashMap<CanopyService, Arc<TargetSlot>>>, plus an outbound-wide renewal epoch. A target’s slot is created once and never removed. It holds atokio::sync::Mutexover the target’sDelegationCacheand the epochs it was filled under, and aparking_lot-guarded state: the slot’s own epoch, an attempt counter, a last-failed flag, and a stale flag tagged with the renewal epoch it was refused under. Theparking_lotguards cover only reads and writes of that state, never an await. -
Invalidation by generation.
rejected(target)bumps the slot’s epoch, and a successful renewal (X6) bumps the outbound’s. Nothing is removed, so every caller, queued or new, meets the same slot.-
Holding the slot’s lock, a caller first clears a cache filled under an older pair of epochs, so a rejected or pre-renewal token is never served.
-
A token minted while either epoch moved is returned to its own caller, being a new token, but is not cached.
-
A caller whose epochs moved while it waited re-reads the current pair before serving.
-
Renewal happens at most once per request, and
rejectedonly on the caller’s own 401, so this converges within the call’s bound.
-
-
Failure sharing, as
SystemTokenSourceshares it: callers queued during a failed attempt answerSharedFailureinstead of minting again.-
The attempt runs under a guard that publishes a failure (attempts + 1, last failed) on drop unless it completed, so an attempt cancelled by its bound still publishes its outcome to the callers queued behind it.
-
A
session_stalerefusal is not a shared failure. It sets the slot’s stale flag at the current renewal epoch, and every caller that sees the flag goes straight to the shared renewal (X6) without minting, then retries under the new epoch.
-
-
Bearers:
bearer(&self, target) → Result<OwnedBearer, WebSendError>copies the token out under the slot’s lock into a zeroizingOwnedBearer, through a newpub(crate)constructor (E7). A fan-out holds no borrow. -
Bounds. This amends E6’s per-acquisition bound for canopy-web, which computes every stage from one request deadline.
-
Each mint attempt, its wait for the slot included, is bounded by the lesser of
SENDER_BUDGETand what remains todeadline. -
The renewal (X6) is bounded by what remains less
MINT_RESERVE. -
The whole
bearer()is bounded bydeadline. -
Past a bound, the answer is
Timeout, orRenewalPendingfor the renewal.
-
-
The ADR exception: this is interior mutability, which the coding conventions allow only with an ADR, and this decision is that ADR. It follows
SystemTokenSource's pattern, scoped to one request.
-
-
X6.
session_stale(R7, G2).-
One renewal per request. A mint refused
session_stalerenews the session once per request, through atokio::sync::OnceCell<Result<NumericDate, Renewal>>that concurrent calls share.-
RenewalisCopy:Ended,Pending,NotAdvancedorStore(StoreFault). -
The renewal is
engine.maintain_now(key, served_version, remaining − MINT_RESERVE). -
MINT_RESERVE(1 s) guarantees the retried mint at least that long; the retry gets the lesser ofSENDER_BUDGETand what remains. A slow issuer’s retry may therefore time out, a deliberate trade so that the renewal fits the request. -
With no more than the reserve remaining, the answer is
RenewalPendingwithout renewing. -
Not advanced: a renewal that answers a session whose
fresh_untildid not pass the served one isNotAdvanced, and the request answersRenewalPendingwith no retry. canopy-identity refused or failed it without ending the session, and the leader committed a retry.
-
-
After a successful renewal:
-
the outbound bumps its renewal epoch once (F5 re-projected roles and programs), so no pre-renewal token is served again (X5);
-
each stale call retries its mint once, with the same credential (F2 echoes it);
-
the retry is classified as the first attempt was, and only a second
session_staleisWebSendError::Delegation.
-
-
Refusals:
-
session_endedandsubject_suspendedcallengine.end_refused(key, refusal, remaining)and answerSessionEnded; -
any other refusal, a 429 (G10’s limit), a 503 or a transport failure answers its typed error, with no retry and no fallback (E6: never fail open).
-
-
Renewal outcomes:
Unserved::NoSessionorEndedisSessionEnded;PendingisRenewalPending;StoreisStore.
-
-
X7. The engine’s two new entries.
-
maintain_now(key, seen: RecordVersion, budget) → Result<LiveSession, Unserved>runs V4’s loop under one deadline, withdecide_forced, in this precedence:-
no row →
NoSession; -
unbound → end
UpstreamChanged; -
lapsed claim → end
RefreshLost; -
version past
seen→ V4’s ordinarydecide, since another leader maintained it; -
at
seen, not maintainable → endExpired; -
at
seen, inside V3’s retry spacing (maintain_at > nowandmaintain_at > fresh_until − FRESHNESS_LEAD, which no scheduled time exceeds) →Pending. This holds a failed renewal’s 30 s spacing while the local freshness is withinFRESHNESS_LEADplusMAINTENANCE_RETRYoffresh_until. Beyond that skew, each new version may be forced once per request, single-flight (see Risks); -
deadline passed →
Pending; -
a live claim → wait;
-
free → lead.
Otherwise it ignores the local freshness and
maintain_at, because canopy-identity’s freshness has spoken. The claim at the version keeps it single-flight.
-
-
end_refused(key, refusal: CanopyRefusal, budget) → Result<(), Unserved>ends the recordIdentityRefused:-
under
SessionEnded, with no identity revocation; -
under
SubjectSuspended, revoking canopy-identity’s session within 2 s, since F8 revokes a suspended subject’s session only at a renewal.revoke_identity's skip rule (no revocation forIdentityRefused) moves into its callers. Aspawn_revocation(inner, credential)revokes, and each end path decides whether to call it.
-
-
-
X8. A receiver’s 401 (E6).
-
WebOutbound::rejected(target), which is sync, bumps the target slot’s epoch (X5), so the request’s delegation tokens for it are never served again, even to callers already queued, and it invalidates the process’s system token for it. -
The caller retries once. The sender never retries a 401 on its own.
-
Rate
Reuse is per request, so canopy-web’s mints are roughly page loads × distinct targets per page: about 3 on P1’s assumption. That is within P4’s ≥ 60 000 a minute at two replicas. A 429 is a typed error, never retried by the sender.
Units
Every commit goes through the J1–J8 review. Each subject is at most 72 characters with its ` (#N)`.
Erratum (2026-10-10): each piece landed with its first use, so nothing sat unused between units. The engine_world re-export landed in U3, not U2. calls took the record’s key in U4, with the renewal. The delegation mock’s one-shot answer arrived in U4. X4’s callers also included the capacity harness (xtask/src/cmd/perf/identity/senders.rs). The admin end-to-end test’s SignedIn keeps the session in place of the bare credential. The renewal cell holds Result<(), Renewal>, since nothing read the new freshness. U4’s "minted across the renewal" test became the deterministic "no token minted before the renewal is served after it", the property the epoch pair guarantees.
-
U1 (#2824, w2)
docs(adr): record canopy-web’s sender.-
ADR-049 Amendment 19 (R5–R8, X1–X8), plus the Status line.
-
This page (
In progress), with the** Identity Plane Split (epic &130)nav group above the archive line.
-
-
U2 (#2825, w3)
feat(auth): force a web session’s maintenance(X7).-
Files:
-
identity_web_session/decide.rs:decide_forced(facts, seen, now, deadline_passed); -
engine.rs:maintain_nowandend_refused.currentandmaintain_nowshare a private loop taking a mode,ServeorForce(seen), split into helpers to stay within 40 lines. A second impl block holds the methods past the 16-method cap.
-
-
Test access:
-
engine.rs's[cfg(test)] mod testsbecomespub(crate) mod tests, andidentity_web_session.rsre-exports it under[cfg(test)]aspub(crate) use self::engine::tests as engine_world, for U3 and U4. -
One pair of test ids,
TEST_SIDandTEST_SUB(pub(crate)inidentity_client/delegation/tests.rs), is shared by the delegation endpoint’s minted claims, the engine world’sf2answers andWorld::record, so X4’s check passes.
-
-
Tests:
-
a locally fresh session at
seenis led, and one refresh and one renewal are posted; -
a version past
seenis served asdecidewould; -
a row inside its retry spacing is
Pending, and nothing is posted; -
16 concurrent
maintain_nowcalls at one version post one refresh; -
a live claim is waited on;
-
unbound, lapsed and tokenless sessions end as V4 does;
-
the deadline gives
Pending; -
end_refused(SessionEnded)endsIdentityRefusedand posts no revocation, whileend_refused(SubjectSuspended)posts one; -
a proptest: at
seen,decide_forcednever leads past the deadline, inside the spacing or over a claim; pastseen, it equalsdecide.
-
-
Docs:
shared-crates.adoc.
-
-
U3 (#2826, w5)
feat(auth): add canopy-web’s sender(X2–X5, X8).-
Files:
-
crates/canopy-auth/src/identity_web_sender.rs(+tests.rs), with re-exports inlib.rs:WebSender,WebOutbound(with a hand-writtenDebugnaming only the key’s presence and the served version), andWebSendError(NoEdge,NoSystemEdge,Timeout,SharedFailure,System(SystemTokenError),Delegation(DelegationError),SessionEnded,RenewalPending,Store(StoreFault)), no variant carrying a token or credential; -
identity_sender.rs:OwnedBearer::from_call(&str), apub(crate)constructor; -
identity_client/delegation.rs: X4’sfrom_session(&FederatedSession, …)and its check; -
the callers X4 names.
-
-
Test helpers: the delegation tests'
Script(its fields),script()and endpoint becomepub(crate). The endpoint gains adelay(a stall gate) and a one-shot raw answer. -
Tests:
-
a
Delegationedge sends the session form:requested_token_typethe access-token type,subject_token_typeweb-session, the target’sresource, and neitherrequested_rolesnorrequested_programs; -
the
Bothedge (canopy-security) delegates in a request; -
system_bearer(Security)takes a system token, andsystem_bearer(Persons)isNoSystemEdge; -
a target with no edge is
NoEdge, and nothing is sent; -
concurrency:
-
8 concurrent bearers to 3 targets post 3 mints, and calls to one target get one token;
-
8 concurrent bearers to one target against a 503 post one mint, the rest answering
SharedFailure; -
staggered waiters: one caller’s attempt against a stalled endpoint is cancelled by its bound, and a caller queued behind it answers
SharedFailurewith no second mint; -
rejectedwhile callers are queued on the target and a mint is in flight: no queued caller receives the rejected token, the in-flight token is returned but not cached, and every later caller is served one new token from the same slot;
-
-
two outbounds mint separately (request scope);
-
rejectedre-mints, and invalidates the system token; -
a stalled endpoint gives
Timeoutby the lesser of the budget and the deadline; -
X4’s check: a token naming another
sid, or outlivingsession_ends_at, is refused; -
probes:
-
WebOutboundisSend + Sync + 'static, andbearer()'s future isSend; -
WebOutboundhas noClone(it owns the session’s credential); -
OwnedBearerhas noDebug.
-
-
-
Docs:
shared-crates.adoc.
-
-
U4 (#2827, w3)
feat(auth): renew a stale session once per request(X6).-
Tests (
engine_worldplus the delegation endpoint):-
session_stalethen success: one renewal posted, the renewal epoch bumped, the mint retried once, a bearer; -
8 concurrent calls refused
session_staleshare one renewal; -
several callers to one target, the first refused
session_stale: the others join the renewal without minting, all receive bearers, and the target sees exactly two mints (the refused one and one retry, its token served to every caller); -
a renewal completing while mints to other targets are in flight: their tokens are returned but not cached, and later calls are served post-renewal tokens;
-
session_staleon the retry givesDelegation, with no second renewal; -
session_endedon the retry givesSessionEnded; -
a renewal that does not advance
fresh_until(canopy-identity 503) givesRenewalPendingwith no retry; -
too little time left gives
RenewalPendingwithout renewing; -
session_endedgivesSessionEnded, the record endedIdentityRefusedwith no revocation; -
subject_suspendeddoes the same and revokes; -
a 429 or another refusal leaves the record untouched.
-
-
Docs:
shared-crates.adoc.
-
-
U5 (#2828, w2)
test(auth): prove canopy-web’s sender on the devstack.-
The test file:
crates/canopy-test-lib/tests/web_sender_test.rs.-
It duplicates
web_session_engine_test.rs's plane construction, since each test file builds alone: a cast worker per test signs in through the engine. -
Probes sit behind
IdentityReceiver::over_httpfor canopy-persons and canopy-security, asidentity_sender_test.rs'sserve_probedoes.
-
-
The tests:
-
a bearer for Persons admits the worker’s user principal,
act[canopy-web]; -
8 concurrent bearers across Persons and Security get one token per target;
-
in a request, Security takes a delegation, and
system_bearer(Security)admits canopy-web’s system principal; -
rejectedmints a new token; -
after
sign_out, a bearer from a fresh outbound (an empty cache, so the mint reaches the issuer) isSessionEnded.
-
-
A real
session_staleneeds 900 s, so U4’s scripted tests prove it, and this unit does not. -
Close:
-
CHANGELOG.adocAdded(andChangedfor X4’s signature); -
Amendment 19’s as-built record;
-
the plan Done and archived;
-
plan-lint --donewith--allow-openfor U1–U5, #2344, #2345, #2521 and #2647; -
after merge, update the epic.
-
-
Scope
In: WebSender and WebOutbound; X4’s session-form check; the engine’s maintain_now and end_refused; the devstack proof.
Out:
-
The switch: canopy-web’s roster, exchange wrappers, handlers, the panel-cache key (#2647), and removing its fail-open read path.
-
The device-approval and security-admin clients, and the edge forwarder: later I3e plans.
-
A narrowing parameter: added only when a route needs one.
Risks
-
The per-request cache is interior mutability. X5 records it as an ADR exception, scoped to one request, as
SystemTokenSourcedoes. -
A renewal adds latency to the first call that finds the session stale. It runs once per request, within the request’s deadline less
MINT_RESERVE, and answersRenewalPendingrather than overrunning. -
Clock skew beyond V3’s 15 s margin makes stale answers routine: each costs one forced maintenance per version. While the local freshness is near its end, a failed renewal’s 30 s spacing holds (X7 step 6). Beyond that skew, a session whose renewals keep failing is forced once per request at each new version: single-flight, bounded by its request rate.
-
A forced maintenance within one second of the last refresh is refused at canopy-identity as not newer (F5). The request answers
RenewalPending, and the next request recovers.
Verification
-
Per unit: fmt; clippy with and without
test-helpers; quality-budgets, plan-lint, check-docs and private rustdoc. -
nextest:
-
canopy-auth (U2–U4);
-
cargo xtask test --integration --host -p canopy-test-lib --no-refresh --skip-static(U5).
-
-
Per MR: the pre-push battery.
Review log
| Round | Vendor | Resolved model | Verdict |
|---|---|---|---|
1 |
Anthropic |
Claude Opus 5.5 (fresh subagent) |
no-ship. Two blockers, fixed in-plan:
|
2 |
not stated (the maintainer’s other vendor) |
not stated |
1 finding (P2) and 4 clarifications, fixed in-plan:
|
The maintainer shipped after round 2 (2026-10-10).