Skip to content

Add portable ClientInfo for Fastly, Axum, Cloudflare and Spin - #517

Open
ChristianPavilonis wants to merge 84 commits into
feature/kv-geoipfrom
feat/portable-client-info
Open

ChristianPavilonis wants to merge 84 commits into
feature/kv-geoipfrom
feat/portable-client-info

Conversation

@ChristianPavilonis

@ChristianPavilonis ChristianPavilonis commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Adds 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 through ctx.client_info() / PreDispatchRequest::client_info() without adapter imports. Header and extension edits cannot replace it.
  • Populates it on Fastly, Axum, Cloudflare and Spin. Every field is captured with its source or unavailable with a reason (NotExposed, Missing, Rejected). effective_client_ip() never returns a trusted proxy's own address.
  • Adds protected CloudFront JA4 on Axum, reusing the CloudFront Geo path, and moves all Axum JA4 trust decisions onto the listener's owned socket peer.

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-geoip includes them until they land:

Review the ClientInfo commits only:

Commit Content
9469c8ae, c20e7176, 998e207b Spec and plan
412edaf6 Core types, dispatch plumbing, manifest tables
26f78793 Fastly and Axum
4d91a03d Cloudflare
6b8a0f44 Spin, including the SpinKvGeo::resolve split
4e5fb082 Axum JA4 from the owned peer and protected CloudFront JA4
f3af72b5 Request fidelity fixture
f3c6402f, e985a1d1 Docs and verification log
8a0ad55c..10ed3803 Review follow-ups: Cloudflare test item order, CodeQL-safe redaction test, Axum JA4 read after forwarding headers are stripped, direct ClientInfo dispatch on Fastly and Cloudflare, SpinClientSource, tighter Spin contract tests, guide corrections

Merge order: this PR merges after #469 and #514. When #514 merges into feature/kv-geoip, that branch is merged back in here.

Changes

Crate / File Change
edgezero-core/src/client_info.rs New ClientInfo, Capture, UnavailableReason, ClientIpSource, ViewerTlsValue; redacted Debug; TLS classification with no grammar or allowlist
edgezero-core app, ingress, context, pre-dispatch dispatch_admitted_with_client_info; the snapshot travels beside GeoOutcome through AdmittedIngress; RequestContext::client_info() and PreDispatchRequest::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_ingress reads the declaration
edgezero-adapter-fastly Downstream IP and TLS protocol/cipher captured before the raw prepare hook; FastlyRequestContext unchanged
edgezero-adapter-axum Checked ingress projected through the spec's fallback table (DirectPeer, Trusted*, PeerFallback); JA4 captured from remote_addr in the service for both modes, after forwarding headers are stripped as before; protected CloudFront JA4 from the Geo selection's ProtectedCloudFrontAlb, with startup errors for Geo off, KV Geo, or generic JA4 also set
edgezero-adapter-cloudflare direct_ingress gates CF-Connecting-IP and cf TLS, read through Reflect instead of the panicking worker::Cf accessors
edgezero-adapter-spin Direct ingress from the last spin-client-addr; authenticated mode reuses #514's admission (token captured as absent/valid/invalid, resolve split into authenticate and lookup with unchanged Geo outcomes); SpinRequestContext reads the last field; SpinClientSource (Off, DirectIngress, AuthenticatedGeo) holds one source, and direct_ingress with authenticated-header Geo is a configuration error
edgezero-test-harness Fidelity fixture reports a fixed client_state label; verification requires the runtime address on Fastly and Spin and not_exposed on Cloudflare; baseline updated
docs/guide Handlers, capability matrix, configuration, and the four adapter pages

