Skip to content

policy: FallbackEvaluate disagrees with the OPA engine on enabled defaults, AND/OR semantics, and rootDirectory #115

Open

Description

@codeyevsky

Problem

Three related semantic-drift issues between the primary Rego/OPA evaluator and the pure-Go FallbackEvaluate path in packages/policy:

  1. rego.go:42 — enabledForRego and enabledForFallback disagree on which features/rules are considered enabled by default, so the same configuration can be interpreted differently depending on which evaluator handles it.
  2. policy.go:375 — FallbackEvaluate combines multiple constraints with OR logic where the Rego policy combines the equivalent constraints with AND, so a rule that should require all conditions to hold can be satisfied by just one of them under the fallback evaluator.
  3. policy.go:360 — rootDirectory constraint checking is entirely unimplemented in FallbackEvaluate (a no-op / always-true), while the Rego engine enforces it.

Impact

Whenever the fallback evaluator is used instead of OPA (e.g. OPA unavailable, or a deployment configured to run fallback-only), policies can be enforced with meaningfully looser semantics than intended: features assumed disabled by default may be enabled, AND-combined constraints degrade to OR, and rootDirectory confinement does nothing at all. This is a silent policy-weakening bug whose effect is invisible to anyone validating policy behavior solely against the Rego engine.

Repro

  1. Compare enabledForRego and enabledForFallback's default-enabled sets directly; find at least one rule/feature where they differ.
  2. Write a policy rule with two constraints that must both hold (AND semantics in Rego); evaluate the same policy via FallbackEvaluate with only one constraint satisfied and observe it is allowed, where the Rego path would deny it.
  3. Set a rootDirectory constraint and evaluate a path outside it via FallbackEvaluate; observe it is allowed, where the Rego engine would deny it.

Suggested fix

Audit enabledForRego vs enabledForFallback and make them share a single source of truth for default-enabled rules rather than two independently maintained lists. Change FallbackEvaluate's constraint combination at :375 from OR to AND to match the Rego semantics (or, better, extract the combination logic into a shared helper exercised by both evaluators). Implement rootDirectory checking in FallbackEvaluate using the same path-containment logic as the Rego engine (see the related rootDirectory issue for the Rego side's own boundary bug, which the fallback implementation should not blindly copy).

Activity

  1. sharmis-tp commented on Nov 18, 2026

    @sharmis-tp

    The fallback evaluator should produce identical results to the OPA engine for every input. I'll add a conformance test suite that runs the same policy through both evaluators and asserts identical decisions, then fix every divergence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions