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

Panic while type checking objects with non-json keys #2183

Closed
patrick-east opened this issue Mar 12, 2020 · 0 comments · Fixed by #2184
Closed

Panic while type checking objects with non-json keys #2183

patrick-east opened this issue Mar 12, 2020 · 0 comments · Fixed by #2184
Assignees
Labels

Comments

@patrick-east
Copy link
Contributor

With some policy snippet like:

package test

x = {{{}: 1}: 1}

OPA will panic like so:

panic: unreachable [recovered]
	panic: unreachable

goroutine 1 [running]:
github.com/open-policy-agent/opa/ast.(*Compiler).compile.func1()
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/ast/compile.go:846 +0x73
panic(0x4772080, 0x49a1730)
	/usr/local/Cellar/go/1.13.7/libexec/src/runtime/panic.go:679 +0x1b2
github.com/open-policy-agent/opa/ast.(*TypeEnv).Get.func1(0xc0003001c0, 0xc0003001e0)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/ast/env.go:67 +0x391
github.com/open-policy-agent/opa/ast.(*object).Foreach.func1(0xc0003001c0, 0xc0003001e0, 0xc000300200, 0x6941460)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/ast/term.go:1769 +0x39
github.com/open-policy-agent/opa/ast.(*object).Iter(0xc0002fb140, 0xc000264480, 0x20, 0x481b1e0)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/ast/term.go:1747 +0xa4
github.com/open-policy-agent/opa/ast.(*object).Foreach(0xc0002fb140, 0xc000300700)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/ast/term.go:1768 +0x53
github.com/open-policy-agent/opa/ast.(*TypeEnv).Get(0xc0002ebd30, 0x4851a60, 0xc000300220, 0x3, 0xc0001e04a0)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/ast/env.go:63 +0x3c0
github.com/open-policy-agent/opa/ast.(*typeChecker).checkRule(0xc0002fb5c0, 0xc0002ebd20, 0xc0002bfe40)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/ast/check.go:181 +0x92a
github.com/open-policy-agent/opa/ast.(*typeChecker).CheckTypes(0xc0002fb5c0, 0xc0002ebd20, 0xc0002ebcf0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x2000107)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/ast/check.go:101 +0x168
github.com/open-policy-agent/opa/ast.(*Compiler).checkTypes(0xc00017f110)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/ast/compile.go:811 +0x117
github.com/open-policy-agent/opa/ast.(*Compiler).runStage(0xc00017f110, 0x48ba9a9, 0x19, 0xc0001e01c0)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/ast/compile.go:832 +0x46
github.com/open-policy-agent/opa/ast.(*Compiler).compile(0xc00017f110)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/ast/compile.go:851 +0x125
github.com/open-policy-agent/opa/ast.(*Compiler).Compile(0xc00017f110, 0xc000264cd0)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/ast/compile.go:345 +0x2a3
github.com/open-policy-agent/opa/bundle.writeModules(0x49cab20, 0xc0000cc008, 0x49d3ea0, 0xc0001a40f0, 0x49b5c60, 0xc0001de5d0, 0xc00017f110, 0x49d0ae0, 0xc0001dc980, 0xc000193200, ...)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/bundle/store.go:397 +0x5b9
github.com/open-policy-agent/opa/bundle.activateBundles(0xc000265358, 0xc0000cc008, 0x49d3ea0)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/bundle/store.go:243 +0x817
github.com/open-policy-agent/opa/bundle.Activate(...)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/bundle/store.go:161
github.com/open-policy-agent/opa/rego.(*Rego).compileModules(0xc0001d2200, 0x49cab20, 0xc0000cc008, 0x49b5c60, 0xc0001de5d0, 0x49d0ae0, 0xc0001dc980, 0x0, 0x0)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/rego/rego.go:1442 +0x1b5
github.com/open-policy-agent/opa/rego.(*Rego).prepare(0xc0001d2200, 0x49cab20, 0xc0000cc008, 0x0, 0xc0002654f8, 0x1, 0x1, 0x0, 0x1)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/rego/rego.go:1269 +0x1f4
github.com/open-policy-agent/opa/rego.(*Rego).PrepareForEval(0xc0001d2200, 0x49cab20, 0xc0000cc008, 0x0, 0x0, 0x0, 0x1, 0x4f0a3e0, 0x0, 0x0)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/rego/rego.go:1184 +0x4d3
github.com/open-policy-agent/opa/cmd.eval(0xc000192fc0, 0x1, 0x3, 0x0, 0xc000194230, 0x1, 0x1, 0x4f0a3e0, 0x0, 0x0, ...)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/cmd/eval.go:263 +0x9b4
github.com/open-policy-agent/opa/cmd.init.4.func2(0xc0001aa780, 0xc000192fc0, 0x1, 0x3)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/cmd/eval.go:203 +0xde
github.com/spf13/cobra.(*Command).execute(0xc0001aa780, 0xc000192f60, 0x3, 0x3, 0xc0001aa780, 0xc000192f60)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/vendor/github.com/spf13/cobra/command.go:766 +0x2aa
github.com/spf13/cobra.(*Command).ExecuteC(0x4ed9560, 0xc000000180, 0xc0000dff50, 0x400753f)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/vendor/github.com/spf13/cobra/command.go:852 +0x2ea
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/vendor/github.com/spf13/cobra/command.go:800
main.main()
	/Users/patrick/projects/go/src/github.com/open-policy-agent/opa/main.go:15 +0x31
@patrick-east patrick-east self-assigned this Mar 12, 2020
patrick-east added a commit to patrick-east/opa that referenced this issue Mar 12, 2020
Previously if there was a non-json key it would `panic("unreachable")`
but it can fall back to using the dynamic property for these types.

Fixes: open-policy-agent#2183
Signed-off-by: Patrick East <east.patrick@gmail.com>
tsandall pushed a commit that referenced this issue Mar 16, 2020
Previously if there was a non-json key it would `panic("unreachable")`
but it can fall back to using the dynamic property for these types.

Fixes: #2183
Signed-off-by: Patrick East <east.patrick@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant