Skip to content

feat(dir): enforce a policy version only once its verdicts cover the records - #2249

Merged
muscariello merged 1 commit into
feat/policy-enforcement-modesfrom
feat/policy-enforcement-backfill
Oct 2, 2026
Merged

muscariello merged 1 commit into
feat/policy-enforcement-modesfrom
feat/policy-enforcement-backfill

Conversation

@muscariello

@muscariello muscariello commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Part of #2209 (second PR: stage 2, and what an edit does). Part of #2205. Stacked on #2248: main ← #2226 ← #2229 ← #2235 ← #2237 ← #2238 ← #2241 ← #2246 ← #2248 ← this.

Why

The gate fails closed: a record with no verdict under the current version is excluded. Enforcing a policy the moment it is added would therefore hide every record not yet evaluated, and empty search until the reconciler caught up.

What this adds

  • A policy is first enforced once its verdicts cover the records. The server enforces a newly added policy only once no indexed record lacks a verdict under its current version, and records that in a new policy_backfills table the first time it holds. Until then reads are as they were without the policy, and the policy is reported as pending.
  • It stays enforced. Records indexed later have no verdict until evaluated and are hidden until they have one, which is what the filter already does.
  • An edit is not a first rollout. The new version is enforced at once, strictly, and every record is hidden until it has been evaluated under it. Content already delivered to users cannot be recalled, and a policy is usually tightened because something harmful was found, so nothing the new rule rejects is served in the meantime. The cost is that records are hidden for as long as the re-evaluation takes.
  • dir_policy_gate_records_unevaluated{policy_id, version} reports, per policy, how many records have no verdict yet under its current version: what remains before a new policy is enforced, and the size of the blackout after an edit.

Testing

  • Database: counting records without a verdict (a non-compliant verdict is still one; a verdict under another version does not count), marking a policy backfilled (twice, and per policy), and database failures.
  • A policy through its life, against the real filter, resolver and registry: not enforced while a record has no verdict, enforced once all have, hidden at once after an edit, filtering by the new rule as records are evaluated, and a record published meanwhile hidden until it has a verdict.
  • Resolver: first rollout waits for the records, a covered policy stays enforced when records arrive and after a restart, an edit is enforced at once, and every store call can fail the start.
  • Metrics: the gauge per registered policy, including one not yet enforced, and a counting error dropping only that gauge.
  • Race-clean; server, reconciler, cli and tests vet clean.

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

muscariello added a commit that referenced this pull request Oct 1, 2026
…t-bypass

Brings in #2249's tests for how backfill bookkeeping fails. One of them
calls servedDatabase, which this branch changed to also return what it
enforces, so the merge updates that call to take three results.

Signed-off-by: Luca Muscariello <[email protected]>
@csirmazbendeguz

csirmazbendeguz commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

As I mentioned in the previous PR, it would be much simpler to ignore policy version when enforcing, that's what I would recommend: #2235 (comment)

@muscariello

Copy link
Copy Markdown
Member Author

@csirmazbendeguz It is simpler, and I considered it. We kept strict enforcement: a verdict under another version doesn't count, because content already delivered can't be recalled and policies are usually tightened after something harmful is found. This PR limits the cost: versions are followed automatically, a new policy isn't enforced until every record has a verdict, and dir_policy_gate_records_unevaluated shows how many records are hidden after an edit.

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-enforcement-backfill branch from 2412c9c to 0ed87b3 Compare October 2, 2026 12:05
@muscariello
muscariello force-pushed the feat/policy-enforcement-backfill branch from 0ed87b3 to 2dfccb8 Compare October 2, 2026 12:33
Enforcing a policy the moment it is added hides every record not yet
evaluated under it: adding a policy would empty search until the
reconciler had caught up.

A policy is now enforced for the first time only once no indexed record
lacks a verdict under its current version. The server records that the
first time it holds and never goes back: records indexed later have no
verdict until evaluated, and are hidden until they do, which is what the
filter already does. Until then reads are as they were without the
policy, and the policy is reported as pending.

Editing a policy that was already enforced is not a first rollout. The
new version is enforced at once, strictly, and records stay hidden until
they are evaluated under it, so nothing the new rule rejects is served in
the meantime. dir_policy_gate_records_unevaluated reports, per policy,
how many records have no verdict yet under its current version: what
remains before a new policy is enforced, and the size of the blackout
after an edit.

Refs #2209

Signed-off-by: Luca Muscariello <[email protected]>
@muscariello
muscariello force-pushed the feat/policy-enforcement-backfill branch from 2dfccb8 to 3f74f1e Compare October 2, 2026 12:59
@muscariello
muscariello added this pull request to the merge queue Oct 2, 2026
Merged via the queue into main with commit d6cbcc8 Oct 2, 2026
34 checks passed
@muscariello
muscariello deleted the feat/policy-enforcement-backfill 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/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.

2 participants