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

Using Conftest with OPA bundles #924

Open
richardmcsong opened this issue Feb 28, 2024 · 1 comment
Open

Using Conftest with OPA bundles #924

richardmcsong opened this issue Feb 28, 2024 · 1 comment
Labels
good first issue Good for newcomers question Further information is requested

Comments

@richardmcsong
Copy link

richardmcsong commented Feb 28, 2024

What I tried:

  1. opa build . where . is the location of my policies
  2. oras push <oci registry uri> --config config.json:[...] bundle.tar.gz:[...] as per the OPA documentation website
  3. conftest test --update <oci registry uri> my-file.yaml

Note that my oci registry is on an on-prem instance of artifactory. I'm not 100% sure, but https://github.com/open-policy-agent/conftest/blob/master/downloader/oci_detector.go#L33 uses a regex match on hostnames to determine whether it's a valid OCI registry, which would fail on my on-prem artifactory (since it doesn't use those hostnames).

What I expected

conftest to download the bundle.tar.gz file, unpack it, and then run the tests in the file.

What I observed

Error: running test: load: loading policies: no policies found in [policy]. I saw that the bundle.tar.gz file had been downloaded.

Notes

I also tried with conftest push -- I was expecting both processes to work the same way. However, when I inspected the registry itself, I saw very different file formats.

The manifest.json for the opa build . && oras push command shows that a single layer was pushed that contained the bundle.tar.gz layer. However, the manifest.json for the conftest push command shows that multiple layers were pushed, each layer containing a single .rego file.

What is the intended behaviour? The documentation mentions the format should reuse the OPA bundle format.

@boranx
Copy link
Member

boranx commented Jun 25, 2024

hi @richardmcsong

Thanks for reporting the issue!
At first glance at the code, I'd say local registries are also supported in conftest:

func containsLocalRegistry(src string) bool {

in case they are in the form of 127.0.0.1:port or localhost

From a user experience point of view, as to how you'd store your policies and execute, I'd recommend using contest push
Because, it just takes the parameters as required so you don't have to manage compressing the layers as tarball and handle json files
The example format would be conftest push 127.0.0.1:5000/testpolicy path/to/policy-dir

We might wanna update the contest docs with local registry use cases for better visibility, any PRs are welcome if you have any cycles:)

@boranx boranx added question Further information is requested good first issue Good for newcomers labels Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants