Skip to content

feat(dir): add OPA validators - #2204

Merged
lgecse merged 1 commit into
mainfrom
feat/opa-validators
Oct 1, 2026
Merged

lgecse merged 1 commit into
mainfrom
feat/opa-validators

Conversation

@csirmazbendeguz

@csirmazbendeguz csirmazbendeguz commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

#2157

This PR adds the ability to configure validators like this:

  - provider: opa
    op: ["push"]
    config:
      file: "require-annotations.rego"

Where file refers to a file uploaded to the policies directory

@github-actions github-actions Bot added the size/L Denotes a PR that changes 1000-1999 lines label Sep 28, 2026
@github-actions

github-actions Bot commented Sep 28, 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 1, 2026, 8:09 AM

@github-actions github-actions Bot added size/M Denotes a PR that changes 200-999 lines and removed size/L Denotes a PR that changes 1000-1999 lines labels Sep 28, 2026
@csirmazbendeguz
csirmazbendeguz force-pushed the feat/opa-validators branch 3 times, most recently from 40aadb4 to 2fc3acc Compare September 28, 2026 12:24
@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.32787% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/validators/opa.go 76.2% 10 Missing ⚠️
reconciler/main.go 0.0% 1 Missing ⚠️
server/validators/registry.go 80.0% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@csirmazbendeguz
csirmazbendeguz marked this pull request as ready for review September 28, 2026 21:52
@csirmazbendeguz
csirmazbendeguz requested a review from a team as a code owner September 28, 2026 21:52
@lgecse
lgecse force-pushed the feat/opa-validators branch from 6a9752f to b68a68c Compare September 29, 2026 16:00
@tkircsi

tkircsi commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

@csirmazbendeguz Please check this. The reconciler will crash-loop whenever an opa validator is configured. The chart now injects policy into reconciler.config.yml, but the policies ConfigMap is mounted only in apiserver/templates/deployment.yaml — reconciler-deployment.yaml has no such volume. And NewRegistry eagerly constructs every entry regardless of op, so even a op: ["push"] entry causes the reconciler to call os.ReadFile on a path that doesn't exist in its container and return an error from run().

@tkircsi

tkircsi commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

And this one also. A policy without an allow rule silently denies everything. A module containing only deny contains msg if { ... } parses, compiles, and then rejects every record with record rejected by policy "x". rs.Allowed() can't distinguish "evaluated to false" from "the rule doesn't exist,".

@tkircsi

tkircsi commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

policy.enabled is defaulting to false in values.yaml and is still checked by policy.Config.Validate(), but an opa validator evaluates regardless. Pick one: honor the flag (reject opa entries when disabled), or remove it in this PR and drop it from the chart. Leaving it as a no-op documented in a comment is the worst option.

@tkircsi tkircsi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the issues mentioned in the PR comments.

@csirmazbendeguz
csirmazbendeguz force-pushed the feat/opa-validators branch 2 times, most recently from f7fd244 to c2fe799 Compare September 30, 2026 10:08
@csirmazbendeguz

Copy link
Copy Markdown
Contributor Author

Thanks @tkircsi ! Very helpful.

And this one also. A policy without an allow rule silently denies everything. A module containing only deny contains msg if { ... } parses, compiles, and then rejects every record with record rejected by policy "x". rs.Allowed() can't distinguish "evaluated to false" from "the rule doesn't exist,".

I think this is expected - users should always include an allow rule I think

lgecse
lgecse previously approved these changes Sep 30, 2026

@lgecse lgecse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

tkircsi
tkircsi previously approved these changes Sep 30, 2026

@tkircsi tkircsi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

ramizpolic
ramizpolic previously approved these changes Sep 30, 2026

@ramizpolic ramizpolic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an extra provider alongside CEL is good, users can opt-in to decide which to use. LGTM

@csirmazbendeguz

csirmazbendeguz commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @ramizpolic. Ok, we can merge it then 👍 By the way, we can also do inline OPA policies if you think that's better. We just discussed these file-based ones earlier, that's why this PR adds those only... but if you find this too complex, then we can discard this and do it inline instead. I think if we're not going to re-use the OPA policies, then no need to store them in files

@tkircsi I wanted to answer this:

And NewRegistry eagerly constructs every entry regardless of op

Yes, my idea here was that it's better to fail early. If config depends on a file that doesn't exist it should crash on startup

@csirmazbendeguz
csirmazbendeguz dismissed stale reviews from ramizpolic, tkircsi, and lgecse via a495900 September 30, 2026 13:26
@csirmazbendeguz
csirmazbendeguz force-pushed the feat/opa-validators branch 2 times, most recently from a495900 to 50060a4 Compare September 30, 2026 17:24
Signed-off-by: Bendegúz Csirmaz <[email protected]>
@lgecse
lgecse force-pushed the feat/opa-validators branch from 50060a4 to 7f08cb2 Compare October 1, 2026 08:07
@lgecse
lgecse added this pull request to the merge queue Oct 1, 2026
Merged via the queue into main with commit 34a82a5 Oct 1, 2026
37 checks passed
@lgecse
lgecse deleted the feat/opa-validators branch October 1, 2026 08:50
muscariello added a commit that referenced this pull request Oct 1, 2026
#2204 gave the reconciler a policy section for the directory OPA policy
files are loaded from, the same one the server has, and the chart fills
it from config.policy. Rebased onto it, this branch declared a second
Policy field and policy import for the evaluation task's settings, and
the reconciler stopped compiling.

