Skip to content

feat(server): make the read gate a pull operation policy - #2434

Merged
tkircsi merged 1 commit into
mainfrom
feat/pull-gate-policy
Oct 30, 2026
Merged

tkircsi merged 1 commit into
mainfrom
feat/pull-gate-policy

Conversation

@tkircsi

@tkircsi tkircsi commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Closes #2346.

Adds pull as 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 at pull.

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. applyPolicyGate filters search queries; IsRecordServable answers 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 at pull plus a SQL filter that only does search — not two gates at pull.

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: enforce and no pull policy silently stops enforcing on upgrade. RecordGate consults both and they intersect: either can refuse, which is the conservative direction. #2348 is where policy.enforcement.fetch goes away.

What the parity suite is for

server/policy_pull_parity_test.go drives 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_total and the policy audit service, which read the enforcement config directly.

When #2348 lands, drop sqlGate and the "both gates agree" framing from that file but keep the table, renamed to something like TestPullGate_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, and EvaluatedPolicyStatuses() 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 verdictStatusOf cannot be reached while a policy is enforcing, since a stale verdict implies incomplete backfill. It is pinned by verdicts_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 pull reads verdicts, record_cid, context and now, but not record. A read by CID is gated before the content is fetched, which is what keeps a lookup an index read. checkRecordIsReadable refuses 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 oasf provider is marked as reading the record unconditionally. It is nothing but a reading of record content, so it is refused at pull rather than left to the CEL and Rego dependency analysis, which would not have caught it.

RecordGate.Check panics 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 as Internal rather 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 downgrades enforce to shadow per 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 for oasf.
  • 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.

@tkircsi tkircsi self-assigned this Oct 30, 2026
@tkircsi tkircsi added kind/feature Categorizes issue or PR as related to a new feature. area/dir/server labels Oct 30, 2026
@tkircsi
tkircsi requested a review from a team as a code owner October 30, 2026 10:35
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

The latest Buf updates on your PR. Results from workflow Buf CI / verify-proto (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped⏩ skipped✅ passedOct 30, 2026, 10:35 AM

@github-actions github-actions Bot added the size/XL Denotes a PR that changes 2000+ lines label Oct 30, 2026
@github-actions

Copy link
Copy Markdown
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

codecov Bot commented Oct 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/policy/registry.go 91.6% 8 Missing ⚠️
server/policy/opa.go 90.5% 2 Missing ⚠️
server/policy/recordgate.go 88.2% 2 Missing ⚠️
server/policy/validate.go 84.6% 2 Missing ⚠️
server/policy/verdicts.go 98.3% 1 Missing ⚠️
server/server.go 90.0% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@tkircsi
tkircsi added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit 09ff44c Oct 30, 2026
40 checks passed
@tkircsi
tkircsi deleted the feat/pull-gate-policy branch October 30, 2026 13:42
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. size/XL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Make the read gate a pull operation policy

2 participants