Skip to content

Answer identify and batch sync locally on every adapter - #1614

Open
dhruv8sh wants to merge 15 commits into
spec/edgezero-pr275-migrationfrom
feat/identify-batch-sync-local-all-adapters
Open

dhruv8sh wants to merge 15 commits into
spec/edgezero-pr275-migrationfrom
feat/identify-batch-sync-local-all-adapters

Conversation

@dhruv8sh

Copy link
Copy Markdown
Collaborator

Summary

  • Partner API requests leaked to the publisher origin. On Axum, Cloudflare and Spin, GET /_ts/api/v1/identify and POST /_ts/api/v1/batch-sync had no route, so they fell through to the publisher fallback, carrying the partner's Authorization: Bearer token and mapping body with them. On every adapter, Fastly included, any other method on those paths did the same. This PR answers every request on both paths locally (ID-3 of the server-side identity spec).
  • With an EC record store, identify and batch sync run as before (Fastly only today). Without one, they return a local 501 {"error":"ec_store_not_configured"}, and Fastly with ec.ec_store unset now returns 501 instead of its old 503 store error. Every other method returns 405 with an Allow header (GET, OPTIONS for identify, POST for batch sync). The store-less identify 501 applies the same origin policy as the store-backed path: 403 for a denied browser origin, and reflected CORS headers for an allowed one so the browser can read the 501.
  • A new CapturingOrigin test fixture records every request that reaches the publisher fallback. Each adapter's route tests use it to prove that no identify or batch-sync request, on any method, reaches the origin. A positive control shows that a normal page request does reach it.

Changes

File Change
crates/trusted-server-core/src/ec/identify.rs identify_not_supported(settings, req): 501 behind the identify origin policy. identify_method_not_allowed(): 405 with Allow: GET, OPTIONS. answer_identify_locally(): picks the response by method. Tests
crates/trusted-server-core/src/ec/batch_sync.rs batch_sync_not_supported() (501), batch_sync_method_not_allowed() (405 with Allow: POST), answer_batch_sync_locally(). Tests
crates/trusted-server-core/src/test_support.rs capturing_origin::CapturingOrigin fixture, behind test/test-utils
crates/trusted-server-adapter-fastly/src/app.rs Both paths claim every method. Without ec.ec_store, answers 501 (was 503). Other methods get 405. Test-only #[cfg(test)] services_override on AppState, so route tests can dispatch through the capturing origin. Tests with and without a store
crates/trusted-server-adapter-axum/src/app.rs, tests/routes.rs Routes both paths on every method to the core local answers. Tests
crates/trusted-server-adapter-cloudflare/src/app.rs, tests/routes.rs Same as Axum
crates/trusted-server-adapter-spin/src/app.rs, tests/routes.rs Same as Axum. Removes the stale comment that called these paths intentionally unrouted
docs/guide/api-reference.md Route availability table (identify GET and OPTIONS rows split). Identify and batch-sync contracts updated for 501, 405 and the origin policy

Notes:

  • The store-present ("runs") tests exist only on Fastly. Axum, Cloudflare and Spin have no EC record store on main, so they always answer 501. Plan tasks T8, T9 and A2 bring stores to those adapters.
  • services_override compiles out of non-test builds. Only the Fastly route tests set it.
  • Fastly answers 501 only when ec.ec_store is unset. A configured but unlinked store behaves as before: identify returns a degraded 200 and batch sync rejects items as kv_unavailable.
  • Admin lookup (already 501 locally) and pull sync (outbound only) are unchanged.

Closes

Closes #1582

Spec

