Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opa panics during partial evaluation #2678

Closed
j-denner opened this issue Sep 3, 2020 · 1 comment
Closed

Opa panics during partial evaluation #2678

j-denner opened this issue Sep 3, 2020 · 1 comment

Comments

@j-denner
Copy link

j-denner commented Sep 3, 2020

Expected Behavior

Partial evaluation should not panic.

Actual Behavior

Depending on the order of comparison ["a", "b"][_] == __dat.test versus __dat.test == ["a", "b"][_] opa panics during partial evaluation.

Steps to Reproduce the Problem

The following code contains four test examples. The first three are successful while the forth fails.
While tests 1 & 2 are successful, test 3 & 4 have a switched comparison in the allow_... rule. The switched comparison works for eval (test 3) but not for partial (test 4).

This panic only happens, when the __dat rule has an else clause.

# Filename: bug.rego
#
# Input:
# {
#    "data1": {
#        "test": "a"
#    }
# }
package rego


__dat = x {
  x := input["data1"]
} else = x {
  x := input["data2"]
}

allow_OK {
	["a", "b"][_] == __dat.test
}

allow_Issue {
	__dat.test == ["a", "b"][_]
}

# Tests:
# ======
# opa version
# >> Version: 0.23.2
#
# opa eval -d bug.rego             -i input.json data.rego.allow_OK # Success
# >> { ... }
#
# opa eval -d bug.rego -p -u input -i input.json data.rego.allow_OK # Success
# >> { ... }
#
# opa eval -d bug.rego             -i input.json data.rego.allow_Issue # Success
# >> { ... }
#
# opa eval -d bug.rego -p -u input -i input.json data.rego.allow_Issue # opa panics
# >> panic: interface conversion: ast.Value is ast.Array, not ast.Var
# >>
# >> goroutine 1 [running]:
# >> github.com/open-policy-agent/opa/ast.outputVarsForTerms.func1(0xc0002a2d40, 0x19e9800)
# >> 	github.com/open-policy-agent/opa/ast/compile.go:2481 +0x1cf
# >> github.com/open-policy-agent/opa/ast.WalkTerms.func1(0x189b140, 0xc0002a2d40, 0xc0002a2c40)
# >> 	github.com/open-policy-agent/opa/ast/visit.go:181 +0x42
# >> github.com/open-policy-agent/opa/ast.(*GenericVisitor).Walk(0xc00027ae38, 0x189b140, 0xc0002a2d40)
# >> 	github.com/open-policy-agent/opa/ast/visit.go:270 +0x58
# >>  ...
@tsandall
Copy link
Member

tsandall commented Sep 3, 2020

@j-denner thanks for filing this. It looks like an issue in some of the term rewriting that's done to accept terms like ["a", "b"][_]. We'll get this fixed in the next release.

@tsandall tsandall added the bug label Sep 3, 2020
@tsandall tsandall added this to TODO (Things That Should Be Done) in Open Policy Agent via automation Sep 3, 2020
@tsandall tsandall moved this from TODO (Things That Should Be Done) to Planned (Things We Are Going To Do) in Open Policy Agent Sep 3, 2020
@tsandall tsandall moved this from Planned (Things We Are Going To Do) to In Progress in Open Policy Agent Sep 14, 2020
tsandall added a commit to tsandall/opa that referenced this issue Sep 22, 2020
Previously the output var analysis would panic if it encountered refs
with non-var head terms. This assumption was invalidated in v0.17 with
the introduction of indirect refs.

Fixes open-policy-agent#2678

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Open Policy Agent automation moved this from In Progress to Done Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

2 participants