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_jwt assertions), so the forwarder holds none, and WebSender plays 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 at METADATA_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 htu is 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 400 invalid_request.

    • The limited routes answer with Cache-Control: no-store and Pragma: no-cache.

  • Per-IP limits use canopy-api’s private client_ip: the socket peer, or the leftmost X-Forwarded-For hop only from a peer listed in CANOPY_TRUSTED_PROXIES (ratelimit.rs:123).

  • The issuance log’s peer_addr reads the raw ConnectInfo peer (token_endpoint.rs:1222, device.rs:233, revocation.rs:177).

  • canopy-auth’s client: IdentityHttpClient follows 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-For and 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.

    • TrustedProxies provides from_env(), which reads CANOPY_TRUSTED_PROXIES, and parse(raw), the same rule, for tests. Default is 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) → IpAddr is the peer, or the leftmost X-Forwarded-For hop only from a listed peer. The issuer (Q3) and the forwarder (Q5) call it.

    • client_ip(&self, peer: Option<SocketAddr>, headers: &HeaderMap) → IpAddr is the limiters' form: resolve given a peer, or 127.0.0.1 with none, as today.

    • canopy-api’s process-local and Redis limiters and ApiServer call client_ip, unchanged in behavior. Each apply_rate_limit call 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).

    • TokenEndpointParts gains trusted_proxies. main.rs passes from_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), logs resolve(peer, headers) as peer_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-For on 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/token and /identity/revoke; GET /identity/jwks and METADATA_PATH.

    • HEAD: the GET handler serves HEAD, sending GET upstream. axum sets Content-Length from 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. IdentitySettings gains device_authorization_endpoint() and metadata_url(). The metadata URL is the internal origin plus METADATA_PATH, the internal URL’s path being exactly /identity (identity_url).

    • Shared constants: the five paths and MAX_FORM_BYTES move to canopy-auth, as ADMIN_PATH and ADMIN_BODY_LIMIT did. 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 at MAX_FORM_BYTES on 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-Type as received.

      • Every DPoP value 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-Length and Accept. No Cookie, Authorization, Forwarded, X-Real-IP, other X-Forwarded-* or Accept-Encoding.

    • Peer: read from the request’s ConnectInfo<SocketAddr> extension, as token_endpoint.rs:1222 does. 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 becomes pub(crate)), and only Content-Type, Cache-Control, Pragma, Retry-After and Age. Age is 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-Encoding but identity;

      • any 3xx, so a Location never 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). A const assertion holds it above the first two, and a canopy-security test holds it above REQUEST_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 by new(&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.

  1. 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).

  2. 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 (its TrustedProxies and client_ip removed; the Redis path’s imports stay behind rate-limit-redis) and lib.rs (:232, and the test at :1334).

    • Tests:

      • ratelimit.rs's two X-Forwarded-For tests (: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 parse and 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).

  3. U3 (#2842, w3) refactor(auth): share the issuer’s paths and form limit (Q4).

    • Files:

      • crates/canopy-auth/src/identity_url.rs gains the five paths and MAX_FORM_BYTES;

      • canopy-security’s token_endpoint.rs, device.rs, revocation.rs, jwks.rs, request.rs and config.rs:2269, and its test files, import them;

      • canopy-test-lib’s broker drops its TOKEN_PATH and JWKS_PATH, and native_session_test.rs drops its two copies; they, devstack_identity_test.rs:18 and identity_broker_test.rs:22 import canopy-auth’s;

      • xtask’s cmd/perf/identity/senders.rs:31 imports canopy-auth’s REVOKE_PATH and TOKEN_PATH;

      • the now-tautological pin in identity_federation_test.rs:791 is cut down.

    • Tests: the existing suites, unchanged in what they assert.

    • Docs: shared-crates.adoc.

  4. U4 (#2843, w3) feat(security): record the forwarded client in the log (Q3).

    • Files: TokenEndpointParts and 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 takes TrustedProxies::default() explicitly, since it serves no proxied traffic.

        Also the peer reads in issue, peer_of and 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 in tests/identity_native_test.rs. For each route:

      • a listed peer’s X-Forwarded-For hop 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: a CANOPY_TRUSTED_PROXIES row under "Process-wide variables", and line 433.

  5. 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.rs holding EDGE_FORWARD_TIMEOUT above REQUEST_BUDGET.

    • Tests run in process against a loopback recorder that stands in for canopy-security, with the router served with ConnectInfo on 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-Length equal to the GET’s body length, and the relayed headers.

      • Headers: Content-Type, the DPoP values in order (two arrive as two) and X-Forwarded-For are sent, and beyond those only the transport’s Host, Content-Length and Accept.

        • An unlisted peer sends its own address; a listed peer, its leftmost hop alone. A client’s own X-Forwarded-For is 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_request and sends nothing, both declared and streamed (a raw chunked HTTP/1.1 request over a TcpStream, as in identity_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-Cookie and Location are dropped.

      • Failures: each answers 503 temporarily_unavailable with 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.

  6. 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.rs repeats native_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 Age header.

      • snap’s client-credentials grant for canopy-verification goes through the edge (SystemTokenSource, its token endpoint the edge’s, as in identity_sender_test.rs), and the token verifies at canopy-verification’s receiver.

      • canopy-cli’s device flow runs through the edge:

        1. device authorization;

        2. approval by jane.studio through NativeSessions, accepting the broker’s per-person spacing;

        3. redemption and a refresh with DPoP;

        4. revocation as a public client;

        5. a refresh after it, refused invalid_grant.

          The proof’s htu is 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 and MAX_FORM_BYTES moved to canopy-auth, and the broker’s constants removed.

      • Amendment 22’s as-built record.

      • The plan Done and archived.

      • plan-lint --done with --allow-open for 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_PROXIES takes 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 htu is 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 (resolve, NULL kept); Age relayed for the JWKS contract; one service:: label per issue. Notes folded in: U3’s three missed importers, TOKEN_RESPONSE_CAP visibility, the one-MR justification, canopy-portal out of scope, test files named, glosses.

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 TokenEndpointParts site, with an explicit proxy list; HEAD is served by the GET handler and sent upstream as GET, with a HEAD header assertion in U5.

Edit this page · default