-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Using if
keyword in rule declaration makes the AST rule name empty
#6509
Comments
So, there's a few things going on here, but it largely boils down to this. With the introduction of reference heads, or "nested rules", like... foo.bar.baz {
# some conditions
} ...the Not using deny[x] if {
# some conditions
} will be interpreted as: deny[x] := true if {
# some conditions
} Fixing this ambiguity is one of the main goals of OPA 1.0, and the relatively new docs on that topic describe this in more detail. That the name disappears when using Nested rules like the one shown above does not emit a cluster.deployments[deployment].pods[pod] {
# some conditions
} Would it be It's still possible to build something akin to a Finally — it is true that Regal recommends the use of Not sure if there's anything actionable here which isn't already described in other issues, and the docs around OPA 1.0, Either way, this is really useful as input to the work being done in this space, so thank you for raising the issue! |
if
keyword in rule declaration makes the AST rule name is emptyif
keyword in rule declaration makes the AST rule name empty
Using the if keyword without also using the contains keyword makes the rule name in the OPA AST an emptry string, which causes conftest to inadvertently skip over tests leading to inaccurate results. open-policy-agent/opa#6509 Signed-off-by: James Alseth <[email protected]>
Using the if keyword without also using the contains keyword makes the rule name in the OPA AST an emptry string, which causes conftest to inadvertently skip over tests leading to inaccurate results. open-policy-agent/opa#6509 Signed-off-by: James Alseth <[email protected]>
Using the if keyword without also using the contains keyword makes the rule name in the OPA AST an emptry string, which causes conftest to inadvertently skip over tests leading to inaccurate results. open-policy-agent/opa#6509 Signed-off-by: James Alseth <[email protected]>
@anderseknert Thanks for the explanation. Feel free to close this, or leave it open if you prefer. |
Thanks James! I think I'll close this as there are other issues and even open PRs addressing this, but this is great for future reference. Good that you found a solution to work with this in Conftest in the meantime 👍 |
…ed (#902) Using the if keyword without also using the contains keyword makes the rule name in the OPA AST an emptry string, which causes conftest to inadvertently skip over tests leading to inaccurate results. open-policy-agent/opa#6509 Signed-off-by: James Alseth <[email protected]>
Short description
Using
if
keyword in rule declaration makes the AST rule name is empty. This breaksconftest
which skips evaluation of rules that do not follow the deny/warn/exception naming pattern. Using the if keyword is recommended by the Regal linter https://docs.styra.com/regal/rules/idiomatic/use-if.Steps To Reproduce
Run
conftest test -p examples/awssam/policy examples/awssam/lambda.yaml
and confirm it raises violations as expected. Then, apply the following git patch:Now run
./conftest test -p examples/awssam/policy examples/awssam/lambda.yaml
again and you will see the tests now pass. With some printf debugging I see the following rule names from this policy file. You'll notice thedeny
are all gone when using theif
keyword and an empty string is returned instead.Before:
After:
Expected behavior
The
*ast.Rule.Head.Name.String()
method returns the rule name regardless of usage of the if keyword.Additional context
https://openpolicyagent.slack.com/archives/CBR63TK2A/p1704221665685919
The text was updated successfully, but these errors were encountered: