Skip to content

fix: harden voucher rate, pointer budget, attestation and metrics checks - #3031

Open
alpergundogdu wants to merge 1 commit into
mainfrom
claude/2851-hardening-rest-9bf300
Open

alpergundogdu wants to merge 1 commit into
mainfrom
claude/2851-hardening-rest-9bf300

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Refs #2851

Covers the four items of #2851 still open on main, and reports on a fifth.

Voucher rate tolerance

verify_rate is exact, and the tolerance parameter is gone (DEFAULT_TOLERANCE_BPS removed, no config knob). Every client pricing path rounds up (ledger::next_voucher, driver, credential all use div_ceil, and a chunk prices to exactly rate_per_mb because CHUNK_BYTES == BYTES_PER_MB), so an honest voucher always clears the check. New test one_percent_short_rejected; min_payment_clears_rate_check covers honest round-up pricing at odd byte counts. ADR 003 § Voucher withholding now says the check is exact.

Gateway known-signer budget

PUT /_pointer keys the known-signer lookup budget by (namespace, signer). A former owner's key that is still in high_water spends only its own budget. The map is cleared when the minute turns and holds at most 1,024 keys; past that cap, a known signer uses the shared budget. New test a_former_owner_cannot_spend_the_current_owners_lookup_budget.

Attestation verifier requires registration

AttestationVerifier::admits also requires the signer to be in the registered set (RegisteredOperators). That means the registry snapshot's operator → NodeId binding exists and the staker set reports that NodeId active. This is the same check ChainOriginDirectory already applies and the one ADR 011 § Interaction with CapacityBond describes. ADR 022 § Origin Attestation gains validity rule 4 and the matching conformance text. New test a_seated_signer_outside_the_registered_set_attests_nothing covers both an unbound signer and a signer bound to an inactive NodeId.

Note: a newly registered origin's attestations become valid at each verifier's next registry read (5 min, or sooner when a lookup meets an unknown node). A seat already requires an active operator, so in practice registration lands before seating.

Metrics server

The timer, the 10 s header timeout and the 60 s connection lifetime were already on main. The lifetime bounds keep-alive, since it caps the whole connection. This PR adds the loopback Host check. On a loopback listener, /metrics answers only a Host of localhost or a loopback IP (any port), and anything else gets 403. A listener the operator bound to a non-loopback address (container scrapes) accepts any Host, because scrapers there name the host by its own address. New tests: loopback_hosts_are_the_loopback_names_on_any_port and a_loopback_metrics_listener_refuses_a_foreign_host.

Attestation persisted before the pull lands: not changed

Persisting on commit is not a small change. The attestation has to be in the store from the handshake on, because it gates the pull and lets the node serve downstream while the pull is in flight. A pull lands through several paths (progressive miss pull, buffered fill, ranged legs, the timed source) inside the cache crate's CacheStore, which has no attestation hook. To persist on commit, a completion callback would have to run through each of those paths. #2921 already covers the effect: an attestation for a blob the node never landed serves nothing (serving needs the blob) and is dropped at its first refresh.

Checks

  • cargo nextest run -p decdn-incentive -p decdn-node -p decdn-cli: 3,232 passed. node_origin_pull::concurrent_pulls_resume_at_their_own_frontier_not_the_lanes failed once under full-suite load and passed on retry and in 8 of 8 isolated runs.
  • cargo clippy --workspace --all-targets --all-features: clean
  • cargo test --no-run -p decdn-e2e --features anvil-e2e: builds
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items: clean

🤖 Generated with Claude Code

- incentive: the voucher rate check is exact. The tolerance is gone: the
  client prices every span with div_ceil, so an honest voucher never pays
  less than the quote, and a 1%-short voucher is now refused.
- gateway: the known-signer lookup budget is per (namespace, signer), in a
  map cleared each minute and capped at 1024 keys, so a former owner's key
  cannot spend the current owner's budget.
- node: an origin attestation is valid only while its signer is in the
  registered set (bound to a NodeId the staker set reports active). A seat
  outlives its operator's registration until someone prunes it.
- node: a loopback /metrics listener answers only a loopback Host, so a
  DNS-rebinding page cannot read the scrape.

ADR 003 and ADR 022 state the exact rate check and the registration rule.

Refs #2851

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

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main d769020 claude/2851-hardenin... 8234bbc +/-
78% 78% 0%
View coverage of the 8 most impacted files.
File main d769020 claude/2851-hardenin... 8234bbc +/-
crates/node/src.../attestation.rs 90% 86% -4%
crates/cli/src/...ands/gateway.rs 80% 80% 0%
crates/client/src/lib.rs 89% 89% 0%
crates/node/src...gin/pull_leg.rs 84% 84% 0%
crates/node/src/runtime/mod.rs 28% 28% 0%
crates/node/src...ient/voucher.rs 91% 91% 0%
crates/incentive/src/rate.rs 100% 100% 0%
crates/node/src/metrics.rs 91% 92% +1%

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

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.

1 participant