Spec: server-side identity on every adapter, ID-3 (plan task T1 of #1558)

Test plan

  • justrust cargo test-fastly && justrust cargo test-fastly-reuse && justrust cargo test-axum && justrust cargo test-cloudflare && justrust cargo test-spin
  • justrust cargo clippy-fastly && justrust cargo clippy-axum && justrust cargo clippy-cloudflare && justrust cargo clippy-cloudflare-wasm && justrust cargo clippy-spin-native && justrust cargo clippy-spin-wasm
  • justrust cargo fmt --all -- --check
  • JS tests: cd crates/trusted-server-js/lib && npx vitest run (Node 24.20.0 via mise)
  • JS format and lint: cd crates/trusted-server-js/lib && npm run format && npm run lint
  • Docs format: cd docs && npm run format
  • WASM build: cargo build --package trusted-server-adapter-fastly --release --target wasm32-wasip1
  • Manual testing via fastly compute serve
  • Other: capturing-origin route tests on all four adapters (store absent: 501; store present on Fastly: real handlers, 401; every other method: 405; origin receives nothing)

Checklist

  • Feature PRs: spec linked above, ending in a review log of two or more agent review rounds
  • Changes follow AGENTS.md conventions
  • No unwrap() in production code — use expect("should ...")
  • Uses log macros (not println!)
  • New code has tests
  • No secrets or credentials committed

Adapters without an EC record store answer these partner APIs locally instead of proxying them to the publisher origin. Also add a capturing origin fixture so adapter route tests can prove a request never reaches the origin.

Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
The dev server has no EC record store, so identify and batch sync return 501 and the identify preflight is answered locally; none reach the publisher origin.

Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
Cloudflare has no EC record store, so identify and batch sync return 501 and the identify preflight is answered locally; none reach the publisher origin.

Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
Spin has no EC record store, so identify and batch sync return 501 and the identify preflight is answered locally; none reach the publisher origin.

Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
Without ec.ec_store, identify and batch sync now return the local 501 instead of a 503 store error. Route tests dispatch through a capturing origin to prove neither request reaches the publisher, with and without a record store.

Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
Identify and batch sync now claim every method on Fastly, Axum, Cloudflare and Spin. Methods other than GET/OPTIONS on identify and POST on batch sync answer 405 with an Allow header, so no request or partner Bearer token on these paths reaches the publisher origin.

The store-less identify 501 now applies the identify origin policy: a denied origin gets 403 and an allowed one gets reflected CORS headers. Also document the panic contract on batch_sync_not_supported.

Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
@dhruv8sh dhruv8sh self-assigned this Nov 16, 2026
Signed-off-by: dhruv8sh <dhruv8sh@proton.me>

@ChristianPavilonis ChristianPavilonis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

The adapter routing consistently keeps identify and batch-sync requests out of publisher fallback. Store-less responses reuse the shared method and origin policies, while Fastly retains the store-backed handlers. Capturing-origin tests include positive controls across all four adapters.

Reviewed head 3228f4cccf74aae9c8a21dd67ff0796b7ce38d3f against merge base 1810c763add220dd34fd5faaffe2c69aab1d556f.

CI Status

  • integration tests (Fastly EC lifecycle): PASS
  • integration tests: PASS
  • browser integration tests: PASS
  • trace runtime and browser acceptance: PASS
  • CodeQL: PASS
  • cargo check/build/test (spin native + wasm32-wasip1): PASS
  • cargo check (cloudflare native + wasm32-unknown-unknown): PASS
  • Analyze (javascript-typescript): PASS
  • Analyze (actions): PASS
  • vitest: PASS
  • ts dev lint domains (changed lines): PASS
  • cargo test (ts CLI, native) (ubuntu-latest): PASS
  • HTML EOF runtime (Fastly): PASS
  • cargo test: PASS (required)
  • cargo test (cross-adapter parity): PASS
  • cargo test (axum native): PASS
  • docs-proposal scripts: PASS
  • Analyze (rust): PASS
  • worker-deadlines (spin): PASS
  • prepare integration artifacts: PASS
  • format-docs: PASS (required)
  • cargo fmt: PASS (required)
  • release scripts: PASS
  • CLAUDE.md symlink guard: PASS
  • format-typescript: PASS (required)
  • CI Node pin guard: PASS
  • cargo test (ts CLI, native) (macos-latest): PASS
  • worker-deadlines (cloudflare): PASS
  • Analyze (javascript-typescript): PASS
  • Analyze (python): PASS

T1 now builds on the EdgeZero cutover, so the partner API change ports onto
#1506's adapters:

- Core batch sync keeps T1's local 501 and 405 answers next to #1506's async
  handle_batch_sync_with_writer.
- Fastly takes #1506's per-request services. The identify and batch-sync
  handlers answer locally unless the method is the primary one and an EC
  record store is configured, and both paths claim every method.
- The route tests drop the CapturingOrigin fixture, which implemented the
  platform HTTP client #1506 removed. They route through #1506's scripted
  outbound client instead and assert that no partner API request reaches
  it; a control test shows a publisher page does reach it.
@aram356
aram356 changed the base branch from main to spec/edgezero-pr275-migration November 17, 2026 18:03
aram356 added a commit that referenced this pull request Nov 17, 2026
#1614 now carries #1506's EdgeZero cutover, so #1525's per-provider HTTP
opt-in meets the cutover here, resolved the way rc/identity resolved it in
30a74de:

- The endpoint rule is the union: https, plain http to loopback (#1506), or
  any http with allow_insecure_http (#1525).
- Cloudflare keeps #1506's startup_loads_multi_provider_plan; the dormant
  multi-provider test is dropped because the cutover loads every plan.
- #1506's test ProviderConfig literals in the Fastly app and the auction
  orchestrator gain allow_insecure_http: false.
@aram356
aram356 added this pull request to stack #1621 November 17, 2026 18:05
aram356 added a commit that referenced this pull request Nov 17, 2026
#1525 now carries #1506's EdgeZero cutover and #1614, so #1526's awaitable EC
persistence meets them here. The resolution is the one rc/identity made in
30a74de and 4a414a0:

- Fastly runs the async EC finalize from finalize_response, which EdgeZero
  calls after its dispatch executor returns, and drops edgezero_main.
- Pull sync and batch sync keep #1506's EdgeZero send paths with #1526's
  awaits, and their KV-touching tests become async, including #1506's
  pull-sync group failure test.
- The post-delivery test blocks on the now-async snapshot load.

#1614's identify handler awaits #1526's async handle_identify.
@aram356

aram356 commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

This PR now builds on #1506's EdgeZero cutover, so it can join the identity integration branch (#1608) as a plain merge. 9627ca12a merges #1506's head 47a539528 into this branch and ports T1 onto the cutover; git show --remerge-diff 9627ca12a shows the port.

Area Port
Core batch sync Keeps this PR's batch_sync_not_supported, batch_sync_method_not_allowed and answer_batch_sync_locally next to #1506's async handle_batch_sync_with_writer
Fastly Takes #1506's per-request services. Identify and batch sync answer locally unless the method is the primary one and an EC record store is configured, and both paths claim every method, as before
Spin The two handlers take the request with ctx.into_request()?, the cutover's request API
Route tests, all four adapters CapturingOrigin implemented the platform HTTP client #1506 removed, so it is dropped. The tests route through #1506's scripted outbound client and assert that no partner API request reaches it. The control test that shows a publisher page does reach the origin now sends a body-less GET, because the cutover refuses a GET that carries body bytes

The base is now spec/edgezero-pr275-migration, so the diff still shows only this PR's changes, and the PR lands after #1506. Checked locally at 9627ca12a: cargo fmt, the six adapter clippy aliases, test-axum (63), test-cloudflare (65), test-spin (88) and test-fastly (3,729), all passing.

The chain is GitHub stack 1621: #1506, #1614, #1525, #1526, with the provider stack (#1487 to #1489) to join its top once it is ported.

The partner API requests target publisher.example.com, and the fallback control test scripts the origin URL from the test settings, as the cutover's other Fastly tests do.
aram356 added a commit that referenced this pull request Nov 17, 2026
Takes #1614's 9552a89, which moves its ported Fastly partner API tests onto allowlisted example hosts.
aram356 added a commit that referenced this pull request Nov 17, 2026
Takes #1525's f5d8b7f, which brings #1614's move of its ported Fastly partner API tests onto allowlisted example hosts.
aram356 added a commit that referenced this pull request Nov 17, 2026
… rc/identity

#1526's head b53c6e2 now stacks on #1525 (f5d8b7f), which stacks on #1614 (9552a89), which stacks on #1506. Each PR merged the one below it and resolved its own conflicts, so this merge needs no resolution. #1525's and #1526's resolutions against #1506 are the ones this branch made in 30a74de and 4a414a0, and #1614 (T1) is new here.
aram356 added a commit that referenced this pull request Nov 17, 2026
Brings PR #1487 onto PR #1526's base (PR #1506's EdgeZero cutover, PR #1614,
PR #1525 and PR #1526's awaitable EC persistence) and keeps PR #1487's
behavior in the new base's structure.

How each area was resolved:

- Provider lookups: the lookup transport now sends through EdgeZero's
  outbound client in the auction fan-out's shape. `LookupTransport::start`
  takes every built request and starts them as one batch with
  `HttpClient::start_batch_until` and a cutoff of the identity budget,
  taken on the client's own clock;
  `gather` reads the batch until it finishes, maps slots back to providers
  and reports unresolved slots as timeouts. `PlatformLookupTransport` and the
  coordinator's web-time `Deadline` are replaced by `OutboundLookupTransport`;
  requests keep the 64 KiB response cap, cache bypass and strict TLS.
- Deleted modules: `platform/http.rs` and the Fastly `platform/deadline.rs`
  stay deleted. PR #1487's final-snapshot change to the Fastly deadline
  select (a 1 ms surfacing wait per pending body and counting arrived headers
  as progress) has no counterpart in EdgeZero's batch and is not ported, nor
  is its doc-only change to `select_until`.
- Async KV: `ec/kv.rs`, `ec/mod.rs` and `ec/finalize.rs` take PR #1487's
  versions converted to PR #1526's async store; the page-load and
  after-response writes, the write planner, after-response commit, batch
  sync's provider-owned check and their tests await the store. Unchanged
  tests take PR #1526's async versions, and PR #1526's non-Send yielding
  store test is kept. `generate_if_needed` stays async as on the base.
- Fastly entry point: `main.rs` takes the base's lifecycle. `finalize`
  collects the navigation's page-phase lookups inside the async EC finalize
  under its one `block_on`, using the partner registry built once in
  `AppState`. After-response lookups run in post-delivery work, after pull
  sync, on the post-delivery client and clock. Lookups still travel through
  the request-local slot, because an in-flight batch is not `Send`; the slot
  is now cleared before each request and after delivery.
- Fastly app: keeps the base's local 501/405 identify and batch-sync answers,
  publisher origin options and response-body scope owner, with PR #1487's
  partner registry, identity coordinators, navigation permit and dispatch.
- Other adapters, core call sites and tests: kept both sides; PR #1487's
  tests that used the removed platform HTTP client or a custom auction
  provider now use the scripted outbound client, and the Fastly identity
  tests route with the host geo lookup the entry point's `prepare` runs.
- Cargo: the lockfile adds only the identity-providers crate to the base's.
- Docs and CHANGELOG: auction collection text follows the base; PR #1487's
  identity entries and spec now describe the EdgeZero batch transport.
@dhruv8sh
dhruv8sh removed this pull request from stack #1621 November 18, 2026 16:50
aram356 added a commit that referenced this pull request Nov 19, 2026
Core identity app. IdentityApp now carries the provider stack's identity
state as well as its own: the partner registry, the page and after-response
provider coordinators (#1487, #1489), the EC record store and the rate
limiter. IdentityPlatform takes an optional IdentityProviders (the registry
the coordinators were built against plus both coordinators); without one the
app builds the registry with PartnerRegistry::from_ec and runs no provider,
matching the base's non-Fastly adapters. The admin EC lookup awaits the async
handler from #1526.

Send and Sync. #1526 keeps EcKvStore free of Send and Sync bounds and tests a
non-Send store, so the T21 supertrait bounds on EcKvStore and RateLimiter are
dropped. The identity app instead holds its record store and rate limiter as
Send and Sync trait objects, and IdentityApp::identity_graph hands out a graph
over that one shared store through the new KvIdentityGraph::from_shared.
IdentityPlatform's identity_graph field becomes record_store accordingly.

Fastly app. AppState drops the base's partner_registry, page_identity and
after_response_identity fields for the identity app. build_identity_app builds
the kind-aware registry and both coordinators from the identity-providers
crate, then the app with Fastly's record store and rate limiter. Page lookups
and after-response preparation read their coordinators and rate limiter from
the identity app; identify, batch sync, auction, page bids and the publisher
fallback use its registry and graph. The admin lookups stay mounted by the
identity app, so the base's async admin early dispatch is removed.

Fastly entry point. finalize_response keeps the base's single block_on around
the async EC finalize, which collects the page lookups first. FinalizeInputs
keeps the base's AppState, and FinalizeState carries the identity app and the
after-response lookups. maybe_identity_graph is gone; the test-only
require_identity_graph reads the identity app's graph.

Post-delivery. The after-response providers, pull sync included, take the
partner registry, graph and rate limiter from the identity app carried in
FinalizeState. The base's pull-sync tests build their state through the
identity app.

Axum, Cloudflare and Spin. The identity app mounts the admin lookups; the
base's provider rejection at startup and #1614's local 501 and 405 partner API
answers are kept.

Tests. The core identity app tests use record stores and the async graph, and
two tests cover the carried registry and coordinators. The Fastly identity
fixture builds an identity app around its echo-provider coordinator. The
adapter identity guard replaces dispatch_pull_sync, which #1489 deleted, with
commit_after_response_lookups and also guards PartnerRegistry::from_ec.
Takes #1506's new head feaf3df, which brings #1506's repin of
EdgeZero to rc/identity at 9d02d7b3. The merge is clean, and this PR's tree
changes only by that repin.
aram356 added a commit that referenced this pull request Nov 19, 2026
Takes #1614's new head bf7a363, which brings #1506's repin of
EdgeZero to rc/identity at 9d02d7b3. The merge is clean, and this PR's tree
changes only by that repin.
@aram356 aram356 mentioned this pull request Nov 19, 2026
20 of 21 tasks
Takes #1506's new head c197404, which repins EdgeZero to rc/identity at
d063a8e7 and merges main's Fastly SDK 0.13.3 upgrade (#1671): fastly 0.13.3,
url 2.5.9 and Viceroy 0.22.0. The merge is clean.
aram356 added a commit that referenced this pull request Nov 25, 2026
…1622 into rc/identity

#1622 (244ca26) now carries the whole chain, each PR merging the one below
it:

- #1506 (c197404) repins EdgeZero to rc/identity at d063a8e7, which
  carries EdgeZero main's Fastly SDK 0.13.3 upgrade through every EdgeZero PR
  here, and merges Trusted Server main's upgrade (#1671): fastly 0.13.3, url
  2.5.9 and Viceroy 0.22.0.
- #1614, #1525, #1526, #1487 and #1488 take it in turn. #1488 also adds
  b2d4bfd, which records known UID hashes with a setter.
- #1489, the identity spine (#1639, #1640, #1612, #1628 and #1623), #1531 and
  #1532.
- The Axum serving line: #1613, #1616, #1617, #1615, #1635, #1637 and #1627,
  chained, with #1627's b958107 decoding the Spin discovery document with
  Response::json and #1627's merge of #1625, which brings #1625's Wrangler pin
  into the chain.
- The held line on #1627: #1533, #1534, #1536, #1535, #1537, #1539, #1538,
  #1540, #1566, #1624, #1641, #1642 and #1646. #1646 keeps its own shared
  after-response runner in ec::app::lookups.
- #1636 (72096cd) on #1646 (b5a5f62), draining Axum
  after-response identity tasks on SIGTERM through #1646's shared runner.
- The EC route line on #1636: #1626 (067531e), which merges #1636, the
  draft #1656, #1661, #1662 and #1622, and through #1622's merge of it,
  #1620's round-6 head.

Each conflict was resolved in the PR that sits higher. This merge is clean.

Since the last update the chain also takes #1488's hashed-email intake
(a610152 and 9104fd3) and its POST, body and header options for the
status call (f063a76), #1627's split of the generic runtime KV store into
trusted_server_runtime_kv (4d0c1a2), #1646's gate on identity writes for
rejected clients (aa31559) its native container test of the failure router
(4f4c036) and that test's header check on an ordinary route (71a573a),
#1626's withholding of a mirrored UID while another source owner is opted
out (d07f789), and #1617's description of the Axum startup failure router
(6d174a8) and of the startup failures that still exit before listening
(4c07cad). #1636 no longer sits in the Axum serving line; it arrives
through #1626, which merges it on top of #1646. Its new head adopts #1646's
after-response runner in place of the one rc/identity took with cf1102c.

Cloudflare guide: #1627's merge of #1625 now keeps both #1625's tool version
clause and #1627's TRUSTED_SERVER_RUNTIME_KV binding in the smoke paragraph,
and fixes #1625's smoke script test for #1617's Python floor and Worker
build, and #1537's merge fixes its ts stub for #1537's storage template
step, so this merge needs no resolution.
@aram356

aram356 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#1608), I pushed 9e08a9bb2, a merge of #1506's new head c1974041f. It repins EdgeZero to rc/identity at d063a8e7 and takes main's Fastly SDK upgrade (#1671): fastly 0.13.3, url 2.5.9 and Viceroy 0.22.0. The merge had no conflicts.

ChristianPavilonis added a commit that referenced this pull request Nov 25, 2026
…on every adapter

Source: feat/identify-batch-sync-local-all-adapters at 9e08a9b.
Takes #1506's new head 42e0c46, which repins EdgeZero to rc/identity at
459bd27d: PR 275 at 0e2a58ae, the stack's test fixes and EdgeZero 536's
bounded record update, RecordHandle::update.

The merge is clean.
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#1608), I pushed 594625a28, a merge of #1506's new head 42e0c46c7, which repins EdgeZero to rc/identity at 459bd27d: EdgeZero #275 at 0e2a58ae, the EdgeZero stack's test fixes and EdgeZero #536's bounded record update, RecordHandle::update. The merge had no conflicts.

@prk-Jr prk-Jr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Every request on /_ts/api/v1/identify and /_ts/api/v1/batch-sync is now answered locally on all four adapters, so a partner's Bearer token and mapping body no longer reach the publisher origin.

What I checked:

  • Fastly claims all seven fallback methods on both paths and looks up the store only for GET (identify) and POST (batch sync), so OPTIONS preflight stays local with or without ec.ec_store.
  • Every adapter registers the publisher fallback for the same seven methods only, so other methods (for example TRACE) get a router response and are never proxied.
  • The route tests discriminate. As a control I removed the two new Axum named routes, and both route tests failed with 408/502 from the fallback instead of 501/405.

Non-blocking nit on the PR description: it still mentions a CapturingOrigin fixture in test_support.rs and a test-only services_override on Fastly's AppState. Neither is in the diff; the tests use the existing ScriptedHttpClient. Updating the Changes table and the summary bullet would keep the description accurate after the port onto the cutover.

Verified locally: the new Axum route tests at 594625a2. Fastly, Cloudflare and Spin rely on the green CI run at the same head.

Takes #1506's new head 8edc50e, which repins EdgeZero to rc/identity at
1619078a, a revert that removes EdgeZero 522 (portable Fastly record
providers) and 524 (outbound mTLS client identities).

The merge is clean.
@aram356

aram356 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#1608), I pushed fb1d91d31.

Takes #1506's new head 8edc50e, which repins EdgeZero to rc/identity at 1619078a, a revert that removes IABTechLab/edgezero#522 (portable Fastly record providers) and IABTechLab/edgezero#524 (outbound mTLS client identities).

The merge is clean.

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.

Answer identify and batch sync locally on every adapter

4 participants