The task's settings move to policy_evaluation: RECONCILER_POLICY_EVALUATION_*
in the environment, reconciler.config.policy_evaluation in Helm, and
reconciler.policy_evaluation in the daemon configuration.

Refs #2207

Signed-off-by: Luca Muscariello <[email protected]>
muscariello added a commit that referenced this pull request Oct 1, 2026
Brings in the fix that moves the reconciler's policy evaluation settings to policy_evaluation (#2229), which the rebase onto main had left clashing with #2204's policy section.

Signed-off-by: Luca Muscariello <[email protected]>
muscariello added a commit that referenced this pull request Oct 1, 2026
Brings in the fix that moves the reconciler's policy evaluation settings to policy_evaluation (#2229), which the rebase onto main had left clashing with #2204's policy section.

Signed-off-by: Luca Muscariello <[email protected]>
muscariello added a commit that referenced this pull request Oct 1, 2026
Brings in the fix that moves the reconciler's policy evaluation settings to policy_evaluation (#2229), which the rebase onto main had left clashing with #2204's policy section.

Signed-off-by: Luca Muscariello <[email protected]>
muscariello added a commit that referenced this pull request Oct 1, 2026
Brings in the fix that moves the reconciler's policy evaluation settings to policy_evaluation (#2229), which the rebase onto main had left clashing with #2204's policy section.

Signed-off-by: Luca Muscariello <[email protected]>
muscariello added a commit that referenced this pull request Oct 1, 2026
…eers

Brings in the fix that moves the reconciler's policy evaluation settings to policy_evaluation (#2229), which the rebase onto main had left clashing with #2204's policy section.

Signed-off-by: Luca Muscariello <[email protected]>
muscariello added a commit that referenced this pull request Oct 1, 2026
…cement-modes

Brings in main's #2204, which rewrote the policy config this branch extends and moved its OPA directory into the reconciler's policy section, and the policy_evaluation rename from #2229. The policy config keeps main's struct, without enabled or Validate, plus this branch's enforcement settings; its test file, which main deleted, keeps only the enforcement tests.

# Conflicts:
#	cli/cmd/daemon/daemon.config.yaml
#	install/charts/dir/apiserver/values.yaml
#	install/docker/reconciler.env
#	reconciler/config/config.go
#	reconciler/config/config_test.go
#	reconciler/service/service.go
#	server/config/config_test.go
#	server/database/gorm/gorm.go
#	server/database/gorm/policy_gate.go
#	server/database/gorm/policy_gate_test.go
#	server/policy/config/config.go
#	server/policy/config/config_test.go
#	server/server.go
#	server/types/database.go
muscariello added a commit that referenced this pull request Oct 1, 2026
…ment-backfill

Brings in main's #2204, the policy_evaluation rename from #2229, and #2248's merge of both. The policy config keeps main's struct plus this branch's refresh interval and previous_version.

Signed-off-by: Luca Muscariello <[email protected]>
muscariello added a commit that referenced this pull request Oct 1, 2026
…t-bypass

Brings in main's #2204, the policy_evaluation rename from #2229, and the merges below. The runbook now names the evaluation task's Helm key, reconciler.config.policy_evaluation.

Signed-off-by: Luca Muscariello <[email protected]>
muscariello added a commit that referenced this pull request Oct 1, 2026
#2204 gave the reconciler a policy section for the directory OPA policy
files are loaded from, the same one the server has, and the chart fills
it from config.policy. Rebased onto it, this branch declared a second
Policy field and policy import for the evaluation task's settings, and
the reconciler stopped compiling.

The task's settings move to policy_evaluation: RECONCILER_POLICY_EVALUATION_*
in the environment, reconciler.config.policy_evaluation in Helm, and
reconciler.policy_evaluation in the daemon configuration.

Refs #2207

Signed-off-by: Luca Muscariello <[email protected]>
muscariello added a commit that referenced this pull request Oct 1, 2026
#2204 gave the reconciler a policy section for the directory OPA policy
files are loaded from, the same one the server has, and the chart fills
it from config.policy. Rebased onto it, this branch declared a second
Policy field and policy import for the evaluation task's settings, and
the reconciler stopped compiling.

The task's settings move to policy_evaluation: RECONCILER_POLICY_EVALUATION_*
in the environment, reconciler.config.policy_evaluation in Helm, and
reconciler.policy_evaluation in the daemon configuration.

Refs #2207

Signed-off-by: Luca Muscariello <[email protected]>
muscariello added a commit that referenced this pull request Oct 2, 2026
#2204 gave the reconciler a policy section for the directory OPA policy
files are loaded from, the same one the server has, and the chart fills
it from config.policy. Rebased onto it, this branch declared a second
Policy field and policy import for the evaluation task's settings, and
the reconciler stopped compiling.

The task's settings move to policy_evaluation: RECONCILER_POLICY_EVALUATION_*
in the environment, reconciler.config.policy_evaluation in Helm, and
reconciler.policy_evaluation in the daemon configuration.

Refs #2207

Signed-off-by: Luca Muscariello <[email protected]>
@lgecse lgecse mentioned this pull request Oct 2, 2026
2 tasks done
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.

4 participants