Repository navigation
Add portable ClientInfo for Fastly, Axum, Cloudflare and Spin - #517
ChristianPavilonis wants to merge 84 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
|
Round 12 identity realignment:
This PR merges #514 again as a second base, as it did twice before. Spin Each merge message says what it carries and how any conflict was resolved. |
Bring in PR #514's new head, which hardens Spin geo deadlines and operator publication, makes the geo module crate-private, moves the KV geo tests inline and refreshes the offline dependency closure. crates/edgezero-adapter-spin/src/geo.rs: #514 changed the old single KV geo resolve; #517 had split it into authenticate and lookup. Keep #517's split, TokenCapture admission and SpinClientSource, and apply #514's changes to the split: same_credential for the token compare, a bounded secret read without the timer race, the DeadlineKv wrapper in lookup and #514's crate-private visibility. With the timer race gone, authenticate no longer takes a timer, so its callers in resolve, request.rs and the tests drop it. SpinClientSource becomes pub(crate) like SpinKvGeo and expects dead_code off Spin, where nothing reads the authenticated selection. crates/edgezero-adapter-spin/src/geo/kv_tests.rs: #514 moved these tests into geo.rs's inline kv_tests module. Delete the file and apply #517's changes there: the TokenCapture::Invalid assertion and its three tests for header admission, admission-to-Geo outcomes and direct ingress. crates/edgezero-adapter-spin/src/request/test_support.rs: take #514's helper, which drops dispatch_request_with_geo_secret and takes the geo configuration and timer explicitly. With the geo module private, the helper resolves #517's SpinClientSource from that configuration the way managed dispatch does, instead of reading it from app state. crates/edgezero-adapter-spin/tests/contract.rs: take #514's calls with the geo configuration and timer. #517's tests keep their assertions but pass configuration instead of inserting a SpinClientSource. The direct-ingress test passes a manifest that declares direct_ingress. docs/guide/native-geo.md: keep #517's Cloudflare direct-ingress sentence and #514's unsupported-country note.
|
Round 15 identity realignment:
This round's link resolves #514's new Spin geo hardening, which makes Each merge message says what it carries and how any conflict was resolved. |
Peers are canonicalized before matching, so a mapped entry such as ::ffff:10.0.0.5 never matched. Store mapped entries as IPv4 and reject entries that cover every IPv4 peer. (cherry picked from commit b4d96cf)
…aders The core module doc and the adapter overview said JA4 is never taken from request headers, but Axum reads a configured header from a trusted peer. (cherry picked from commit 4f78b22)
Stock nginx resolves the variable as the client's Ssl-Ja4 header and nginx -t does not catch it, so the guide now asks for a module check and a smoke test. (cherry picked from commit a1d97b0)
…nance The CHANGELOG now states how mapped trusted proxy entries are stored and which IPv6 entries are rejected, and the provenance sentence covers the fixed CloudFront header.
…udflareService The Unreleased bullet still listed CloudflareService as a geo path after geo was gated on the direct_ingress declaration.
…f client info Peers listed only for protected CloudFront or JA4 are still reported as DirectPeer, so the guide and spec now tell operators to add them to the trusted proxy CIDRs.
The listener strips Forwarded and X-Forwarded-* before it reads JA4, so such a name reported Missing on every request. The unmanaged converter still accepts it.
The setting now drops the manifest's geo fields, as on Axum, instead of rejecting them and answering every request with a 500.
Credential, binding, timeout and store failures were indistinguishable ProviderFailure outcomes; a fixed-reason warning names them without request values.
Review follow-up: fixes committed to this branchA full review of this PR turned up the problems below; each would otherwise have needed a follow-up ticket, so it is fixed on this branch instead. Every item names its commit.
Fixes made on the PRs below this one in the stack were merged into this branch with merge commits. 907cb8c reconciles #514's Spin geo failure logging with this PR's |
| }; | ||
| assert!( | ||
| matches!(capture(trusted), CapturedJa4::Captured { .. }), | ||
| "{proxies} should trust {trusted}" |
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