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 check should ignore non-Rego files #6317

Closed
anderseknert opened this issue Oct 15, 2023 · 6 comments · Fixed by #6437
Closed

opa check should ignore non-Rego files #6317

anderseknert opened this issue Oct 15, 2023 · 6 comments · Fixed by #6437
Labels

Comments

@anderseknert
Copy link
Member

Running opa check --strict on a couple of policy libraries in the wild, and I'm seeing all sorts of errors related to data files in the scanned directories (commonly, merge errors). It's not clear to me why a command that describes its own role as:

Check Rego source files for parse and compilation errors.

Would need to attempt merging data files found in directories it traverses. I'm currently deploying something like:

--ignore "*.yaml" --ignore "*.yml" --ignore "*.json"

as a workaround, but I doubt most users would come to the conclusion that's what's needed in order to solve the quite opaque "merge error" (with no further explanation given) failure.

It is imperative that this command is easy to run regardless of project structure, so unless there are good reasons for parsing data files as part of this process, we shouldn't. If there are good reasons for doing that, we should explain those in the output of opa check --help. Given that the command seems to do exactly what I asked for with the --ignore flags provided, I doubt that's the case though.

@ashutosh-narkar
Copy link
Member

In bundle mode, we read all files as seen here. We could apply some auto filters maybe to only read the Rego files.

@anderseknert
Copy link
Member Author

Thanks Ash. FWIW, I did not run with the --bundle flag, just on a directory directly. I guess it's fine if opa check --bundle verifies the bundle as a whole, but if so it must be made clear what the flag means. Without the bundle flag, the command should just read Rego files, right?

@ashutosh-narkar
Copy link
Member

Without the bundle flag, the command should just read Rego files, right?

Currently it reads both data and policy files. You mentioned that you saw errors merging data files. Did that happen w/o the bundle flag. If yes, did bundle mode resolve it?

@anderseknert
Copy link
Member Author

Yes, it happened without the bundle flag, and bundle mode did not resolve it. A lot of projects in the infra space keeps test data files like resouce manifests in each policy directory, so you'll see lots of directories containing things like:

policy.rego
policy_test.rego
testdata/
  pod1.yaml
  pod2.yaml
  pod3.yaml

They then have some custom script that'll run tests in each directory separately. I have suggested in the past that OPA would better support this natively to avoid having users glue together their tests with bash scripts. But leaving that aside, there's no reason opa check would need to try and merge these various YAML or JSON files if the purpose of the command is to check only Rego files like it says it does, or at least I can't see one.

@ashutosh-narkar
Copy link
Member

But leaving that aside, there's no reason opa check would need to try and merge these various YAML or JSON files if the purpose of the command is to check only Rego files like it says it does, or at least I can't see one.

Seems that way to me as well. Applying some auto filters seems like one way to resolve this.

@tjons
Copy link
Contributor

tjons commented Nov 24, 2023

I'll work on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants