Skip to content

fix(policy): a rule without an explicit enabled field is off in both evaluators (#261) - #297

Merged
codeyevsky merged 3 commits into
solongate:mainfrom
tnalbant:fix/261-enabled-default
Nov 3, 2026
Merged

codeyevsky merged 3 commits into
solongate:mainfrom
tnalbant:fix/261-enabled-default

Conversation

@tnalbant

@tnalbant tnalbant commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

What this changes

PolicyRule.Enabled is a *bool, and the two evaluators answered "is this rule on?" differently:

  • enabledForRego in packages/policy/rego.go required an explicit true.
  • enabledForFallback treated a nil Enabled as on.

One policy file could therefore allow or deny depending only on whether OPA happened to be installed: a DENY rule written without enabled blocked on a machine using the pure Go fallback and was dead on a machine where the rules were compiled to Rego.

One helper now answers the question for both, and a missing enabled means off. That is what the Rego compiler already did, and what rego_test.go pins with its rule d, so the fallback is the side that moves — the existing assertion is left as it is.

Behaviour change, so it belongs in the title: a DENY or ALLOW rule with no enabled field no longer applies where the fallback evaluator runs. Nothing changes on the Rego path, and a rule that sets "enabled": true is unaffected either way.

What I tested

  • cd packages/policy && go test -count=1 ./... — ok.
  • The new table test fails on the previous head, which is what makes it a measurement rather than decoration: TestBothEvaluatorsAgreeOnWhetherARuleIsEnabled/no_enabled_field reports compiled into Rego=false, blocked by the fallback=true, and TestFallbackEvaluateSkipsARuleWithoutAnEnabledField sees the fallback block rm -rf /tmp/x.
  • Four tool-pattern tests in toolpattern_test.go built their rules without enabled and so relied on the old default; they set it explicitly now, and keep testing the tool pattern rather than the default.
  • go vet ./... clean in shared, policy and guard.

scripts/sg-unit-check.sh stops at its gofmt leg on this machine: local Go is 1.27.3 while the modules declare 1.24–1.26, so it lists files this change never touched, packages/guard among them. I ran each package's go vet and go test directly instead. packages/sandbox and packages/core/config carry failing tests here (Darwin sandbox preview, file locks under macOS 27) that fail identically with these changes reverted, so they are not from this diff.

The real OPA binary was not run here; the comparison is between the compiled Rego and the fallback evaluator, which is how the existing tests compare them too.


Written with an AI coding assistant.

…evaluators (solongate#261)

`PolicyRule` carries `Enabled *bool`, and the two evaluators read an absent field
oppositely: `enabledForRego` required an explicit `true`, while
`enabledForFallback` treated `nil` as on. The same policy file therefore allowed
or denied depending only on whether OPA was installed -- a DENY rule could block
on a machine without OPA and be dead on one with it.

One helper now answers the question for both: a rule with no `enabled` field is
off, and turning a rule on takes an explicit `"enabled": true`. That is the
reading the Rego compiler and its test already encoded (`rego_test.go`'s rule
`d`), so the fix aligns the fallback with the documented behaviour instead of
relaxing an assertion to match new code.

Behaviour change, stated for the release notes: a DENY or ALLOW rule with no
`enabled` field no longer applies on machines that fall back to the pure Go
evaluator. The Rego path already ignored it.

Tests: a table over the three states (absent / true / false) asserts the two
evaluators agree and that the rule is live exactly when it is explicitly
enabled; a second test pins the fallback alone. Both fail on the previous head
with "compiled into Rego=false, blocked by the fallback=true". The four
tool-pattern tests that relied on the old nil default now set `enabled`
explicitly, so they keep testing the pattern rather than the default.

Co-authored-by: Hermes Agent (DeepSeek V4) <noreply@nousresearch.com>
Signed-off-by: Turgay Nalbant <182372382+tnalbant@users.noreply.github.com>
@tnalbant
tnalbant force-pushed the fix/261-enabled-default branch from b7b98b6 to a57be42 Compare November 3, 2026 06:44
@codeyevsky
codeyevsky merged commit 7fd6ae1 into solongate:main Nov 3, 2026
34 checks passed
codeyevsky added a commit that referenced this pull request Nov 3, 2026
fix(policy): a rule without an explicit enabled field is off in both evaluators (#261)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants