Identity plane split, plan I3e6: the edge forwarder (epic &133)
Status: Done (2026-10-11) — !1592
Epic: &133 (stage I3 of &130)
Issues: #2840 (U1, w2); #2841 (U2, w3); #2842 (U3, w3); #2843 (U4, w3); #2844 (U5, w5); #2845 (U6, w3). Follow-up: #2846 (CIDR ranges).
MR: feat/identity-edge-forwarder, "the edge forwarder (#2840 … #2845)".
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. Q1–Q7 are this plan’s decisions (ADR-049 Amendment 22); R15–R17 are the maintainer’s rulings.
Context
ADR-049 D2 keeps canopy-web the only internet-facing edge: "It forwards canopy-identity’s public endpoints: device authorization, and the token endpoint for native and machine clients." N8 adds the revocation route.
-
Callers: canopy-cli (I3f) and machine clients. They bring their own credentials (DPoP proofs, refresh credentials,
private_key_jwtassertions), so the forwarder holds none, andWebSenderplays no part. -
Staging: W1 (Amendment 17’s staging rule) makes the forwarder canopy-auth library code. canopy-web’s "forwarding mount" lands with the switch, and canopy-web holds no dormant module.
What exists:
-
No forwarder code exists anywhere.
-
canopy-security serves the token, revoke and device-authorization routes,
/identity/jwks, and the RFC 8414 metadata atMETADATA_PATH(/.well-known/oauth-authorization-server/identity).-
The paths are canopy-security constants:
TOKEN_PATH(token_endpoint.rs:224),METADATA_PATH(:228),DEVICE_AUTHORIZATION_PATH(device.rs:101),REVOKE_PATH(revocation.rs:115),JWKS_PATH(jwks.rs:47). -
The metadata advertises every URL under the issuer identifier.
-
The DPoP
htuis checked against the configured public token endpoint, never the request URL (native.rs:324). -
Forms are capped at
MAX_FORM_BYTES(64 KiB) and read within a deadline. An oversized form answers 400invalid_request. -
The limited routes answer with
Cache-Control: no-storeandPragma: no-cache.
-
-
Per-IP limits use canopy-api’s private
client_ip: the socket peer, or the leftmostX-Forwarded-Forhop only from a peer listed inCANOPY_TRUSTED_PROXIES(ratelimit.rs:123). -
The issuance log’s
peer_addrreads the rawConnectInfopeer (token_endpoint.rs:1222,device.rs:233,revocation.rs:177). -
canopy-auth’s client:
IdentityHttpClientfollows no redirects. -
canopy-web has no request timeout, and its whole router sits under its per-IP edge limiter.
The maintainer’s rulings (2026-10-11):
-
R15. Routes: forward the three POSTs, plus the metadata and the JWKS, so every URL the metadata advertises resolves at the edge.
-
R16. Source address: the issuer records the forwarded client, and the client-IP rule becomes one source in canopy-common.
-
R17. Forms: the edge passes every form through. It never parses a form, and the issuer authenticates every grant.
Decisions (ADR-049 Amendment 22, Q1–Q7; land with U1)
-
Q1. Staging.
-
The forwarder is canopy-auth library code, unwired until the switch.
-
The switch brings:
-
canopy-web’s mount;
-
canopy-web’s address in canopy-security’s
CANOPY_TRUSTED_PROXIES; -
the issuer identifier at canopy-web’s public origin;
-
an ingress in front of canopy-web that overwrites
X-Forwarded-Forand never appends to it. canopy-web keys on the leftmost hop, so an appending ingress would let a client choose the address canopy-web forwards (plan I2g).
-
-
The devstack identifier stays internal until the switch. The devstack proof hosts the forwarder in its own test process.
-
-
Q2. The client-IP rule, one source (R16):
canopy_common::http::client_ip.-
TrustedProxiesprovidesfrom_env(), which readsCANOPY_TRUSTED_PROXIES, andparse(raw), the same rule, for tests.Defaultis the empty list. -
Entries must be exact addresses, as today. The one change: each unparseable entry is warned at startup rather than dropped silently, since a mistyped proxy puts every proxied client in one bucket.
-
resolve(&self, peer: IpAddr, headers: &HeaderMap) → IpAddris the peer, or the leftmostX-Forwarded-Forhop only from a listed peer. The issuer (Q3) and the forwarder (Q5) call it. -
client_ip(&self, peer: Option<SocketAddr>, headers: &HeaderMap) → IpAddris the limiters' form:resolvegiven a peer, or 127.0.0.1 with none, as today. -
canopy-api’s process-local and Redis limiters and
ApiServercallclient_ip, unchanged in behavior. Eachapply_rate_limitcall still reads the variable, so a bad entry is warned once per limiter; that is accepted. -
canopy-portal’s own client-IP rule (
canopy-portal/src/ratelimit.rs:464) is out of scope.
-
-
Q3. The issuer records the forwarded client (R16).
-
TokenEndpointPartsgainstrusted_proxies.main.rspassesfrom_env(), the variable its limiter also reads; tests pass a parsed list, so no test sets the environment. -
Every route of the token router, code entry included (it shares
peer_of), logsresolve(peer, headers)aspeer_addr, and so do the session rows those routes write. A request with no peer still logs NULL; no address is made up. -
canopy-web sends no
X-Forwarded-Foron its own calls (code entry, federation, the sender), so they keep logging canopy-web. -
With the variable unset, nothing changes.
-
-
Q4. The forwarded routes (R15; amends D2 and N8).
-
Routes: POST
/identity/device_authorization,/identity/tokenand/identity/revoke; GET/identity/jwksandMETADATA_PATH. -
HEAD: the GET handler serves HEAD, sending GET upstream. axum sets
Content-Lengthfrom the relayed body before stripping it (route.rs's top-level HEAD handling), so a HEAD advertises the representation’s true length; a HEAD sent upstream would advertise 0. -
Targets: each goes to its twin under the internal URL.
IdentitySettingsgainsdevice_authorization_endpoint()andmetadata_url(). The metadata URL is the internal origin plusMETADATA_PATH, the internal URL’s path being exactly/identity(identity_url). -
Shared constants: the five paths and
MAX_FORM_BYTESmove to canopy-auth, asADMIN_PATHandADMIN_BODY_LIMITdid. canopy-security imports them directly, with no re-export. -
Never forwarded: code entry, the admin routes, any other path or method, and any query string.
-
-
Q5. The request at the edge (R17).
-
Body:
-
A POST’s body is read within
EDGE_BODY_READ_TIMEOUT(2 s, the issuer’s processing budget) into a zeroizing buffer. The buffer is reserved atMAX_FORM_BYTESon the first frame, so an idle connection pins nothing and the buffer never reallocates. -
A slow body answers 503
temporarily_unavailable. -
A body over the cap, declared or streamed, answers 400
invalid_request, as the issuer does. Both carry no-store and no-cache, and nothing is sent. -
The buffer is sent as
Bytes::from_owner(Zeroizing<Vec<u8>>), so it is wiped once sent. -
GETs send no body.
-
-
Headers sent:
-
Content-Typeas received. -
Every
DPoPvalue as received, in order; the issuer judges zero, one or several. -
X-Forwarded-For: exactly the client IP canopy-web resolves by Q2 under its own trusted proxies, overwritten, never appended. -
Beyond these, only the transport’s own
Host,Content-LengthandAccept. NoCookie,Authorization,Forwarded,X-Real-IP, otherX-Forwarded-*orAccept-Encoding.
-
-
Peer: read from the request’s
ConnectInfo<SocketAddr>extension, astoken_endpoint.rs:1222does. A request without one is a wiring defect: it is answered 503 and logged at error, never forwarded under a made-up address.
-
-
Q6. The answer.
-
Relayed: the status, the body (read capped at 64 KiB,
TOKEN_RESPONSE_CAP, which becomespub(crate)), and onlyContent-Type,Cache-Control,Pragma,Retry-AfterandAge.Ageis the JWKS answer’s contract (jwks.rs:13-18), which canopy-auth’s key cache reads for staleness. canopy-web’s layers add its security headers. -
Answered 503 instead, as
{"error":"temporarily_unavailable"}with no-store and no-cache (A8, the issuer’s retryable answer), and logged at warn with the route and cause, never the request:-
a call with no complete answer within
EDGE_FORWARD_TIMEOUT; -
a transport failure;
-
an answer over the cap;
-
an answer with any
Content-Encodingbut identity; -
any 3xx, so a
Locationnever reaches the internet.
-
-
The bound:
EDGE_FORWARD_TIMEOUT(6.5 s) runs from the send, after the body is read, with the connect timeout falling inside it.-
It covers the grants an internet client sends: the native grants (
NATIVE_BUDGET, 5.5 s), delegation (5.5 s), and client credentials (REQUEST_BUDGET, 5 s). Aconstassertion holds it above the first two, and a canopy-security test holds it aboveREQUEST_BUDGET. The issuer’s own budget therefore normally answers first, and a refresh’s rotation is not lost to the edge’s timeout. -
A federation form (canopy-web’s own credential, 13 s), or a JWKS read waiting on a key fetch (up to 11 s), may instead get the edge’s 503 past 6.5 s.
-
-
-
Q7.
EdgeForwarder(canopy_auth::identity_edge).-
It is a cheap
Clone, built bynew(&IdentitySettings, IdentityHttpClient, TrustedProxies). -
router<S: Clone + Send + Sync + 'static>(&self) → axum::Router<S>serves Q4’s routes alone. -
At the switch, canopy-web merges it outside the protected router’s session and CSRF layers, since the routes take no cookie, change no canopy-web state, and carry their own credentials. It sits under canopy-web’s edge limiter, which P2 (Amendment 10: per-IP limits are a backstop) relies on to bound anonymous traffic.
-
Limiting: once canopy-web is listed, the issuer’s per-IP limits key per client.
-
The form is never parsed (R17).
-
Units
Every commit goes through the J1–J8 review. Each subject is at most 72 characters with its ` (#N)`.
Erratum (2026-10-11): U4’s token-suite rig serves through a serve_with(parts, proxies) beside serve, and the native suite’s code entry is sent both with and without X-Forwarded-For. U5’s forwarder also answers an unreadable body 400 invalid_request, as the issuer does, and skips an empty data frame before reserving its buffer; its tests add a declared length refused before any read, a GET sending no body, and an answer stalling after its head. U6’s machine client is snap’s IdentitySender over settings under the edge, its token verified over the JWKS the edge relays.
-
U1 (#2840, w2)
docs(adr): record the edge forwarder.-
ADR-049 Amendment 22 (R15–R17, Q1–Q7; Q4 amends D2 and N8) and the Status line.
-
This page (
In progress) and its re-created nav group. -
A GitLab issue for CIDR ranges in
CANOPY_TRUSTED_PROXIES(#2846; see Risks).
-
-
U2 (#2841, w3)
refactor(common): share the client-IP rule(Q2).-
Files:
-
crates/canopy-common/src/http/client_ip.rs(+ tests); -
canopy-api’s
ratelimit.rs(itsTrustedProxiesandclient_ipremoved; the Redis path’s imports stay behindrate-limit-redis) andlib.rs(:232, and the test at:1334).
-
-
Tests:
-
ratelimit.rs's twoX-Forwarded-Fortests (:509,:531) move with the rule. The key-churn test (:483) stays, since it tests governor’s sweep. -
parse: addresses, junk and blanks, and each junk entry warned. -
Proptests, since
parseand the hop read are parsers: neither panics on arbitrary input, and a listed peer’s single valid hop round-trips.
-
-
Docs:
shared-crates.adoc(canopy-common).
-
-
U3 (#2842, w3)
refactor(auth): share the issuer’s paths and form limit(Q4).-
Files:
-
crates/canopy-auth/src/identity_url.rsgains the five paths andMAX_FORM_BYTES; -
canopy-security’s
token_endpoint.rs,device.rs,revocation.rs,jwks.rs,request.rsandconfig.rs:2269, and its test files, import them; -
canopy-test-lib’s broker drops its
TOKEN_PATHandJWKS_PATH, andnative_session_test.rsdrops its two copies; they,devstack_identity_test.rs:18andidentity_broker_test.rs:22import canopy-auth’s; -
xtask’s
cmd/perf/identity/senders.rs:31imports canopy-auth’sREVOKE_PATHandTOKEN_PATH; -
the now-tautological pin in
identity_federation_test.rs:791is cut down.
-
-
Tests: the existing suites, unchanged in what they assert.
-
Docs:
shared-crates.adoc.
-
-
U4 (#2843, w3)
feat(security): record the forwarded client in the log(Q3).-
Files:
TokenEndpointPartsand its construction sites:-
main.rs; -
tests/identity_{token,delegation,federation,native}_test.rs(token twice); -
identity_admin/end_to_end.rs; -
the federation, renewal, revocation, device and delegation
flow_tests.rs; -
native/flow_support.rs; -
xtask’s performance replica (
xtask/src/cmd/perf/identity/replica.rs:288), which initializes every field and takesTrustedProxies::default()explicitly, since it serves no proxied traffic.Also the peer reads in
issue,peer_ofand revocation.
-
-
Tests run in process against the database. They read the issuance log as those suites do: token and revocation in
tests/identity_token_test.rs, device authorization and code entry intests/identity_native_test.rs. For each route:-
a listed peer’s
X-Forwarded-Forhop is logged; -
an unlisted peer is logged, whatever it sends;
-
with no list, the peer is logged;
-
code entry from a listed peer, sending no
X-Forwarded-For, logs that peer.
-
-
Docs:
-
data-models/canopy-security.adoc:114(peer_addr); -
configuration-reference.adoc: aCANOPY_TRUSTED_PROXIESrow under "Process-wide variables", and line 433.
-
-
-
U5 (#2844, w5)
feat(auth): add canopy-web’s edge forwarder(Q5–Q7).-
Files:
-
identity_settings.rs(+ tests); -
the new
identity_edge.rs(+tests.rs); -
lib.rs; -
a test in
services/canopy-security/src/identity/token_endpoint/tests.rsholdingEDGE_FORWARD_TIMEOUTaboveREQUEST_BUDGET.
-
-
Tests run in process against a loopback recorder that stands in for canopy-security, with the router served with
ConnectInfoon loopback.-
Routing: each route reaches its twin with its method. Code entry, an admin path, PUT and DELETE reach nothing. A query string is dropped.
-
HEAD: a HEAD on the JWKS route reaches the recorder as a GET, and answers 200 with no body, a
Content-Lengthequal to the GET’s body length, and the relayed headers. -
Headers:
Content-Type, theDPoPvalues in order (two arrive as two) andX-Forwarded-Forare sent, and beyond those only the transport’sHost,Content-LengthandAccept.-
An unlisted peer sends its own address; a listed peer, its leftmost hop alone. A client’s own
X-Forwarded-Foris replaced. -
The cookie, authorization, forwarding and encoding headers never arrive.
-
-
Body:
-
It arrives byte-identical, a non-form included (R17).
-
64 KiB forwards. 64 KiB + 1 answers 400
invalid_requestand sends nothing, both declared and streamed (a raw chunked HTTP/1.1 request over aTcpStream, as inidentity_token_test.rs:1002). -
A body stalled past its read timeout answers 503.
-
-
Answer: the status, the body and the five headers are relayed.
Set-CookieandLocationare dropped. -
Failures: each answers 503
temporarily_unavailablewith no-store:-
a 307;
-
a gzip-encoded answer;
-
a stalled issuer: the forwarder’s timeout is a private field, which the child test module sets short;
-
a refused connection;
-
an answer over the cap;
-
no
ConnectInfo.
-
-
-
Docs:
shared-crates.adoc.
-
-
U6 (#2845, w3)
test(auth): prove the edge forwarder on the devstack.-
The test file: the new
crates/canopy-test-lib/tests/edge_forwarder_test.rsrepeatsnative_session_test.rs's plane construction and canopy-cli stand-in, each test file building alone, the stand-in taking its base URL. It hosts the forwarder on loopback in front of the devstack canopy-security. -
Tests:
-
The metadata and the JWKS through the edge equal canopy-security’s own: the same body, and for the JWKS an
Ageheader. -
snap’s client-credentials grant for canopy-verification goes through the edge (
SystemTokenSource, its token endpoint the edge’s, as inidentity_sender_test.rs), and the token verifies at canopy-verification’s receiver. -
canopy-cli’s device flow runs through the edge:
-
device authorization;
-
approval by
jane.studiothroughNativeSessions, accepting the broker’s per-person spacing; -
redemption and a refresh with DPoP;
-
revocation as a public client;
-
a refresh after it, refused
invalid_grant.The proof’s
htuis the devstack issuer’s/token, so the edge passes DPoP untouched.
-
-
-
Close:
-
CHANGELOG.adoc:-
Added:TrustedProxies,EdgeForwarder, the new settings URLs, and the log’s forwarded client; -
Changed:TokenEndpointParts, the path constants andMAX_FORM_BYTESmoved to canopy-auth, and the broker’s constants removed.
-
-
Amendment 22’s as-built record.
-
The plan Done and archived.
-
plan-lint --donewith--allow-openfor U1–U6. -
After merge, the epic’s I3e6 task list is ticked, and its stage line is marked done.
-
-
Scope
In: the shared client-IP rule, paths and form limit; the issuer recording the forwarded client; EdgeForwarder; the devstack proof.
Out:
-
The switch: canopy-web’s mount; the trusted-proxy, ingress and issuer-identifier configuration; the edge limit’s figure.
-
I3f: canopy-cli’s device client.
-
CIDR ranges in
CANOPY_TRUSTED_PROXIES.
Risks
-
Exact addresses only:
CANOPY_TRUSTED_PROXIEStakes exact addresses, so a deployment with dynamic canopy-web addresses needs CIDR support before the switch (#2846). -
An appending ingress in front of canopy-web would let clients choose their limiter key and logged address. It is a switch precondition (Q1).
-
A lost answer: if the edge loses a refresh’s answer, canopy-cli holds a spent credential, and replay detection ends the session. Q6’s bound makes this rare, not impossible.
-
The devstack’s
htuis not the URL the proof reaches, until the switch moves the identifier to the edge.
Verification
-
Per unit: fmt; clippy (workspace with the lane’s features, and canopy-auth with
test-helpers); quality-budgets; check-docs; plan-lint; private rustdoc. -
nextest:
-
canopy-common, canopy-api and canopy-auth;
-
cargo xtask test --integration --host -p canopy-security --no-refresh --skip-static(U3, U4, U5); -
-p canopy-test-lib(U3, U6).
-
-
Per MR: the pre-push battery.
Review log
| Round | Vendor | Resolved model | Verdict |
|---|---|---|---|
1 |
Anthropic |
claude-opus-5-5 |
no-ship. Three blockers, fixed: Q3’s missing-peer and code-entry rule ( |
2 |
not stated (the maintainer’s other vendor) |
not stated |
One finding (P2) and one clarification, fixed in-plan: U4 adds xtask’s performance replica as a |