Skip to content

feat(gateway)!: capabilities only, scoped by namespace, no loopback token - #2910

Merged
alpergundogdu merged 6 commits into
mainfrom
claude/gateway-pending-key
Nov 17, 2026
Merged

alpergundogdu merged 6 commits into
mainfrom
claude/gateway-pending-key

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What

decdn gateway is funded only by capabilities, from outside, so a gateway machine holds no secret and no payment state and can be replaced with nothing to tear down. Five commits:

  1. One pending delegate key. GET /_delegate returns the gateway's one unclaimed key (the same address until a capability claims it). PUT /_capability takes {"capability"} for a key the gateway holds; a key holds one capability per pool. The gateway pays each pull with the first registered capability that no funding stop retired and that is outside the node expiry margin (one redeem interval + 120 s). Per-page scope, x-decdn-host selection, per-site delegate bounds and the pending-key TTL are gone. A cache hit is served with nothing that can pay.
  2. Capabilities only, no allowance. --keystore/--capability are refused on every gateway; a public gateway answers the capability API on its bare host and pays with capabilities alone (503 with the decdn: URI when nothing can pay). --allowance-bytes-per-day / --allowance and every charge path are removed; caps bound spend. requests_allowance_exhausted is renamed requests_payment_required.
  3. No loopback token. Every loopback request passes a browser-header check instead: Sec-Fetch-Site: cross-site, a foreign Origin, or a browser without Sec-Fetch-Site gets 403, except a top-level GET navigation (Sec-Fetch-Mode: navigate + Sec-Fetch-Dest: document), which passes from anywhere so links open loopback content. Clients outside a browser pass. The dashboard reads /_status with no token.
  4. Namespace-scoped capabilities. PUT /_capability takes a "scope": {"namespaces", "signature"}, an EIP-712 CapabilityScope(address signer,bytes32 poolId,uint256[] namespaces) (domain decdn-capability-scope, verifyingContract PaymentPool) that the pool's owner signs. On a public gateway a scoped capability pays only for requests that one of its namespace pointers serves (the pointed bundle on <ns>.<host>); ?ns= and <ns>.<hash32> labels select no scoped capability there. On a loopback gateway, the namespace the request's decdn: URI names (?ns=, site label) selects it. Scoped matches pay before "any" ones. The listing, /_status and the dashboard show namespaces. decdn pool assign --namespace <id> signs the scope and prints the whole PUT body. A publisher can fund a shared public gateway (e.g. decdn.link) for its own content only; CORS stays open on public.
  5. Every registration states its scope. scope is required: "any" (pays for any content) or a namespace scope. A body without one gets 422, so nothing pays for everything by accident. decdn pool assign --any-namespace prints the "any" body. The gateway_pointer journey funds its gateway with a real namespace-scoped capability.

Docs: adr/appendix-gateway.md (ASD-STE100, new § Scope), adr/appendix-binaries.md, docker/README.decdn.md, CLI help. E2E journeys fund gateways through the new decdn_e2e::pool_owner.

SDK pins

Moves .github/sdk-typescript.sha to decdn/sdk-typescript#28 (1dab70e) and .github/sdk-python.sha to decdn/sdk-python#15 (3b502a9). Land those first. Both SDKs register with a required scope ("any" or {namespaces, signature}), map 503 and 402 to PAYMENT_REQUIRED (POOL_UNFUNDED is gone), and the TypeScript SDK drops its ./node subpath. New contract tests in both SDKs run only against gateways after v0.3.1, so release-tag runs are unaffected.

Verified locally

  • CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features, cargo doc gate, check_crate_edges.py: clean
  • cargo nextest run -p decdn-cli -p decdn-common -p decdn-e2e: 1802 passed
  • anvil journeys: gateway_public (2), gateway_pointer, gateway_concurrent_pulls, gateway_sdk (public + loopback), gateway_sdk_python (public + loopback): 8/8 pass
  • dashboard pnpm test / typecheck / lint: clean
  • cargo deny advisories fails on RUSTSEC-2026-0387 (crypto-bigint via alloy), RUSTSEC-2026-0441 (pin-utils) and RUSTSEC-2026-0543 (chrono), all present on main.

Behaviour to review

  • A link on another site can make a loopback gateway pay for the content it opens as a whole page (bounded by the caps; the page reads no answer; the cache serves repeats).

🤖 Generated with Claude Code

alpergundogdu and others added 3 commits November 16, 2026 18:26
…y modes

The gateway holds at most one pending delegate key: GET /_delegate returns
it until a capability claims it. PUT /_capability takes {"capability"}
only, for a key the gateway holds, one capability per pool per key. The
gateway pays every pull with the first registered capability that no
funding stop retired and that sits outside the node expiry margin, and
serves a cache hit with nothing that can pay. /_delegate, /_capability and
/_status need no token and no Origin; a loopback gateway answers nothing
cross-origin. A public gateway answers the same API on its bare host and
pays with capabilities first, then from its own pool when it names a
keystore.

