Skip to content

Complete Cloudflare geo and add pinned Spin KV lookup - #514

Open
prk-Jr wants to merge 10 commits into
feature/kv-geoipfrom
feature/480-cloudflare-spin-geo
Open

prk-Jr wants to merge 10 commits into
feature/kv-geoipfrom
feature/480-cloudflare-spin-geo

Conversation

@prk-Jr

@prk-Jr prk-Jr commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Complete portable ctx.geo() coverage with Cloudflare request metadata and Spin lookup against an explicitly pinned KV dataset.
  • Admit one authenticated visitor-IP assertion on Spin, strip private headers before callbacks, and bound request-local preparation and lookup without retaining host handles.
  • Provide a separate operator loader that publishes the existing binary artifacts into Spin KV, verifies them, and stops its temporary loopback runtime.

Stacked on #454 (feature/kv-geoip), which already includes #502. The portable KV reader and Axum foundation are supplied by those parents.

Integration note: a current git merge-tree comparison with #496 reports conflicts in Axum response conversion, Cloudflare/Spin contracts, and core error/extractor code. These siblings need reconciliation when integrated.

Changes

Crate / File Change
edgezero-adapter-spin Manifest/environment selection, authenticated IP admission, pinned async lookup, request-local resources, private immutable geography, and native/WASM contracts
edgezero-core Spin geo configuration placement, bounded configuration namespace inspection, and authenticated-IP provenance
edgezero-adapter-axum Reject Spin-only credential settings on native geo selection
Cloudflare contracts and adapter guides Positive managed-entrypoint metadata coverage, country-only/absence behavior, and forged-header resistance
examples/geo-kv-prototype Expose the existing artifact/publication code to operator consumers without native backend features
examples/geo-spin-loader Separate binary dataset publisher, ephemeral credential, fixed diagnostic categories, finite deadlines, and tested child cleanup
CI and technical documentation Maintain loader checks, admit only their exact standalone unittest command, and document deployment, publication, cold-request cost, and trust boundaries

Spin defaults to off. KV selection requires a declared store, generation/hash pin, authenticated-header reader mode, and a Spin credential-variable name. A trusted proxy must replace and authenticate the original visitor IP; it does not need to supply geography. Both roots and the selected path are verified on each request. Geo errors remain application policy inputs and do not independently grant permission or select HTTP status. No automatic fallback is added.

Closes

closes #480
closes #486

This PR targets feature/kv-geoip, so merging it into that branch does not automatically close the linked issue(s); close them manually or upon default-branch integration.

Test plan

Historical author-reported local verification below (original head unrecorded unless an explicit SHA is given). These results, counts, timings and negative controls were not rerun in this audit, and their underlying local logs were unavailable; checked boxes retain the original report. At the current head ec0b912b, all 29 reported hosted checks are passing.

  • cargo test --workspace --all-targets (3,058 passed; nine ignored)
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check
  • cargo check --workspace --all-targets --features "fastly cloudflare spin"
  • Fastly, Spin and Cloudflare WASM builds, strict lint and maintained suites (Fastly 362; Spin 39 contracts + 25 SDK; Cloudflare 142 library + 31 contracts)
  • examples/app-demo (68 tests + three WASM checks), 32 native feature combinations, 199 tooling tests, generated consumer, and isolated serial harness (679 passed; four ignored)
  • Docs lint, formatting and VitePress build
  • Native and WASM positive KV lookup, duplicate/spoof rejection, admission ordering, original head budgets, pending-work cancellation and aggregate timeout tests
  • Deliberately broken lookup, authentication and IP-removal controls fail their expected assertions; restored geo tests pass
  • Fresh Rust 1.98.1 / Spin 4.1 / SDK 8 runtime: 34 serving, 12 configuration, 13 fault/snapshot cases; fresh binary publication, identical replay and unchanged serving-store snapshots
  • Fresh Cloudflare Worker: 15 real workerd cases with source/artifact identity checks
  • Axum: actual manifest/environment-selected listener returns CloudFront US/CA without a Trusted Server boot profile
  • Operator publisher/loader tests, standalone strict lint and WASM compilation; five runner lifecycle tests including total timeout during a dripping response