Closes

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 warnings
  • cargo fmt --all -- --check, plus the harness, reusable-app and request-fidelity workspaces
  • cargo check --workspace --all-targets --features "fastly cloudflare spin"
  • WASM builds and suites: Fastly contract (37) and request::/context:: lib tests under Viceroy 0.21.0; Cloudflare contract (33), ingress fidelity (7) and lib (142) under wasm-bindgen-test-runner and Chromium; Spin contract (39) and SDK (25) under Wasmtime 48.0.2
  • examples/app-demo workspace: cd examples/app-demo && cargo test --workspace --all-targets (68 passed)
  • Docs build: cd docs && npm run lint && npm run format && npm run build
  • Manual testing via edgezero serve --adapter axum
  • Other: harness tests (680 passed); ingress fidelity on real Spin 4.1.0 (spin up) and Viceroy. In the Spin spoof case the client sends spin-client-addr: 192.0.2.1:1 first and the snapshot still reports the runtime's loopback address.
  • Review follow-ups (8a0ad55c..10ed3803): workspace fmt, clippy and feature cargo check; wasm clippy for Cloudflare, Fastly and Spin with and without test-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 Spin ClientInfo assertions fail when their fixes are reverted.

Not run locally:

  • scripts/run_tests.sh end to end; its suites were run individually.
  • Cloudflare ingress fidelity: npm ci fails building sharp on this machine. The Worker contract tests cover the Cloudflare cases with synthetic cf data.
  • The full Fastly --lib run 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_outcome failed once during a parallel run and passed on five later runs.

Live follow-ups

  • Positive Fastly viewer TLS on a deployed service.
  • Cloudflare direct-ingress client IP and viewer TLS on a live Worker.
  • Spin client address on each hosted Spin runtime.
  • Protected CloudFront JA4 on a real distribution: a fingerprint on HTTPS, none over plain HTTP, a viewer-sent CloudFront-Viewer-JA4-Fingerprint never reaching the origin, and origin isolation.
  • ctx.geo() and ctx.ja4() on Cloudflare read cf without an opt-in, and a service-binding caller can supply cf. 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

  • Changes follow CLAUDE.md conventions
  • No Tokio deps added to core or adapter crates
  • Route params use {id} syntax (not :id)
  • Types imported from edgezero_core (not http crate)
  • Store wiring goes through KvRegistry / ConfigRegistry / SecretRegistry (not the legacy single-handle setters) — see spec §6.6
  • New code has tests
  • No secrets or credentials committed

dhruv8sh and others added 30 commits November 12, 2026 21:38
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
EdgeZeroAxumService does not exist once this meets #275, and #275's check_outbound_legacy_api.sh rejects the name in docs/guide. AxumDevServer::with_trusted_ja4_header is public on both main and #275.
Use the JA4 reconciliation from the audited #439/#502 composition as a reference, without carrying RC history. Preserve #454 Geo preparation and Cloudflare KV imports.
@aram356

