Repository navigation
feat(server): make the read gate a pull operation policy - #2434
Merged
Merged
Conversation
Signed-off-by: Tibor Kircsi <[email protected]>
Contributor
|
The latest Buf updates on your PR. Results from workflow Buf CI / verify-proto (pull_request).
|
Contributor
|
This PR exceeds the recommended size of 2000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note that this PR might take longer to review due to large size. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
ramizpolic
approved these changes
Oct 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2346.
Adds
pullas an operation, gives the operation layer the verdict map it needs to decide there, and routes every read of one record by CID through a single gate that consults both the stored verdicts and the policies configured atpull.Why two gates exist after this
They are not symmetric, and both are temporary in different ways.
The SQL gate serves two operations with one body of code.
applyPolicyGatefilters search queries;IsRecordServableanswers one record by CID. Only the second is replaceable by a policy: search returns many records and the filter has to run inside the query, so no per-record evaluation can replace it. The end state is one gate atpullplus a SQL filter that only does search — not two gates atpull.Today's fetch check is also hardcoded: an AND over every enforced policy, each needing an evaluated compliant verdict at the version in force. There is no way to express "enforce X but only report on Y", or any condition over the verdicts other than their conjunction. The operation policy makes the same rule configuration, and makes other rules possible for the first time.
Both are live during the transition because the SQL check is what is deployed. Removing it here would mean a node configured with
policy.enforcement.fetch: enforceand no pull policy silently stops enforcing on upgrade.RecordGateconsults both and they intersect: either can refuse, which is the conservative direction. #2348 is wherepolicy.enforcement.fetchgoes away.What the parity suite is for
server/policy_pull_parity_test.godrives both gates against the same seeded database, for all six verdict states crossed with both modes, plus an unindexed CID. They agree everywhere. That is the evidence #2348 needs: deleting the SQL half becomes a removal rather than a behaviour change.Two things are still tied to the old config and need an answer before it can go:
dir_policy_gate_fetches_excluded_totaland the policy audit service, which read the enforcement config directly.When #2348 lands, drop
sqlGateand the "both gates agree" framing from that file but keep the table, renamed to something likeTestPullGate_WhatEachVerdictStateDecides. It is the only test that runs a real database through the real resolver into the registry and out through the gate; the resolver, the registry and the coverage query are otherwise only tested apart, with fakes.What parity revealed about the backfill latch
Four of the six verdict states serve the record under
enforce, and not because the gate is lax. A policy only enforces once its verdicts cover the catalogue, andEvaluatedPolicyStatuses()is just{evaluated}. So a verdict that failed, was superseded, or was reached under a since-edited version does not cover the record it is for — the policy is held in backfill by the very record it would have refused. The only verdict that refuses an indexed record is one that evaluated it and found it non-compliant; the other way to be refused is not to be indexed at all.A consequence worth recording: the version-in-force comparison in
verdictStatusOfcannot be reached while a policy is enforcing, since a stale verdict implies incomplete backfill. It is pinned byverdicts_test.go, not by the parity suite — mutating it fails two unit tests and no parity case.This is now documented for operators as an admonition under Deciding Reads With a Policy, because "I configured a pull policy and nothing is being refused" is otherwise discovered at the worst moment.
Design notes
A policy at
pullreadsverdicts,record_cid,contextandnow, but notrecord. A read by CID is gated before the content is fetched, which is what keeps a lookup an index read.checkRecordIsReadablerefuses such a policy at load time and points at the evaluation layer. The restriction costs little: record content cannot change under its CID, so a content question has one answer forever and belongs where it is answered once and cached.The
oasfprovider is marked as reading the record unconditionally. It is nothing but a reading of record content, so it is refused atpullrather than left to the CEL and Rego dependency analysis, which would not have caught it.RecordGate.Checkpanics on a nil receiver rather than allowing. "Enforces nothing" has an explicit spelling,NewRecordGate(nil, nil). The first version allowed on nil, and two publication tests then passed while consulting no gate at all — the exact fail-open the type exists to prevent.Announcement is gated too: announcing a record you would refuse to serve is a promise you would break, and a peer that took it up would be turned away.
Tests
recordgate_test.go— both halves of the gate can refuse, an unanswerable check fails closed asInternalrather than as an exclusion, and an excluded record costs no policy evaluation.verdicts_test.go— the verdict map: only a current compliant verdict counts, an unregistered policy has no current version, a pending policy still reports its verdict, and the backfill latch downgradesenforcetoshadowper decision rather than at load.verdictrefs_test.go— which verdict keys a policy reads, per engine, with an unreadable reference widening to "every verdict".registry_test.go— the two load-time refusals, for CEL and foroasf.policy_pull_parity_test.go— as above.Each load-bearing branch was mutation-tested. The nil-record guard in both validators is now conditional on the policy reading the record, which is what made the gate runnable without one.