Skip to content

feat(dir): apply the policy gate to the peer RPC - #2238

Merged
muscariello merged 1 commit into
feat/policy-pull-gatefrom
feat/policy-peer-gate
Oct 2, 2026
Merged

muscariello merged 1 commit into
feat/policy-pull-gatefrom
feat/policy-peer-gate

Conversation

@muscariello

@muscariello muscariello commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Closes #2208 (third and last PR). Part of #2205. Stacked on #2237: main ← #2226 ← #2229 ← #2235 ← #2237 ← this. Based on feat/policy-pull-gate; retargets as the PRs below it merge.

What this adds

The peer RPC (routing/rpc) serves Lookup, Pull, ListReferrers and PullReferrer to remote peers over libp2p, straight from the store and with no database access, so a peer could still fetch a record the policy gate excludes. Each handler now checks the record first.

  • The peer is told. An excluded record is refused with PermissionDenied, the same types.RecordExcludedError the API uses, through each handler's existing error wrapping, with no policy name and no reason. The gate answers from the index, so a record this node doesn't hold is refused the same way.
  • Fails closed. A gate error answers Internal and nothing is read from the store.
  • Can't be forgotten. The gate is a required argument of rpc.New, newRemote and routing.New; rpc.New rejects nil. The server passes its database. The routing package's test server passes a gate with no policy enforced.
  • types.RecordServabilityAPI names the check; the store controller's private copy of that interface goes.
  • Lookup and Pull log the local peer through the nil-safe localPeerID(), as the referrer handlers already did.

#2208, all together

Read path Gated by
Search, catalog, resolve (GetRecords, GetRecordCIDs, CountRecords, catalog entries and count) #2235 — handleFilterOptions
Filter values, catalog tags #2235 — distinctColumn, distinctAuthors
StoreService Pull, Lookup, PullReferrer; AIFinderService.ExportAgent #2237 — IsRecordServable
Peer RPC Lookup, Pull, ListReferrers, PullReferrer this PR

Still outside #2208: RoutingService.Publish with an explicit CID announces a record without the gate (announcement, not content; query-based publication is gated), IdentityService.GetIdentityStatus by CID (gated in #2241), and direct registry access, which bypasses the API entirely.

Testing

  • routing/rpc had no tests; it has four now, each over all four handlers: an excluded record is refused with PermissionDenied, where a record the gate lets through but the store lacks still gets NotFound (same CID, excluded vs not in the store), without reading the store for the excluded one; a servable record is served; a gate error fails closed without reading the store; New refuses a nil gate.
  • Mutation-checked, every mutant compiling: removing the gate from each of the four handlers, answering an excluded record with NotFound again, failing open, and a nil gate accepted by New each make a test fail.
  • server, reconciler, cli and tests vet clean. The routing package's own tests (which build newTestServer) and server link only in CI here — they compile, but can't be linked on this macOS toolchain.

@muscariello
muscariello requested a review from a team as a code owner September 30, 2026 11:01
@muscariello muscariello added kind/feature Categorizes issue or PR as related to a new feature. area/dir/server kind/security Categorizes issue or PR as related to security. labels Sep 30, 2026
@github-actions github-actions Bot added the size/M Denotes a PR that changes 200-999 lines label Sep 30, 2026
@codecov

codecov Bot commented Sep 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@muscariello
muscariello added this pull request to stack #2234 September 30, 2026 12:24
@muscariello
muscariello force-pushed the feat/policy-peer-gate branch from 4775812 to 82ee3ec Compare October 1, 2026 11:20
@muscariello
muscariello force-pushed the feat/policy-peer-gate branch from 59bac10 to 03c9d6a Compare October 1, 2026 15:12
@muscariello
muscariello force-pushed the feat/policy-peer-gate branch from 03c9d6a to 991ec80 Compare October 1, 2026 15:52
@muscariello
muscariello force-pushed the feat/policy-peer-gate branch from 991ec80 to d7eae19 Compare October 1, 2026 17:51
@muscariello
muscariello force-pushed the feat/policy-peer-gate branch from d7eae19 to 9ff5780 Compare October 2, 2026 07:34
csirmazbendeguz
csirmazbendeguz previously approved these changes Oct 2, 2026
@muscariello
muscariello dismissed csirmazbendeguz’s stale review October 2, 2026 12:05

The merge-base changed after approval.

@muscariello
muscariello force-pushed the feat/policy-peer-gate branch from 9ff5780 to 8440580 Compare October 2, 2026 12:05
@muscariello
muscariello force-pushed the feat/policy-peer-gate branch from 8440580 to 04c9910 Compare October 2, 2026 12:33
The libp2p RPC serves Lookup, Pull, ListReferrers and PullReferrer to
remote peers straight from the store, with no database access, so a
peer could still fetch a record the policy gate excludes. Each handler
now checks the record first.

As on the API, an excluded record is refused with PermissionDenied (the
record is not available under this node's content policy), with no
policy name and no reason. The gate answers from the index, so a record
this node does not hold is refused the same way. A gate error fails
closed.

The gate is a required argument of rpc.New, routing.New and newRemote,
so the peer RPC cannot be built without it; the server passes its
database. types.RecordServabilityAPI names the check, and the store
controller's copy of it goes.

Closes #2208. Refs #2205

Signed-off-by: Luca Muscariello <[email protected]>
@muscariello
muscariello added this pull request to the merge queue Oct 2, 2026
Merged via the queue into main with commit 39ec17b Oct 2, 2026
34 checks passed
@muscariello
muscariello deleted the feat/policy-peer-gate branch October 2, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dir/server kind/feature Categorizes issue or PR as related to a new feature. kind/security Categorizes issue or PR as related to security. size/M Denotes a PR that changes 200-999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make exclusion of non-compliant records unconditional on every read path

2 participants