Additional diagnostic: native cargo build --workspace --all-targets --all-features cannot link Fastly SDK host imports on ARM64. The same failure is reproduced on unchanged base 925fe019; the supported Fastly WASM suite passes all 362 tests using the prescribed CI runner.

  • Deploy-action tool-policy contract and ten exception-boundary regressions; modified shell/workflow lint

Checklist

  • Changes follow CLAUDE.md conventions
  • No Tokio dependencies added to core or adapter crates
  • Route parameters use {id} syntax
  • Application HTTP types come from edgezero_core
  • Serving store wiring uses the declared KvRegistry
  • New behavior has meaningful tests
  • No secrets, licensed datasets or credentials committed

Local synthetic runtime evidence does not qualify hosted proxy protection, external backend permissions/propagation, geography accuracy or production capacity. Spin SDK reads materialize values before core validates size; guest deadlines do not certify host-side cancellation. The request-local cache repeats manifest/root reads, so operators must qualify backend latency and capacity. Publication assumes one operator per generation; ordinary read-before-write is not a distributed lock.

@prk-Jr prk-Jr self-assigned this Nov 18, 2026
@prk-Jr prk-Jr changed the title Add authenticated Spin geo and verify Cloudflare context Complete Cloudflare geo and add pinned Spin KV lookup Nov 18, 2026
@prk-Jr
prk-Jr changed the base branch from spec/482-axum-geo-manifest-binding to feature/kv-geoip November 18, 2026 14:25
@prk-Jr
prk-Jr marked this pull request as ready for review November 18, 2026 15:50
aram356 added a commit that referenced this pull request Nov 19, 2026
#517 (10ed380) tops ChristianPavilonis's line on #439:
- #510, the KvStore record contract with DynamoDB and celld providers on
  Axum (#472, #473);
- #454, portable KV-backed geo;
- #514, country and region through ctx.geo() on Cloudflare and Spin (#480,
  #486);
- #517, the portable ClientInfo contract with its Fastly, Axum, Cloudflare and
  Spin mappings (#475, #90, #91, #92, #485).

#517 also merged #469 and #502 itself, so its tree contains everything this
branch had. The only conflicts were JA4 lines that #517 refactors on top of
#469; this merge takes #517's version, and its tree is identical to #517's.
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.
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 PR #275's installation of the wasm32-unknown-unknown target
before the Viceroy 0.22.0 readiness repair builds, which the fastly
wasm tests and Portable record contracts (Fastly) jobs need.
@aram356

aram356 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), I pushed 521ad02f, f53d4508 and 49d16cd4.

Bring in PR #275's atomic conditional KV insert in the Viceroy readiness
repair, and the production hosting tests' held port reservations and
spawn-token respawn from PR #406 up, with each later PR's tests reading
the live host's address.
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), I pushed 251074eb, a merge of #454's new head that brings #275's 41cdf035, which makes conditional KV inserts atomic in the Viceroy readiness repair, as the Fastly record contract's native race needs, and the production hosting tests' held port reservations and spawn-token respawn from #406 up, with each later PR's tests reading the live host's address. It had no conflicts.

Bring in PR #275's batch cutoff test fix, which advances the test clock
when the request arms its own deadline instead of after dispatch, and
the AWS emulator proofs' readiness markers from PRs #414 and #510, now
published by rename.
@aram356 aram356 mentioned this pull request Nov 26, 2026
15 of 17 tasks
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), I pushed c12fd631, a merge of #454's new head that brings #275's 0e2a58ae, which fixes an intermittent failure of the batch cutoff test by advancing its clock when the request arms its deadline timer, and the AWS emulator proofs' readiness markers from #414 and #510, now published by rename. It had no conflicts.

aram356 added a commit that referenced this pull request Nov 27, 2026
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.

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

Development

Successfully merging this pull request may close these issues.

Geo with country and region through ctx.geo() on Spin Geo with country and region through ctx.geo() on Cloudflare

2 participants