aram356 commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Round 12 identity realignment: rc/identity (#495) is now at 38cb74fe. This branch fast-forwarded from 949c0b66 to 2a0150cb:

This PR merges #514 again as a second base, as it did twice before. Spin geo.rs combines this PR's authenticate and lookup split with #514's before_deadline re-arm.

Each merge message says what it carries and how any conflict was resolved.

prk-Jr and others added 5 commits December 2, 2026 23:08
Bring in PR #275's lockfile update, which moves the yanked
pin-project-lite, chacha20 and yoke-derive versions to their
replacements, and PR #454's matching pin-project-lite update in the
geo-kv-prototype lockfile. The merge is clean.
Bring in PR #275's lockfile update, which moves the yanked
pin-project-lite, chacha20 and yoke-derive versions to their
replacements, and PR #454's matching pin-project-lite update in the
geo-kv-prototype lockfile. Both match this PR's own updates, so the
merge is clean.
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.
aram356 added a commit that referenced this pull request Dec 3, 2026
Take PR #515's new head, which brings the yanked-crate lockfile updates
from PR #275 and PR #454, the owner updates on PR #509, #512, #515 and
#519, and PR #514's Spin geo hardening through PR #517.
aram356 added a commit that referenced this pull request Dec 3, 2026
Take PR #464's new head, which carries the lockfile updates and PR
#514's Spin geo hardening through PR #517.
@aram356

aram356 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Round 15 identity realignment: rc/identity is now at ef5cbf308. This branch fast-forwarded from 2a0150cb1 to c6d077723:

This round's link resolves #514's new Spin geo hardening, which makes edgezero_adapter_spin::geo crate-private, against this PR's authenticate and lookup split. It keeps the split, TokenCapture and SpinClientSource, and adopts #514's crate-private module. Trusted Server does not use that module.

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.
# Conflicts:
#	crates/edgezero-adapter-spin/src/geo.rs
@aram356

aram356 commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

Review follow-up: fixes committed to this branch

A 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.

  • Same JA4 fixes as Expose JA4 through a standard request interface #469. 544e9ba, b381dbe and 380431d are patch-identical cherry-picks of Expose JA4 through a standard request interface #469's b4d96cf (IPv4-mapped JA4 trusted-proxy entries), 4f78b22 (JA4 provenance wording) and a1d97b0 (FoxIO nginx module warning), so both PRs carry the same code and text. 794dde5 adds the mapped-entry rule to this PR's CHANGELOG and extends the provenance sentence to cover the fixed CloudFront-Viewer-JA4-Fingerprint header read from a protected CloudFront ALB peer.
  • effective_client_ip() could return a proxy's own address while the docs said it never does. Axum's ClientInfo treats a peer as a proxy only when TrustedProxyPolicy lists it, so an ALB listed only for protected CloudFront Geo, or an nginx listed only in EDGEZERO__ADAPTER__JA4_TRUSTED_PROXY_CIDRS, was reported as DirectPeer. Behaviour is unchanged (the specified DirectPeer row stays); 40e111e corrects the axum.md Client info table and paragraph, both JA4 sections, handlers.md, the effective_client_ip rustdoc and the spec, and tells operators to add those networks to EDGEZERO__ADAPTER__TRUSTED_PROXY_CIDRS with a forwarding header family. Docs only.
  • CHANGELOG still promised Cloudflare geo through CloudflareService. Since ef4a490, CloudflareService and undeclared run_app report UntrustedIngress. f86df0a rewords the bullet: geo needs [adapters.cloudflare.client_info] direct_ingress = true through run_app/dispatch_app, and CloudflareService always reports UntrustedIngress.
  • A JA4 header named like a forwarding header was accepted and then always Missing. The managed Axum listener strips Forwarded and X-Forwarded-* before it captures JA4, so e.g. x-forwarded-ja4 passed startup and reported Unavailable(Missing) on every request with no log. 77bb89d fails startup before listening on such a name, from EDGEZERO__ADAPTER__JA4_* (dev and production) or AxumDevServer::with_trusted_ja4_header, reusing the predicate behind strip_forwarding_headers so the two cannot drift; TrustedJa4Header::parse still accepts it for the unmanaged converter. Tests: managed_ja4_rejects_forwarding_header_names, the extended development_capture_reads_ja4_trusted_proxy_env, and server_rejects_a_forwarding_ja4_header_before_serving, all failing before the change.
  • Root cause of the malformed-prefix ClientInfo case (reported here as well) is fixed on feat(axum): add safe diagnostics and trusted proxy metadata #409 (f45fbc1), which this PR picks up when feat(axum): add safe diagnostics and trusted proxy metadata #409 merges forward.

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 authenticate/lookup split (credential and timeout reasons are reported from authenticate, binding/timeout/store from lookup, never twice), adapts the merged #510 Cloudflare test to (GeoOutcome::NoSelection, ClientInfo::not_exposed()), and adds a ClientInfo projection case for a malformed visitor-written X-Forwarded-For prefix (now Some(client) after #409's fix) with the matching axum.md row wording.

};
assert!(
matches!(capture(trusted), CapturedJa4::Captured { .. }),
"{proxies} should trust {trusted}"

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants