Repository navigation
Add portable ClientInfo for Fastly, Axum, Cloudflare and Spin - #517
ChristianPavilonis wants to merge 49 commits into
Conversation
Specify a provider-neutral JA4 accessor (ctx.ja4()) backed by adapter-owned RequestIngress metadata: Fastly and Cloudflare populate it from their trusted runtime APIs, Spin and Axum report NotExposed, and no adapter derives JA4 from request headers. Refs #283
Add edgezero_core::ja4 with a validated, Debug-redacted Ja4Fingerprint and CapturedJa4 provenance/absence states. RequestIngress carries an optional capture and RequestContext::ja4() reads it. Fastly and Cloudflare populate it from their runtime TLS APIs; Spin and Axum report NotExposed. No adapter derives JA4 from request headers. Includes the implementation plan and adapter documentation. Refs #283
Add a fixed ja4_state label to the request-fidelity fixture hook and send spoofed ja4 / cloudfront-viewer-ja4-fingerprint headers in its spoof case. The runner asserts Fastly and Cloudflare report missing and Spin reports not_exposed on the real local runtimes, covering Spin's into_core_request path that the plain-wasmtime contract suite cannot construct. Replace magic section offsets in ja4.rs with named constants shared by parse and the accessors, use matches! byte ranges, share one FoxIO sample constant across core tests, and move test imports to module level. Refs #283
Axum never sees the TLS handshake, but a TLS-terminating proxy in front of it (FoxIO's nginx module, HAProxy, ATS, CloudFront) can compute JA4. Add Ja4Source::TrustedProxyHeader and CapturedJa4::from_trusted_proxy_header, and an Axum TrustedJa4Header that records the configured header only when the direct TCP peer is inside an operator CIDR allowlist. Any other peer stays NotExposed, so clients cannot forge it. Configured with EDGEZERO__ADAPTER__JA4_HEADER and EDGEZERO__ADAPTER__JA4_TRUSTED_PROXY_CIDRS, or programmatically via AxumDevServer / EdgeZeroAxumService::with_trusted_ja4_header. Config fails closed on partial settings, invalid entries and /0 networks. Default behaviour is unchanged. Spec §5.8, plan task 6 and the Axum guide document the design, the operator requirement to overwrite the header, and an nginx example. Refs #283
Both workspaces depend on edgezero-adapter-axum by path, so adding ipnet to it requires their lockfiles to record the new edge. CI runs them with --locked. No new packages are resolved. Refs #283
The workspace now pins url =2.5.9 for main's Fastly SDK 0.13.3 upgrade (#529), and this loader resolves edgezero-core from the workspace, so its lockfile no longer satisfied the manifests after the merge. A targeted `cargo update -p url --precise 2.5.9` moves url to 2.5.9 and form_urlencoded to 1.2.3, matching the v0.0.12 lockfiles.
Bring in main's Fastly SDK 0.13.3 upgrade (#529) with Viceroy 0.22.0 and the Fastly CLI 17.2.0 upgrade (#531), with PR #275's exact pins at 0.13.3 and url 2.5.9, its Viceroy readiness repair on 0.22.0 and its typed Image Optimizer unavailability check for SDK 0.13.3. This takes PR #514's tip rather than PR #454's: it contains PR #454's new head, this PR's base, and also PR #514's url 2.5.9 update to the geo-spin-loader lockfile, which this PR carries from its earlier PR #514 merge. It merges without conflicts.
|
For the identity integration branch (#495), I pushed
|
|
For the identity integration branch (#495), I pushed |
|
For the identity integration branch (#495), I pushed |
prk-Jr
left a comment
There was a problem hiding this comment.
Approving the ClientInfo commits (reviewed against the #514 merge parent, so #469/#514 content is out of scope here).
What I checked:
- Core snapshot.
ClientInfotravels inAdmittedIngressbesideGeoOutcome, not in public extensions, so hooks, middleware and handlers that edit headers or insert/remove aClientInfoextension cannot replace it;effective_client_ip()excludesPeerFallback.Debugredacts addresses and TLS values (CodeQL alert 55 is now fixed). - Axum. The projection follows the checked trusted-proxy result: an untrusted peer is always
DirectPeerwhatever forwarding headers it sends; a trusted peer with no, unresolved, all-trusted or malformed chain isPeerFallback(Missing|Rejected). JA4 is captured from the ownedremote_addrafter forwarding headers are stripped, and the per-requestTrustedJa4Headerextension is removed before preparers run. Protected CloudFront JA4 reuses the Geo ALB admission, and startup rejects it with Geo off/KV or with the generic JA4 settings. - Fastly. IP and TLS protocol/cipher are read from the original downstream request before the raw prepare hook.
- Cloudflare. Nothing is read without
direct_ingress;cfTLS goes throughReflect, avoiding the panickingworker::Cfaccessors. - Spin. The last
spin-client-addrrule is sound against Spin's actual header preparation: v4.1.0 appends the runtime fields after the client's, and current upstream renames client-sentspin-*fields toclient-provided-*, so the last field is the runtime's either way.direct_ingresstogether with authenticated-header Geo is rejected at startup, soctx.geo()andclient_info()cannot describe different addresses.
Evidence:
- Local, Rust 1.98.1: targeted core (
client_info, manifest client-metadata), Axum (client_info,ja4,geo-cloudfront) and Spin (context/direct-ingress) tests pass. - Broken-code checks:
- Spin reading the first
spin-client-addrinstead of the last failsdirect_ingress_maps_the_last_spin_client_addr. - Axum reporting an untrusted peer as
PeerFallbackfails both the unit projection test and the TCP-levelserver_projects_checked_ingress_into_client_info.
- Spin reading the first
- Hosted CI at d6df01e: green, including the Fastly/Cloudflare/Spin wasm suites and CodeQL. The two failing jobs are
cache-restore-smokeandcache-new-revision-smoke, which fail at the target-cache restore assertion and are unrelated to this change.
Not verified: live CloudFront/ALB, Cloudflare production cf/CF-Connecting-IP provenance and SpinKube deployments. The guide already lists these as operator-side checks.
PR #524 (outbound mTLS client identities, #523) belongs to no identity epic, and PR #522 (portable DynamoDB and celld record providers on Fastly, #474) is still a draft. #524 is stacked on #522, so both leave together. This commit reverts their net changes. Its tree is rc/identity as it was before #522 (654f546) merged with the current tips of #519, #515, #502, #469 and #536, the branch's remaining lines. #514 and #517 are already inside them. The rebuild merges without conflicts, and the change touches only the 113 paths that #522 and #524 changed against #517. Three files differed from a plain reverse of the two PRs because of the conflict resolutions in 7616c85 and b3a45df. Each keeps the other lines' code and drops only #522's or #524's: - crates/edgezero-adapter-axum/src/cli.rs keeps the capability matrix test's lint expectation and drops #524's client identity test. - crates/edgezero-adapter-fastly/src/request.rs keeps the after-response handle and wrapper and drops #522's deferred portable KV registry. - crates/edgezero-store-aws/src/dynamodb_records_tests.rs drops imports used only by #522's tests. Merging a later tip of #522 or #524 will not restore this code, because git treats their earlier commits as already merged. Bringing them back needs a revert of this commit first.
aram356
left a comment
There was a problem hiding this comment.
PR Review
Summary
Found while reviewing the rc/identity integration branch (#495) and traced to this PR. Each finding was re-checked at this head (d6df01e3); line numbers refer to it.
Requesting changes for two blocking findings.
Findings
Blocking
- 🔧 Spin client-source misconfiguration answers every request with 422. See
spin/src/lib.rs:268. - 🔧 CHANGELOG:
## Unreleasedhas no entry for portableClientInfoon Fastly, Axum, Cloudflare and Spin, or for theclient_infomanifest settings.
Non-blocking
- 🤔 Cloudflare geo and JA4 read
cfwithout this PR'sdirect_ingressgate. Seecloudflare/src/request.rs:711.
CI Status
- GitHub checks at
d6df01e3: 29 of 29 pass.
| request::dispatch_with_registries(app, req, stores.config, stores.kv, stores.secrets, &env) | ||
| .await | ||
| let resolved = geo::SpinKvGeo::from_config(A::manifest(), &env, stores.kv) | ||
| .and_then(|geo| geo::SpinClientSource::resolve(A::manifest(), geo)); |
There was a problem hiding this comment.
🔧 A client-source misconfiguration reaches every visitor as 422
SpinClientSource::resolve returns EdgeError::validation for a malformed manifest or for direct_ingress combined with authenticated-header geo (geo.rs:173-181). send_assembly_error renders that with error.status(), so every request answers 422 with the message. This is an operator error. Return EdgeError::internal, as Cloudflare effectively does (500) and Axum does by refusing to start. #514's geo selection error has the same problem.
There was a problem hiding this comment.
Fixed in 7a22645. The direct_ingress versus authenticated-geo conflict in SpinClientSource::resolve now returns EdgeError::internal (a redacted 500), and direct_ingress_is_declared_and_conflicts_with_authenticated_geo asserts the 500. The malformed-manifest branch still uses #514's invalid_selection(), which becomes internal once #514 merges forward. That branch cannot be reached through lib.rs anyway.
|
|
||
| /// Client facts for a managed request. Without the operator's `direct_ingress` | ||
| /// declaration nothing is read: another Worker can set both `CF-Connecting-IP` (through | ||
| /// `x-real-ip`) and the `cf` object (through a service binding). |
There was a problem hiding this comment.
🤔 Geo and JA4 read the same cf object without this gate
request_client_info refuses to read anything without direct_ingress, because another Worker can set the cf object through a service binding. ctx.geo() (:756-763, labelled PlatformMetadata) and the JA4 capture (:375-377, labelled RuntimeTls) read the same cf with no gate. Both came in before this gate existed (#502 and #469), and this PR is where it can be applied. Gate them the same way, or label their provenance as unverified when direct_ingress is off.
There was a problem hiding this comment.
Fixed in ef4a490. With direct_ingress off, ctx.geo() no longer reads cf and reports Selected { cloudflare, Unavailable(UntrustedIngress) }, and JA4 records NotExposed, the value Axum and Spin use for "no trusted source". New and updated tests in the lib, contract and ingress-fidelity suites cover it, and the Cloudflare guide, capabilities matrix and design spec are updated.
Two things to decide:
CloudflareServiceandinto_core_requesthave no manifest, so manual dispatch now never gets Cloudflare geo or JA4. That reverses what the design spec said. If manual dispatch should be able to opt in, the next step would be a builder flag.- The 12 Cloudflare
ja4_stateentries in the request-fidelityobservations.jsonwere edited by hand, not re-recorded against workerd.
Combining the two is a deployment error. As a validation error, assembly answered every visitor with 422 and the message; as an internal error it is a redacted 500.
A service-binding caller can supply the whole cf object, so the client_info declaration now gates geo and JA4 as well. Without it, geo reports UntrustedIngress and JA4 NotExposed.
|
CHANGELOG finding from the review: fixed in 949c0b6. |
Summary
ClientInfo, a read-only snapshot of the client address and viewer TLS facts that each managed adapter captures once at ingress. Handlers, middleware and pre-dispatch hooks read it throughctx.client_info()/PreDispatchRequest::client_info()without adapter imports. Header and extension edits cannot replace it.NotExposed,Missing,Rejected).effective_client_ip()never returns a trusted proxy's own address.Design:
docs/superpowers/specs/2026-11-18-portable-client-info-design.md. Plan and verification log:docs/superpowers/plans/2026-11-18-portable-client-info.md.Review scope
This branch merges two open PRs as its development baseline, so the diff against
feature/kv-geoipincludes them until they land:078d872b.ec0b912b, merged atc8613016.Review the ClientInfo commits only:
9469c8ae,c20e7176,998e207b412edaf626f787934d91a03d6b8a0f44SpinKvGeo::resolvesplit4e5fb082f3af72b5f3c6402f,e985a1d18a0ad55c..10ed3803ClientInfodispatch on Fastly and Cloudflare,SpinClientSource, tighter Spin contract tests, guide correctionsMerge order: this PR merges after #469 and #514. When #514 merges into
feature/kv-geoip, that branch is merged back in here.Changes
edgezero-core/src/client_info.rsClientInfo,Capture,UnavailableReason,ClientIpSource,ViewerTlsValue; redactedDebug; TLS classification with no grammar or allowlistedgezero-coreapp, ingress, context, pre-dispatchdispatch_admitted_with_client_info; the snapshot travels besideGeoOutcomethroughAdmittedIngress;RequestContext::client_info()andPreDispatchRequest::client_info()edgezero-core/src/manifest.rs[adapters.cloudflare.client_info],[adapters.spin.client_info](direct_ingress),[adapters.axum.ja4] source; each rejected on other adapters.Manifest::client_info_direct_ingressreads the declarationedgezero-adapter-fastlyFastlyRequestContextunchangededgezero-adapter-axumDirectPeer,Trusted*,PeerFallback); JA4 captured fromremote_addrin the service for both modes, after forwarding headers are stripped as before; protected CloudFront JA4 from the Geo selection'sProtectedCloudFrontAlb, with startup errors for Geo off, KV Geo, or generic JA4 also setedgezero-adapter-cloudflaredirect_ingressgatesCF-Connecting-IPandcfTLS, read throughReflectinstead of the panickingworker::Cfaccessorsedgezero-adapter-spinspin-client-addr; authenticated mode reuses #514's admission (token captured as absent/valid/invalid,resolvesplit intoauthenticateandlookupwith unchanged Geo outcomes);SpinRequestContextreads the last field;SpinClientSource(Off,DirectIngress,AuthenticatedGeo) holds one source, anddirect_ingresswith authenticated-header Geo is a configuration erroredgezero-test-harnessclient_statelabel; verification requires the runtime address on Fastly and Spin andnot_exposedon Cloudflare; baseline updateddocs/guideCloses
Closes #475
Closes #89
Closes #90
Closes #91
Closes #92
Closes #485
Live checks are follow-ups, not closing conditions (see below).
Test plan
cargo test --workspace --all-targets(3,098 passed)cargo clippy --workspace --all-targets --all-features -- -D warningscargo fmt --all -- --check, plus the harness,reusable-appandrequest-fidelityworkspacescargo check --workspace --all-targets --features "fastly cloudflare spin"request::/context::lib tests under Viceroy 0.21.0; Cloudflare contract (33), ingress fidelity (7) and lib (142) underwasm-bindgen-test-runnerand Chromium; Spin contract (39) and SDK (25) under Wasmtime 48.0.2examples/app-demoworkspace:cd examples/app-demo && cargo test --workspace --all-targets(68 passed)cd docs && npm run lint && npm run format && npm run buildedgezero serve --adapter axumspin up) and Viceroy. In the Spinspoofcase the client sendsspin-client-addr: 192.0.2.1:1first and the snapshot still reports the runtime's loopback address.8a0ad55c..10ed3803): workspace fmt, clippy and featurecargo check; wasm clippy for Cloudflare, Fastly and Spin with and withouttest-utils; core and adapter tests (2,152 passed); Spin contract (40) and SDK (25) under Wasmtime 48.0.2; docs lint and Prettier. The new Axum JA4 and SpinClientInfoassertions fail when their fixes are reverted.Not run locally:
scripts/run_tests.shend to end; its suites were run individually.npm cifails buildingsharpon this machine. The Worker contract tests cover the Cloudflare cases with syntheticcfdata.--librun aborts under stock Viceroy in outbound backend tests, as Report geo on every adapter and bind Axum geo from the manifest #502 reported on its base. CI uses the patched Viceroy.One flaky local failure:
production_hosting::geo_hosting_proves_real_peer_and_shared_outcomefailed once during a parallel run and passed on five later runs.Live follow-ups
CloudFront-Viewer-JA4-Fingerprintnever reaching the origin, and origin isolation.ctx.geo()andctx.ja4()on Cloudflare readcfwithout an opt-in, and a service-binding caller can supplycf. Not changed here; to raise with Report geo on every adapter and bind Axum geo from the manifest #502 and Expose JA4 through a standard request interface #469.Checklist
{id}syntax (not:id)edgezero_core(nothttpcrate)KvRegistry/ConfigRegistry/SecretRegistry(not the legacy single-handle setters) — see spec §6.6