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

allow to specify absolute paths with conftest pull #989

Open
sebhoss opened this issue Aug 9, 2024 · 4 comments
Open

allow to specify absolute paths with conftest pull #989

sebhoss opened this issue Aug 9, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@sebhoss
Copy link

sebhoss commented Aug 9, 2024

When calling conftest pull oci://... --policy <DIR> conftest always assumes that <DIR> is a relative path to the current working directory. This is troubling because conftest test --policy <DIR> just takes the <DIR> as-is and thus cannot find the downloaded policies.

Reproduce with:

$ SOME_DIR=$(mktemp -d)
$ conftest pull oci://... --policy $SOME_DIR/conftest
$ helm template ... | conftest test --policy $SOME_DIR/conftest -
Error: running test: load: loading policies: load: 1 error occurred during loading: stat /tmp/tmp.feEnr57lWT/conftest: no such file or directory

$ tree ./tmp
./tmp
└── tmp.feEnr57lWT
    └── conftest
        └── ...

Notice that I've used ./tmp in the last shell command and not /tmp.

@boranx boranx added the enhancement New feature or request label Aug 20, 2024
@boranx
Copy link
Member

boranx commented Aug 20, 2024

I think it's doable but you'd need the same feature for conftest test as well to be able to run them for the next step, right?

@sebhoss
Copy link
Author

sebhoss commented Aug 22, 2024

conftest test already loads policies from absolute paths just fine, e.g. this works:

conftest test --policy /absolute/path/to/my/policies ...`

this does not:

conftest pull oci://... --policy /absolute/path/to/my/policies
conftest test --policy /absolute/path/to/my/policies ...`

The second example does not work because conftest pull writes the downloaded policies into $(pwd)/absolute/path/to/my/policies instead of /absolute/path/to/my/policies.

@synack-badamson
Copy link

+1 to this. I can use absolute paths when I use conftest test but not conftest pull.
https://github.com/open-policy-agent/conftest/blob/master/internal/commands/pull.go#L69
The . forces it to be relative.

@boranx
Copy link
Member

boranx commented Sep 2, 2024

then yeah +1 from me to implement it for conftest pull to have a similar experience with test.
Still, it might be nice to put this behind a flag for pull to keep the default behavior, instead of a breaking change
We'd welcome a PR anyways, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants