Skip to content

feat(reconciler): evaluate records against OPA and CEL policies - #2266

Merged
muscariello merged 4 commits into
feat/policy-audit-bypassfrom
feat/policy-evaluator-validators
Oct 2, 2026
Merged

muscariello merged 4 commits into
feat/policy-audit-bypassfrom
feat/policy-evaluator-validators

Conversation

@muscariello

Copy link
Copy Markdown
Member

Closes #2265. Part of #2205. Stacked on #2253: main ← #2226 ← #2229 ← #2235 ← #2237 ← #2238 ← #2241 ← #2246 ← #2248 ← #2249 ← #2253 ← this. Based on feat/policy-audit-bypass; retargets as the PRs below it merge.

What this adds

The policy task stores verdicts and the read gate enforces them, but nothing implemented policy.Evaluator: a node could not produce a verdict, so enforcing a policy would hide every record, and nothing could be tested end to end (#2244) or dry-run (#2264). This adds the first evaluator, from the OPA and CEL validators already on main.

A validator gets a fourth op, evaluate, which makes it a content policy instead of an admission check:

validators:
  - provider: opa
    op: ["evaluate"]
    config:
      file: require-license.rego
  - provider: cel
    op: ["evaluate"]
    config:
      name: has-description
      expressions:
        - 'record.description != ""'
  • ID. provider:name: opa:require-license, cel:has-description. name defaults to the OPA file's name without .rego and is required for CEL. Letters, digits, ., _ and - only, because the ID is listed in a comma-separated setting and used as a metric label. Two entries cannot define the same ID. This is what policy.enforcement.policies lists.
  • Version. A hash of the policy's content as it was loaded: the .rego source, or the expressions. An edit is a new version, anything else is not, and nobody states one. The reconciler registers it and the server follows it, as before.
  • Only opa and cel. An OASF schema is fetched from a remote endpoint, so the content of that policy is not known when it is loaded; it stays an admission check.
  • Verdict. ValidatorEvaluator reads the record from the store (the index holds only the fields searches use) and has the validator decide on it. A rejection carries what the validator reported as its reason. A record that cannot be read, or a validator that cannot judge it, is an error, which the task stores as a failed evaluation: it stays excluded and is tried again next run.
  • Wiring. The service registers one evaluator per policy in the validator registry. The reconciler warns when policies are configured and the task is off, and when the task is on and none is configured, so neither passes silently.
  • Docs. The runbook gets a "Defining a Policy" section in place of the note that no evaluator ships. The validators page, the server README and the Helm values comments name the new op. Helm already mounts the policy files into the reconciler and restarts both pods when they change.

Hot-reloading a policy file is out of scope: an edit takes effect when the reconciler restarts, as for every other validator.

Testing

  • Config: a name is required for CEL and optional for OPA; OASF is rejected; names outside the allowed characters are rejected; duplicate IDs are rejected; a validator without the op needs no name.
  • Registry: policies come back in config order with the right ID and a version of the expected length; the version is stable for identical content, changes when the .rego source or the expressions change, and does not depend on the file's name or the policy's name; moving the boundary between two parts changes it.
  • Evaluator: accepted, rejected with the validator's messages as the reason, unreadable record, failing validator. A real CEL policy run through the task stores compliant for the described record, a rejection with a reason for the bare one, and registers the version the policy was loaded at.
  • Service: with policies the task is enabled; with none it is registered disabled; with the task off and policies configured nothing is registered.
  • Mutation-checked, every mutant compiling. Each makes a test fail: a constant version, a version that ignores content, the file name or the part boundaries, dropping the expressions from a CEL version, not collecting the policies, allowing duplicate IDs, allowing OASF to define a policy, an unreadable record or a failing validator counting as compliant, a rejection counting as compliant or losing its reason, validating something other than the stored record, and not registering the policies as evaluators.
  • server, reconciler, cli and tests vet clean; server, reconciler and cli tests pass.

Next

#2244: the E2E test, in the daemon suite, on a node that enforces a policy defined this way.

@muscariello
muscariello requested a review from a team as a code owner October 2, 2026 07:09
@github-actions

github-actions Bot commented Oct 2, 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 2, 2026, 12:59 PM

@github-actions github-actions Bot added the size/M Denotes a PR that changes 200-999 lines label Oct 2, 2026
@muscariello
muscariello force-pushed the feat/policy-evaluator-validators branch from 34f3533 to a178fc4 Compare October 2, 2026 07:34
muscariello added a commit that referenced this pull request Oct 2, 2026
dupword flags "records records" in NewValidatorEvaluator's comment.

Fixes the Lint job failure on #2266.

Signed-off-by: Luca Muscariello <[email protected]>
muscariello added a commit that referenced this pull request Oct 2, 2026
dupword flags "records records" in NewValidatorEvaluator's comment. The
same change is on #2266, whose commit this branch still carries; it
drops out when this branch is rebased onto it.

Fixes the Lint job failure on #2267.

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

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.36620% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/validators/registry.go 80.0% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

muscariello added a commit that referenced this pull request Oct 2, 2026
NewRegistry took a policy's version from the validator by a type
assertion whose failing branch config validation makes unreachable, so
its error return was never covered. validatorFor now returns the version
with the validator, as the OPA and CEL constructors already know it, and
the assertion goes. A provider that cannot define a policy has no
version, and the policy task refuses a policy without one.

Addresses the coverage report on #2266.

Signed-off-by: Luca Muscariello <[email protected]>
@muscariello
muscariello added this pull request to stack #2234 October 2, 2026 10:44
muscariello added a commit that referenced this pull request Oct 2, 2026
dupword flags "records records" in NewValidatorEvaluator's comment.

Fixes the Lint job failure on #2266.

Signed-off-by: Luca Muscariello <[email protected]>
muscariello added a commit that referenced this pull request Oct 2, 2026
NewRegistry took a policy's version from the validator by a type
assertion whose failing branch config validation makes unreachable, so
its error return was never covered. validatorFor now returns the version
with the validator, as the OPA and CEL constructors already know it, and
the assertion goes. A provider that cannot define a policy has no
version, and the policy task refuses a policy without one.

Addresses the coverage report on #2266.

Signed-off-by: Luca Muscariello <[email protected]>
@muscariello
muscariello force-pushed the feat/policy-evaluator-validators branch from 0e27672 to ebcc128 Compare October 2, 2026 12:05
csirmazbendeguz
csirmazbendeguz previously approved these changes Oct 2, 2026
@muscariello
muscariello dismissed csirmazbendeguz’s stale review October 2, 2026 12:33

The merge-base changed after approval.

muscariello added a commit that referenced this pull request Oct 2, 2026
dupword flags "records records" in NewValidatorEvaluator's comment.

Fixes the Lint job failure on #2266.

Signed-off-by: Luca Muscariello <[email protected]>
@muscariello
muscariello force-pushed the feat/policy-evaluator-validators branch from ebcc128 to 6a9c677 Compare October 2, 2026 12:33
muscariello added a commit that referenced this pull request Oct 2, 2026
NewRegistry took a policy's version from the validator by a type
assertion whose failing branch config validation makes unreachable, so
its error return was never covered. validatorFor now returns the version
with the validator, as the OPA and CEL constructors already know it, and
the assertion goes. A provider that cannot define a policy has no
version, and the policy task refuses a policy without one.

Addresses the coverage report on #2266.

Signed-off-by: Luca Muscariello <[email protected]>
A validator now accepts a fourth op, evaluate. It does not check records
on their way in: it makes the validator a content policy, whose
verdicts the reconciler stores and the server's read gate enforces.
Only opa and cel accept it. An OASF schema is fetched from a remote
endpoint, so the content of that policy is not known when it is loaded.

A policy's ID is provider:name, such as opa:require-license: config.name,
or for OPA the file's name without .rego, and required for CEL. It is
limited to letters, digits, '.', '_' and '-' because it ends up in a
comma-separated setting and in metric labels, and two entries cannot
define the same one.

Its version is a hash of its content, the .rego source or the
expressions, taken from what was loaded. An edit is a new version,
nothing else is, and nobody states one. Registry.Policies returns the
policies with their ID, version and validator.

Refs #2265, #2205

Signed-off-by: Luca Muscariello <[email protected]>
Nothing implemented policy.Evaluator, so a node could not produce a
verdict and enforcing a policy would have hidden every record.
ValidatorEvaluator is one: it reads the record from the store, since the
index holds only the fields searches use, and has the validator decide on
it. A rejection carries what the validator reported as its reason; a
record that cannot be read, or a validator that cannot judge it, is an
error, which the task stores as a failed evaluation that stays excluded.

The service registers one evaluator for each policy in the validator
registry, and the task now runs when policy_evaluation is enabled and a
policy is configured. It warns when policies are configured and the task
is off, and when the task is on and none is, so neither passes silently.

The runbook describes how to define a policy, what its ID and version
are, and what the reconciler does with a record, in place of the note that
no evaluator ships.

Closes #2265. Refs #2205

Signed-off-by: Luca Muscariello <[email protected]>
dupword flags "records records" in NewValidatorEvaluator's comment.

Fixes the Lint job failure on #2266.

Signed-off-by: Luca Muscariello <[email protected]>
NewRegistry took a policy's version from the validator by a type
assertion whose failing branch config validation makes unreachable, so
its error return was never covered. validatorFor now returns the version
with the validator, as the OPA and CEL constructors already know it, and
the assertion goes. A provider that cannot define a policy has no
version, and the policy task refuses a policy without one.

Addresses the coverage report on #2266.

Signed-off-by: Luca Muscariello <[email protected]>
@muscariello
muscariello force-pushed the feat/policy-evaluator-validators branch from 6a9c677 to e774182 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 2c6f4e8 Oct 2, 2026
37 checks passed
@muscariello
muscariello deleted the feat/policy-evaluator-validators 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

size/M Denotes a PR that changes 200-999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Evaluate records against the node's OPA and CEL policies

2 participants