-
Notifications
You must be signed in to change notification settings - Fork 309
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
Verify --data differs from documented and opa behaviour #535
Comments
@mykter I think this has to do with test_services_not_denied {
deny["Cannot expose one of the following ports on a LoadBalancer [22]"] with input as {"kind": "Service", "metadata": { "name": "sample" }, "spec": { "type": "LoadBalancer", "ports": [{ "port": "22" }]}}
} The test does indeed need to be updated |
(just in case it got lost in the discussion of the test: the important part of this report is the incorrect behaviour of |
I added #536 to hopefully clarify the behavior. Looks like the docs on the website showcase the current behavior: https://www.conftest.dev/options/#-data At the moment the folder itself doesn't come into play, it's more on the structure of the data. If this differs from OPA behavior it would probably be worth looking into. I personally haven't used the Do you have an example OPA and Conftest command that differs so I can compare the behavior? Everytime I try and add multiple bundles I'm seeing a root conflict error. |
Here's a fairly minimal example of the difference in behaviour of opa's bundles vs conftest's --data. $ cat a/dir/data.json
{"v":1}
$ cat a/p.rego package main
import data.dir
deny[msg] {
not dir.v == 1
msg := "couldn't load data via dir"
}
import data.v
deny[msg] {
not v == 1
msg := "couldn't load data via v"
} $ conftest test --policy=a --data=a <(echo 1)
FAIL - /dev/fd/63 - main - couldn't load data via dir
2 tests, 1 passed, 0 warnings, 1 failure, 0 exceptions
$ opa -b a eval data.main.deny
{
"result": [
{
"expressions": [
{
"value": [
"couldn't load data via v"
],
"text": "data.main.deny",
"location": {
"row": 1,
"col": 1
}
}
]
}
]
} |
To represent what you're trying to do in Conftest, it would be: Typically you'll pass in the configuration that you're trying to test (data.json) and tell conftest the policy directory. With |
Ah sorry I wasn't clear, the data.json is meant to be an example of static data that the policy refers to, as opposed to the input document. I just didn't refer to "input" or have an input doc to conftest for simplicity. The intent was to show that in conftest the first rule matches and the second doesn't, with opa it's the other way round. |
Yeah I see, the If the desire is to have it indexed based on the directory, I'd need to think through it some more as I haven't seen many questions or issues come up about conftest's data parameter. |
@anderseknert are you familiar with OPA and using bundles? There does appear to be a difference with how Conftest and OPA handle external data, but I'm not familiar with them enough to know if the difference is warranted or if making these behaviors consistent is something we should do. |
Yeah, OPA will load any JSON/YAML data (obviously not policies as those have a package defined) on the (relative) path under the which it was read. The only difference I know of in behavior as far as Whether it makes sense to preserve this behavior for |
Thanks! The documentation has been updated to reflect reality. I'll play around with --data and --bundle and see if it makes sense to change. The fear being that I imagine it would be a breaking change, and want to make sure we're actually solving a problem and not a symptom of poor docs 😅 |
Yeah, I guess a sensible middle ground could be to keep current behavoir while introducing the |
That's honestly not a bad idea either. Love it. Then come v1.0.0 we could consider removing |
@mykter @anderseknert I just noticed that OPA also has a echo {} | conftest test --policy=a --data=a - opa -d a/dir eval data.main.deny # -b also works here as well.. whats the difference between bundle and data? So that behavior seems consistent. The dir is slightly different, because Conftest traverses all children. That said, if the above finding is correct, this issue then is more about Conftest supporting |
I've just ran into this and am perplexed. I've spent a bunch of time wrapping my head around how I have a policy directory that looks like
This means the tests that use the data mock have to be changed depending on if the person is working currently in opa or conftest
is now at the top of my test file to accommodate for this. If I remember I can also force opa to shorten the path but then the command becomes quite hard to remember |
Any advice on this? We would prefer this path-based data structure instead of playing around with our data and merging it into a single file. |
Reusing the bundle loader from OPA should not be too complicated, I think. If you want to give it a shot :) |
The docs say that data in a folder "exceptions/a.json" will be exposed as "data.exceptions".
The example, which is the tested behaviour, shows that it is actually available directly under "data".
I think the test logic is inverted - it is checking that running
conftest test
gives an error, but it should be checking that it doesn't:Am I right in thinking that
opa test --bundle <path>
should be equivalent toconftest verify --policy <path> --data <path>
? My tests are working using this opa command at any rate!The text was updated successfully, but these errors were encountered: