Repository navigation
Add pluggable native Geo providers and protected CloudFront ingress - #439
ChristianPavilonis wants to merge 28 commits into
Conversation
72ceed7 to
c8ee48f
Compare
#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.
|
For the identity integration branch (#495), I pushed |
|
For the identity integration branch (#495), I pushed |
|
For the identity integration branch (#495), I pushed |
Account for the original request head, then hide the origin credential and raw geographic fields before app callbacks when Geo is selected. Keep ordinary forwarding intact and resolve only after admission. Move the Geo outcome once and rely on the existing body policy for JSON privacy. Cover the startup, forwarding, and dispatch contracts and run the Geo checks only in the workspace CI leg.
|
Review follow-up: 5bf4a674. This is the current-head summary for the older notes in the PR body.
Local checks against the reviewed #422 merge base |
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 (5bf4a674); line numbers refer to it.
Requesting changes for the missing CHANGELOG entry.
Findings
Blocking
- 🔧 CHANGELOG:
## Unreleasedhas no entry for pluggable native Geo providers,RequestContext::geo(), or protected CloudFront ingress. All three are new public surface. #454's "KV-backed Geo" entry refers to "the earlier CloudFront-only API", which has no entry of its own.
CI Status
- GitHub reports no checks at
5bf4a674.
Covers RequestContext::geo(), the edgezero_core::geo types, and opt-in protected CloudFront ingress on Axum.
|
CHANGELOG finding from the review: fixed in dd34d19. |
dhruv8sh
left a comment
There was a problem hiding this comment.
PR Review
Summary
This PR adds a portable, immutable GeoOutcome to RequestContext. It also adds explicit, default-off native Geo selection for managed Axum hosting: a built-in CloudFront parser behind geo-cloudfront and an application-supplied GeoProvider. Both are gated by a separate ProtectedCloudFrontAlb socket-peer policy. The trust boundary is sound:
- Assertions are captured only for an admitted socket peer.
- The credential header and both Geo headers are stripped before the preparer, admission and middleware run.
- The outcome lives in private context storage, so extensions cannot forge it.
- Selection is validated before any runner resource or listener exists.
I found nothing blocking. The findings below are non-blocking suggestions.
😃 Praise
sanitize_received_headstrips the credential before it checks the validation result. A rejected oversized head therefore never carries the credential into the error path. The original head still counts toward limits, and the service test covers both behaviours.- Moving the network parsing into the shared
PeerNetworkslets Geo admission reuse the existing bounds (256 entries, 16 KiB, no whole-family coverage, mapped-IPv4 normalisation) without copying them. Ordinary trusted-proxy policy still cannot admit Geo, and thegeo-supplied-untrustedhosting fixture proves that end to end. - The forged-extension contract tests on Fastly, Cloudflare and Spin, plus
geo_owned_outcome_survives_public_request_mutation, pin down thatctx.geo()cannot be replaced from public state. scripts/check_geo_dependency_contract.shchecks thatgeo-cloudfrontadds no dependencies and that portable crates stay isolated. It fails closed on empty or malformedcargo treeoutput.
Findings
Blocking
None.
Non-blocking
- 🤔 Other
CloudFront-Viewer-*headers stay untouched: with Geo selected, onlyCloudFront-Viewer-CountryandCloudFront-Viewer-Country-Regionare removed. Headers such as-City,-Postal-Codeand-Latitudestill pass through from any peer (crates/edgezero-adapter-axum/src/geo.rs:316). - ♻ Keep
NativeHosting: Debug: a redacted manualDebugonNativeGeowould avoid dropping the derive and the.err().expect(..)test churn (crates/edgezero-adapter-axum/src/dev_server.rs:515).
📌 Out of Scope
default_dispatch_preserves_serde_json_error_detailincrates/edgezero-core/src/app.rstests JSON error detail, not Geo. It would fit better in its own change.
| return None; | ||
| }; | ||
| let admitted = policy.admit(peer, headers); | ||
| let _country = headers.remove(VIEWER_COUNTRY); |
There was a problem hiding this comment.
🤔 Only two of the CloudFront-Viewer-* headers are removed: with Geo selected, take_assertions strips cloudfront-viewer-country and cloudfront-viewer-country-region. Other generated headers still pass through unchanged from any peer, including unadmitted ones: CloudFront-Viewer-City, -Postal-Code, -Latitude, -Longitude, -Time-Zone, -Country-Name, -Country-Region-Name, -Metro-Code, -ASN and -Address.
This matches the documented contract ("both raw Geo fields"). But an operator who turns this on has signalled that this deployment sits behind CloudFront. An app that reads, say, CloudFront-Viewer-City straight from headers will reasonably assume that header gets the same protection, and it doesn't.
Two options:
- Make it explicit in
native-geo.mdthat only the two v1 fields are stripped, and that the otherCloudFront-Viewer-*headers stay spoofable. - Or, while Geo is selected, strip every
cloudfront-viewer-*name, keeping the two bounded captures as they are. For example:
let _country = headers.remove(VIEWER_COUNTRY);
let _region = headers.remove(VIEWER_REGION);
// Optionally: drop the whole generated family so none of it reaches the app unadmitted.
let generated: Vec<HeaderName> = headers
.keys()
.filter(|name| name.as_str().starts_with("cloudfront-viewer-"))
.cloned()
.collect();
for name in generated {
let _removed = headers.remove(name);
}| } | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| #[derive(Clone)] |
There was a problem hiding this comment.
♻ Keep NativeHosting: Debug with a redacted NativeGeo impl: the derive was removed because NativeGeo holds Arc<dyn GeoProvider + Send + Sync>. That cascades into the .expect_err(..) → .err().expect(..) rewrites in the existing tests at L2387/L2399.
A small manual impl, matching the redaction style already used for NativeGeoSelection, keeps the derive and the original tests:
impl fmt::Debug for NativeGeo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Off => f.write_str("Off"),
Self::Selected { policy, id, .. } => f
.debug_struct("Selected")
.field("policy", policy)
.field("id", id)
.finish_non_exhaustive(),
}
}
}| } | ||
|
|
||
| #[test] | ||
| fn default_dispatch_preserves_serde_json_error_detail() { |
There was a problem hiding this comment.
📌 Unrelated test: default_dispatch_preserves_serde_json_error_detail checks JSON error-message detail on default dispatch and has nothing to do with Geo. It's a useful regression test, but it would be easier to track in its own PR, or at least with a line in the PR description explaining why it's here.
prk-Jr
left a comment
There was a problem hiding this comment.
PR Review
Summary
Follow-up review at dd34d19d. I checked the code for both of my earlier blocking items, and both are fixed. The protected CloudFront ingress path now behaves as documented: the credential header and the raw Geo fields are gone before any application callback runs; only the owned socket peer can admit input; and an absent or nonmatching peer becomes UntrustedIngress, never a located result. I found no new blocking issues, so I'm approving. The only notes left are optional.
😃 Praise
sanitize_received_headputs the order in one place: validate and count the original head, strip the credential even if validation fails, capture input only for a matching peer, remove both raw Geo fields, and only then call the preparer.- The new tests catch a regression. I moved
strip_credential/take_assertionsback afterprepare_received_head, and bothreceived_head_preparation_sees_forwarder_auth_but_not_selected_geo_fieldsandgeo_managed_resolution_runs_once_from_owned_ingressfailed. I then restored the code. geo-supplied-untrustedcovers the forwarding-trust gap I raised earlier: trusted proxy127.0.0.1,X-Forwarded-For: 192.0.2.1, Geo policy192.0.2.1/32. The effective client is192.0.2.1and the outcome is stilluntrusted_ingress.- Every path that takes
AxumRunOptionsgoes throughrun_production_selected, which callsoptions.native_geo()?before any runner resources exist. A selection can't be silently dropped toOff.
Prior findings status (my review at 3a0e5eb4)
- ✅ Credential header visible to the received-head preparer (blocking ❓): fixed.
service.rs:329-335strips the credential beforevalidation?and calls the preparer last. The router rustdoc (router.rs:391,:762) and the guide (native-geo.md:197-200,:261-263) now say the same thing. - ✅ Geo CI steps run in every matrix leg (blocking 🔧): fixed. All nine Geo steps in
.github/workflows/test.yml:189-235haveif: matrix.suite == 'workspace'. - ✅ No test shows that forwarding trust can't admit Geo (🤔): covered by the
geo-supplied-untrustedhosting mode (production_hosting.rs:2487-2513). - ✅ Reserved credential names vs. doc comment (⛏): the rustdoc now lists the actual prefixes and names (
geo.rs:143-145). Not reservingx-edgezero-*is a reasonable choice. - ✅ Nothing pins the detailed JSON error on the
Defaultpath (⛏):default_dispatch_preserves_serde_json_error_detailnow checks the exactinvalid JSON payload: <serde detail>text. - ✅ Duplicate
dep:ipnet/dep:getrandom(⛏): removed. - 📝
#[non_exhaustive]on the public Geo types: deferred to #502 by the author. Fine with me, since it's acknowledged. - ⛏ Stale PR description: still open, see below.
For other reviewers' threads: aram356's CHANGELOG request is addressed by dd34d19d, and the entry matches the code.
Findings
Blocking
None.
Non-blocking
- 🤔 Only the two consumed
CloudFront-Viewer-*fields are stripped (docs/guide/native-geo.md:197). See the inline comment. - ⛏ PR description is still stale. The "Owned follow-up review checkpoint" names
63650628as the current head, and "Current review-stack checkpoint" names414e52ae. The head isdd34d19d, and the description doesn't mention the5bf4a674sanitization change. A short "current head and what changed" section would help.
CI Status
These checks ran locally on 5bf4a674 with Rust 1.98.1. The only change since then is the CHANGELOG commit dd34d19d.
- fmt (
cargo fmt --all -- --check): PASS - clippy (
-p edgezero-core -p edgezero-adapter-axum --all-targets --all-features -D warnings): PASS cargo test -p edgezero-core --all-targets: PASS (1185 lib tests plus doc/integration targets)cargo test -p edgezero-adapter-axum --all-targets --all-features: lib 500 passed; contract, AWS/celld startup and the other targets passed.production_hostingpassed 32 and failed 4. The 4 failures are the existing proxy/TLS tests that need127.0.0.2/127.0.0.3on loopback, which macOS doesn't have by default. That is the same pre-existing, out-of-scope failure aram356 reported earlier; allgeo_hosting_*tests passed.- Hosted CI: GitHub reports no checks for this head, so there is no hosted result to cite. The Geo feature-matrix CI steps, WASM runtime contracts and the dependency script were not rerun locally.
| let validation = | ||
| validate_normalized_ingress_parts_with_summary(parts, self.app.ingress_head_limits()); | ||
| self.geo.strip_credential(&mut parts.headers); | ||
| let received = validation?; | ||
| let assertions = self.geo.take_assertions(peer, &mut parts.headers); | ||
| self.app | ||
| .prepare_received_head(&parts.headers, &mut parts.extensions); |
There was a problem hiding this comment.
😃 This is the ordering I was asking for. The original head is still validated and counted first. The credential is removed before validation?, so even a rejected head never keeps it. Peer-gated capture and raw-field removal both happen before the preparer. I also checked that the tests catch a regression: moving strip_credential/take_assertions after prepare_received_head fails both service tests.
| With Geo selected, the managed Axum runner removes every instance of both raw Geo fields before | ||
| the received-head preparer, admission callbacks, and middleware, even if the socket peer does | ||
| not match the protected policy. The original fields still count toward head limits. With Geo | ||
| `Off`, the headers are untouched and carry no trust. Read `ctx.geo()` for checked facts. |
There was a problem hiding this comment.
🤔 Only the two consumed CloudFront-Viewer-* fields are stripped
With Geo selected, take_assertions removes cloudfront-viewer-country and cloudfront-viewer-country-region. Every other CloudFront-generated header stays in ctx.headers() and can be spoofed by a nonmatching peer the same way. That includes CloudFront-Viewer-City, -Postal-Code, -Latitude, -ASN, -Address and CloudFront-Is-*-Viewer. That's consistent with v1's scope; I'm not asking to strip more. But this paragraph tells readers to "Read ctx.geo() for checked facts", and someone could take that to mean the other viewer headers are cleaned up too. Consider one sentence along the lines of: "Other CloudFront-Viewer-* and CloudFront-Is-* headers are not removed or authenticated by EdgeZero; treat them as client-controlled." Non-blocking.
Current review readiness
Ready for review. Required current-head CI passed at
414e52ae41ee95880fd11238a22ad2dc944f44c2: test run 42924133045.Minimal fixes originate in #414 and are merged upward:
Deadline; non-timeouts remainUnavailable. The previously failing hosted timeout test and all 78 provider cases now pass without assertion, retry or duration changes.aws-types =1.6.0andaws-smithy-runtime-api =1.19.0. This prevents the schema mismatch and preserves the explicit older behavior version instead of switching retry policy or suppressing deprecations. A fresh consumer passes with compiler and Clippy warnings denied throughout.Local final-top Axum checks pass 488 unit, 28 contract, six AWS startup, four celld startup and 36 hosting cases. Final-top workspace strict Clippy and formatting pass. The prior stable checkpoint passed all six mandatory commands; unchanged inputs retain their receipts, while fresh current-head CI checks the combined state. The current ready state supersedes historical draft-only prerequisites below; unexecuted deployment acceptance is not claimed complete. An additional Fastly WASM runtime job was still running at transition and is not counted as passed. No TS work or deployment qualification is a review prerequisite. Integration #462 remains draft; reviewers
aram356,prk-Jranddhruv8shremain requested. Stack465 and PR bases are unchanged; #453 is excluded.Current review-stack checkpoint
Publication head:
414e52ae41ee95880fd11238a22ad2dc944f44c2. This cleanup preserves the existing feature unit and PR identity. The additional change is the completed generated-native build correction: image-only code now follows the scaffold's existing Fastly-example selection, with no request-policy change. Its focused generator/native proof is retained; fresh per-branch hosted checks are not assumed green.Review order: #275 → #406 → #407 → #409 → #414 → #422 → #439 → #454. Draft integration checkpoint: #462. New SDK/group/codec/phase development and unrelated TS work are not prerequisites or additions to this PR. Earlier notes below retain their original tested revisions and limits; they are not a whole-tree pass for this new head.
Earlier implementation and proof notes
RC refresh checkpoint, 2026-11-10
Current head:
c8ee48fcea9828095640a0fa8e593fb59c6d57fa.Geo-only behavior is ported onto current #409/#422 instead of restoring repeated older dispatch/body code. Built-ins remain synchronous and local. One private outcome is captured from owned ingress and retained through the managed pre-dispatch seam. Native
trusted_proxynaming keeps the outbound hard-cut guard byte-unchanged, without the old exemption.Feature core/native/all-feature, Geo-wire and disabled-feature checks, dependency isolation, strict Clippy, docs/actionlint/format pass. Independent source review found no credible introduced defect. Lower CI/fixture fixes are merged; all five locked fetches and 35 CI tooling cases pass.
Protected CloudFront is a composition: ALB validates the credential value externally; EdgeZero checks the actual socket-source policy and strips the selected credential header, including normalized-head errors, before relevant application callbacks. No live ALB/CloudFront source qualification is claimed. Arbitrary unmanaged
ctx.into_requestplus a fresh context deliberately resets Geo to NoSelection. This adds no production KV Geo provider or local MaxMind implementation. The admitted-error finalizer is a separate follow-on.Draft pending fresh hosted checks and the combined RC audit. Two unchanged native default-parallel deadline misses remain recorded and unclassified; serial passes and untouched-foundation parallel passes do not clear them. No timing bound was relaxed. No deployment, main merge, security-alert dismissal or review-thread resolution occurred. Historical design/review context follows.
Summary
Stack and prerequisite reconciliation
Base branch:
feat/native-celld-stores, draft #422 at5426ea65. This PR stays on top of the existing native celld stack.Although the GitHub stack names #409 as an ancestor, this base did not contain its checked-ingress implementation. This diff therefore also reconciles the pinned
66a05e25checked-ingress/proxy/diagnostics contract. It adapts that commit's own delta while preserving newer native stores, local non-Send initialization,Connections/FuturesUnordered, bounded ingress/config snapshots and asynchronous response EOF validation. The existing forwarding parser supplies the shared bounded peer-network matcher.The distinct #407 buffered JSON-cap/managed Body feature is not imported or claimed. Native JSON error privacy is retained through private admitted/context state. The plan records exactly which #407-dependent cap/carrier checks are excluded. No old branch tree replaced newer files.
Changes
edgezero-core::geoctx.geo(), default NoSelection on legacy/unmanaged paths, preserved framework error privacy and egress classification.AxumRunOptions, capability inspection through finalized options, startup rejection before runner resources, native-only Arc thread bounds.Issue scope
Closes #432. Implements the CloudFront and synchronous Geo contract under #391. Local GeoIP databases, checked-reader-IP input and database lifecycle are tracked separately in #438 and are not included in this PR.
Trusted Server adoption and jurisdiction/consent interpretation remain separate. Geo is an estimate, not proof of residence, identity or consent. Country-only and unrecognized subdivisions stay unknown to application policy.
Test plan
cargo test --locked --workspace --all-targets: 2,115 passed, 6 existing generated-consumer/real-service tests ignored.cargo test --locked -p edgezero-adapter-axum --all-targets --all-features: 422 passed, including mixed AWS/celld startup, preserved lifecycle/EOF tests and 32 hosting tests. Provider service fixtures are loopback-only.cargo clippy --locked --workspace --all-targets --all-features -- -D warnings, disabled-native Clippy,cargo fmt --all -- --check,git diff --check.fixture-axumchecked against its updated lockfile.edgezero serve --adapter axum. Programmatic production-runner and real-listener tests were used instead; no Geo CLI selector is introduced.Tested implementation is
56eab85f; the later commit records evidence/status only. Exact commands, tested feature sets, timings, local logs and ignored-test limits are in the implementation plan. No failing local gate is excluded.Trust and acceptance limits
The protected policy declares an externally credential-gated and isolated ALB path. A matching subnet does not authenticate a distribution or prove that its listener rules are correct. EdgeZero does not receive the configured credential value or call AWS to inspect/provision infrastructure.
Production use still requires deployed proof of the credential gate, target isolation, viewer-header replacement including AWS-network missing-subdivision spoofing, value rotation and shared-cache/error-TTL isolation. The guide requires HTTPS, a default-deny ALB, CloudFront origin-facing prefix-list restrictions, private target access, explicitly generated geographic headers and disabled shared caching. No deployment was attempted.
The six existing ignored generated/service harnesses were not counted as passes. Unchanged docs dependencies report seven npm audit vulnerabilities; no unrelated dependency upgrades were attempted. ShellCheck was unavailable; Bash syntax, behavioral failure cases and real graph checks passed.
Checklist
CLAUDE.mdconventions and scoped ownership.Owned follow-up review checkpoint
6365062820d924b314fc52930ccbdbe252fb6b49. Source treee229fa851df5edc0ec751bb523eab18623191d1eis byte-identical to previous head3a0e5eb43cdb9e20076b47fcede31d3e1b52f862.