Repository navigation
feat(dir): apply the policy gate to reads that fetch a record by CID - #2237
Conversation
checkRecordServable returns a gRPC status for the caller, and the tests' fakes and helpers return statuses and RPC errors unwrapped because the tests compare codes and messages exactly. Wrapping either would change the message a caller sees. Follows the repository's existing patterns: a per-line exemption in the gate, as in ai_finder.go, and a file-level one in the test, as in store.go. Fixes the Lint job failure on #2237. Signed-off-by: Luca Muscariello <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
checkRecordServable returns a gRPC status for the caller, and the tests' fakes and helpers return statuses and RPC errors unwrapped because the tests compare codes and messages exactly. Wrapping either would change the message a caller sees. Follows the repository's existing patterns: a per-line exemption in the gate, as in ai_finder.go, and a file-level one in the test, as in store.go. Fixes the Lint job failure on #2237. Signed-off-by: Luca Muscariello <[email protected]>
5095896 to
5faaa99
Compare
5faaa99 to
7b1440d
Compare
7b1440d to
01300b9
Compare
| // RecordNotFoundError is the error a store returns for a record it does not | ||
| // hold. The API returns the same error for a record the policy gate excludes, | ||
| // so a caller cannot tell excluded content from absent content. | ||
| func RecordNotFoundError(cid string) error { |
There was a problem hiding this comment.
Do we really not want the caller to know? I think it's fine to tell the caller that this record didn't pass the policy gate
There was a problem hiding this comment.
Agreed, done. A record the gate withholds is now refused with PermissionDenied (record <cid> is not available under this node's content policy) on Pull, Lookup, PullReferrer, ExportAgent, the peer RPC, explicit-CID publication and GetVerificationInfo. The message names no policy and no reason (that stays with the audit API in #2253), and search still leaves excluded records out silently.
A correction to what I first wrote here: the gate answers from the index, so with enforcement on, a CID the node never held gets the same refusal, and the node does not reveal which CIDs it holds. NotFound is left for a record that passes the gate but is missing from the store, and for any record while enforcement is off or in shadow mode.
checkRecordServable returns a gRPC status for the caller, and the tests' fakes and helpers return statuses and RPC errors unwrapped because the tests compare codes and messages exactly. Wrapping either would change the message a caller sees. Follows the repository's existing patterns: a per-line exemption in the gate, as in ai_finder.go, and a file-level one in the test, as in store.go. Fixes the Lint job failure on #2237. Signed-off-by: Luca Muscariello <[email protected]>
5a5bd58 to
d650bf3
Compare
checkRecordServable returns a gRPC status for the caller, and the tests' fakes and helpers return statuses and RPC errors unwrapped because the tests compare codes and messages exactly. Wrapping either would change the message a caller sees. Follows the repository's existing patterns: a per-line exemption in the gate, as in ai_finder.go, and a file-level one in the test, as in store.go. Fixes the Lint job failure on #2237. Signed-off-by: Luca Muscariello <[email protected]>
d650bf3 to
44b8242
Compare
checkRecordServable returns a gRPC status for the caller, and the tests' fakes and helpers return statuses and RPC errors unwrapped because the tests compare codes and messages exactly. Wrapping either would change the message a caller sees. Follows the repository's existing patterns: a per-line exemption in the gate, as in ai_finder.go, and a file-level one in the test, as in store.go. Fixes the Lint job failure on #2237. Signed-off-by: Luca Muscariello <[email protected]>
44b8242 to
e49c0b4
Compare
checkRecordServable returns a gRPC status for the caller, and the tests' fakes and helpers return statuses and RPC errors unwrapped because the tests compare codes and messages exactly. Wrapping either would change the message a caller sees. Follows the repository's existing patterns: a per-line exemption in the gate, as in ai_finder.go, and a file-level one in the test, as in store.go. Fixes the Lint job failure on #2237. Signed-off-by: Luca Muscariello <[email protected]>
e49c0b4 to
dfcbafd
Compare
The merge-base changed after approval.
checkRecordServable returns a gRPC status for the caller, and the tests' fakes and helpers return statuses and RPC errors unwrapped because the tests compare codes and messages exactly. Wrapping either would change the message a caller sees. Follows the repository's existing patterns: a per-line exemption in the gate, as in ai_finder.go, and a file-level one in the test, as in store.go. Fixes the Lint job failure on #2237. Signed-off-by: Luca Muscariello <[email protected]>
dfcbafd to
aee563b
Compare
checkRecordServable returns a gRPC status for the caller, and the tests' fakes and helpers return statuses and RPC errors unwrapped because the tests compare codes and messages exactly. Wrapping either would change the message a caller sees. Follows the repository's existing patterns: a per-line exemption in the gate, as in ai_finder.go, and a file-level one in the test, as in store.go. Fixes the Lint job failure on #2237. Signed-off-by: Luca Muscariello <[email protected]>
aee563b to
8bcba0f
Compare
StoreService Pull, Lookup and PullReferrer, and the AI Finder's ExportAgent, read the OCI store by CID and so bypassed the gate in the record query builder. Each now asks IsRecordServable first. A record the gate excludes is refused with PermissionDenied, built by types.RecordExcludedError: the record is not available under this node's content policy. The caller is told that much and nothing more: not which policy, not why. That detail stays with the audit API. The gate answers from the index, so a record that is excluded, not yet evaluated, or not indexed at all gets the same refusal, and the refusal does not reveal which CIDs the node holds. NotFound remains what the store says for a record that passes the gate but is missing from it, and the answer for any record while enforcement is off or in shadow mode. PullReferrer refuses too, rather than answer with an empty list that would read as "no signatures". Search stays silent about what it leaves out. The OCI store and the not-found paths share types.RecordNotFoundError so they cannot drift apart. When the gate cannot answer, the fetch fails with Internal rather than serving: it fails closed. Excluded fetches do not count towards pull or lookup counters. IsRecordServable reads the enforced set once. With nothing enforced every record is servable, indexed or not, so pulls of records not yet indexed keep working until a policy is enforced. The gate stays at the API layer: the reconciler's tasks read the store directly, and must still see unevaluated records to evaluate them. Refs #2208, #2205 Signed-off-by: Luca Muscariello <[email protected]>
checkRecordServable returns a gRPC status for the caller, and the tests' fakes and helpers return statuses and RPC errors unwrapped because the tests compare codes and messages exactly. Wrapping either would change the message a caller sees. Follows the repository's existing patterns: a per-line exemption in the gate, as in ai_finder.go, and a file-level one in the test, as in store.go. Fixes the Lint job failure on #2237. Signed-off-by: Luca Muscariello <[email protected]>
8bcba0f to
81da50d
Compare
Part of #2208 (second PR), part of #2205. Stacked on #2235:
main← #2226 ← #2229 ← #2235 ← this. Based onfeat/policy-read-gate; retargets as the PRs below it merge.What this adds
#2235 gates the record query builder, which covers search, the catalog and resolve. Reads that fetch a record by CID go straight to the OCI store and bypassed it. This gates them:
StoreService.Pull,LookupandPullReferrerAIFinderService.ExportAgentEach asks the new
IsRecordServable(cid)before touching the store.PermissionDenied(record <cid> is not available under this node's content policy), built bytypes.RecordExcludedError. That tells the caller the node withholds it, and says nothing about which policy or why: that stays with the audit API (feat(dir): serve excluded records to named auditors, and the enforcement runbook #2253). The gate answers from the index, so a record that is excluded, not yet evaluated or not indexed at all gets the same refusal, and it does not reveal which CIDs the node holds.NotFound(types.RecordNotFoundError, shared by the OCI store and the paths that report a missing record) remains the store's answer for a record that passes the gate but is missing from it, and the answer for any record while enforcement is off or in shadow mode. Pull, Lookup, PullReferrer and ExportAgent all answer the same way; PullReferrer is refused too, rather than answered with an empty list that would read as "no signatures". Search stays silent about what it leaves out.Internalrather than serving.IsRecordServablereads the enforced set once, so it can't decide "nothing enforced" on one read and gate on another.Not in this PR
routing/rpc) servesLookup,Pull,ListReferrersandPullReferrerto remote peers over libp2p, with no database access, so peers can still fetch excluded content. Gating it means threading the check throughrouting.New→newRemote→rpc.New; that's the next stacked PR.RoutingService.Publishwith an explicit CID announces a record without the gate. Query-based publication is already gated (feat(dir): serve only records that comply with every enforced policy #2235); this is announcement, not content, but should follow for consistency.IdentityService.GetIdentityStatus; it replaced the naming service'sGetVerificationInfowhen naming.v1 was removed) is gated in feat(dir): gate explicit-CID publication and verification lookups #2241.Testing
IsRecordServable, 6 cases: no gate and an empty set both serve a record that isn't indexed; with a policy enforced, compliant is served, and non-compliant, never evaluated and not indexed aren't.PermissionDeniedwith exactly the message above and no policy detail; the other still getsNotFound. The store is never read for an excluded record, and excluded fetches aren't counted. Servable records are served, and a gate error fails closed.NotFoundagain, answering PullReferrer with an empty response again, failing open on a gate error, and querying even when nothing is enforced.server,reconciler,cliandtestsmodules vet clean.serverandreconcilertests pass.