Removes the per-page scope, x-decdn-host selection, per-site delegate
bounds, the pending-key TTL and the psl dependency.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A gateway, loopback or public, pays only with the capabilities pool owners
register to its in-memory delegate keys: --keystore and --capability are
refused, it opens no pool and keeps no buyer store past its run. The daily
allowance (--allowance-bytes-per-day, --allowance) is gone; the caps of the
capabilities bound what a gateway spends. A public gateway with nothing
that can pay answers 503 with the canonical decdn: URI. The counter
requests_allowance_exhausted is renamed requests_payment_required, /_status
loses its allowance field, and an active pull's payer is {signer, pool}.

The e2e journeys fund their gateways through decdn_e2e::pool_owner.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…te it

A loopback gateway writes no token file and reads no x-decdn-token. Every
request passes a browser-header check after the Host check: a cross-site
page, an Origin that is none of the gateway's own (the bare host and its
site origins), and a browser that sends no Sec-Fetch-Site (an Origin, or a
Mozilla/ User-Agent) get 403. A client outside a browser passes. On the
bare host, a browser's navigation to a bundle or entry redirects to its
site; any other request is served there. Site pages may connect to their
own origin only. decdn dashboard reads the gateway's /_status with no
token.

Moves the SDK pins to decdn/sdk-typescript#28 and decdn/sdk-python#15,
whose contract suites pass against this gateway.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-code-quality

github-code-quality Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 116f9e9 claude/gateway-pendi... ae406d9 +/-
77% 77% 0%
View coverage of the 10 most impacted files.
File main 116f9e9 claude/gateway-pendi... ae406d9 +/-
crates/cli/src/...s/local_http.rs 100% 80% -20%
crates/cli/src/...oard/sources.rs 54% 50% -4%
crates/node/src/dht/publish.rs 78% 77% -1%
crates/cli/src/...teway/worker.rs 83% 82% -1%
crates/cli/src/...ands/gateway.rs 80% 80% 0%
crates/cli/src/...ommands/pool.rs 71% 71% 0%
crates/cli/src/...mmands/fetch.rs 46% 47% +1%
crates/e2e/src/sdk_contract.rs 22% 27% +5%
crates/cli/src/...ateway/scope.rs 0% 98% +98%
crates/cli/src/...ay/delegates.rs 0% 100% +100%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 17, 2026 14:17 UTC

alpergundogdu and others added 2 commits November 17, 2026 13:03
A capability registered with a scope that its pool's owner signed
(EIP-712 CapabilityScope, domain decdn-capability-scope) pays only for
requests that one of the scope's namespace pointers serves: the
pointed bundle on <ns>.<host>. Scoped matches pay before unscoped
capabilities. The listing, /_status and the dashboard show each
capability's namespaces. `decdn pool assign --namespace` signs the
scope and prints the whole PUT /_capability body.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`PUT /_capability` requires `scope`: "any" for a capability that pays
for any content, or a pool owner's signed namespace scope. A body with
no scope is refused, so no capability pays for everything by accident.
`decdn pool assign --any-namespace` prints the "any" registration.

A loopback gateway selects a scoped capability by the namespace the
request's decdn: URI names (`?ns=`, or the site label). A top-level GET
navigation passes its browser check from any site, so a link on any
page opens loopback content.

The gateway_pointer journey funds its gateway with a namespace-scoped
capability. Moves the SDK pins to decdn/sdk-typescript@1dab70e and
decdn/sdk-python@3b502a9, which send the scope and map 503 to
PAYMENT_REQUIRED.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alpergundogdu alpergundogdu changed the title feat(gateway)!: capability-funded gateways with one pending key, no allowance, no loopback token feat(gateway)!: capabilities only, scoped by namespace, no loopback token Nov 17, 2026
@alpergundogdu
alpergundogdu merged commit 36b02fa into main Nov 17, 2026
39 checks passed
@alpergundogdu
alpergundogdu deleted the claude/gateway-pending-key branch November 17, 2026 16:30
@yigitdot

Copy link
Copy Markdown
Contributor

Merging this PR makes #2618 (persist the gateway allowance across restarts) obsolete. This PR removes --allowance-bytes-per-day/--allowance and every charge path, so no allowance is left to persist. #2618 can be closed when this PR merges.

alpergundogdu added a commit that referenced this pull request Nov 17, 2026
Takes main's capabilities-only gateway (#2910) as the base and re-applies
the governance/payment chain split on top of it: every registered
capability resolves its PaymentPool contract with capability_pool(), and
its pulls, lanes, payer and retirement are keyed by (contract, pool id,
signer). A namespace scope is checked under each candidate contract's
scope domain before any chain read. Pointer domains and registry reads use
the governance chain. The self-funded pool payer that main deleted stays
deleted, including this branch's per-pool funding for it. The e2e pool
owner helper takes the --governance-*/--pool flags.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants