-
Notifications
You must be signed in to change notification settings - Fork 490
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
A plugin for testing kubernetes objects using conftest/open policy agent #146
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: garethr If they are not already assigned, you can assign the PR to them by writing The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The CI failure appears unrelated to this change, rather a matter of mismatched types in some of the validation tooling. |
The failure should go away if you rebase. |
Hey @garethr , I think I read your newsletter. Keep up the good work! |
plugins/conftest.yaml
Outdated
homepage: https://github.com/instrumenta/conftest | ||
caveats: | | ||
This plugin needs the following programs: | ||
* conftest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the plugin itself a dependency?
Or does the plugin have the same name as another tool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the later.. The plugin provides a kubectl context to conftest
, which is a standalone application https://github.com/instrumenta/conftest
I went the shell script plugin route for speed of implentation. If folks find it interesting I'll build a separate binary that uses go-client and conftest as a library to avoid the need for the shell dependencies.
(I wanted to move the discussion from code review thread to here for more visibility.) @garethr yes this (depending on the actual tool through a separate installation) is certainly a bit unusual. We don't see plugins that have a "bash script wrapper" as their entrypoint. I see here you’re basically parsing cmd-line args to invoke various subcommands of the actual I think you have 2 options: Option 1: Handle plugin logic inside the executableYou can actually do this "inside" the conftest tool, by looking at This way you ship still one binary ( Option 2: Keep wrapper script, but ship the binary, too.In the Then, in the script, you can use something like this to relatively invoke the actual
|
Thanks. I'll likely try and do 2, then something closer to 1. |
/hold |
@ahmetb thanks, changes made. I'm now shipping the plugin in the released packages. And installing it specifically for the plugin as discussed. You no longer need the separate installation. |
🤔 seems like it’s still copying out only the .sh. Are you sure it copies out the binary from the archive? |
@ahmetb ah, more haste less speed. Should be fixed now I think. |
Here's some hot feedback:
this shouldn't be -h probably shouldn't fail (--help works):
Overall I couldn't really use it but it's probably because I don't use OPA. But also the I'm ok with merging as is. Let me know if you want to fix these first. |
Thanks for testing, I've added an $ kubectl conftest -h
A Kubectl plugin for using Conftest to test objects in Kubernetes using Open Policy Agent
See https://github.com/instrumenta/conftest for more information
Usage:
kubectl conftest (TYPE[.VERSION][.GROUP] [NAME] | TYPE[.VERSION][.GROUP]/NAME) Once this is available I'll be adding usage examples to the project README which is linked above. Conftest relies on a $ kubectl conftest service
Found service hello-kubernetes but services are not allowed
Found service kubernetes but services are not allowed |
Hey @garethr, I think conftest is a great tool and it deserves to be featured so that k8s users get aware of it. However, I'm a bit worried that it requires so many extra speps to be useful. As far as I understand, you need to have a Further, my feeling is that conftest is by spirit not an extension of kubectl, but rather a standalone k8s tool. We haven't defined yet, what are the criteria for a krew plugin, but looking at what we have, I would say: tools that extend existing kubectl functionality. Only very few require extra configuration. And in that regard, I don't see how conftest fits in. To me it looks more like a tool from the k8s kosmos, but very different from kubectl. |
@corneliusweig your characterisation of conftest is correct. It sounds like it's a good test of "we haven't defined yet what are the criteria for a krew plugin" as you say. The following isn't a plea for inclusion, more my rationale for creating a kubectl plugin in the first place and packaging for krew. I'd much rather have the general conversation and help define that policy. No rush on the plugin itself. kubectl plugins are just binaries with a certain name, so I could simply ask folks to download Krew provides a nice a nice veneer of management over that, and a handy discovery tool. My assumption was, like the CLI plugin model, the data powering that discovery and management tool was open (albeit with some sensible rules around naming and other bits.) It's absolutely fine to decide that the krew index is actually heavily curated, though it would be good to establish better guidelines and a formal approval process if that's the direction of travel. I do think that will lead to two sets of kubectl plugins, those managed by Krew and everything else. That makes plugin management harder for users in my opinion. It may be worth separating the krew tool from the index. Keep the index heavily curated, but do one or more of the following:
Hopefully that's a useful viewpoint, and not just specific to this particular plugin. I'll be at KubeCon as well if it's worth an in-person conversation. |
Thanks for the valuable discussion. re: @corneliusweig’s point:
I'm not convinced that this would be the admission criteria. We have admitted similar plugins like The rule of thumb I’m using is whether it would fit to be a kubectl subcommand, or is it "mostly" related to a third-party software. There's precedent for both cases. For example, we have re: @garethr’s points:
This would be appreciated. Indeed, right now all open PRs in this repo are on-hold because they fall into a gray area as for whether they should be distributed as plugins or not.
This came up many times before, but we couldn’t find the time to do it yet. It’s the direction that we want to go. We have an open issue kubernetes-sigs/krew#23 but I haven’t been able to follow up with a concrete proposal. It will happen, just a matter of time. I’ll be at KubeCon and have plenty of time to chat about these. Let’s try to catch up. |
…y agent This plugin allow for running conftest tests against a running Kubernetes cluster. This makes it both easy to check a cluster matches some arbitrary policy and also makes writing open policy agent code easier as you can quickly test it against a real cluster with the minimum of fuss. ```console $ kubectl krew install --manifest plugin/conftest.yaml -v4 I0513 22:28:08.542388 7886 install.go:150] --manifest specified, not ensuring plugin index I0513 22:28:08.543105 7886 install.go:119] Will install plugin: conftest Installing plugin: conftest I0513 22:28:08.543132 7886 install.go:74] Looking for installed versions I0513 22:28:08.543148 7886 util.go:79] Searching for installed versions of conftest in "/home/garethr/.krew/bin" I0513 22:28:08.543176 7886 install.go:83] Finding download target for plugin conftest I0513 22:28:08.543189 7886 util.go:38] Using os=linux arch=amd64 I0513 22:28:08.543200 7886 util.go:61] Matching platform for labels(arch=amd64,os=linux) I0513 22:28:08.543272 7886 util.go:68] Found matching platform with index (0) I0513 22:28:08.543287 7886 util.go:131] Matching plugin version is 5b587c11e4b1de8679c39e07a514c68e54de57987fc3eb32dc7946e78994359a I0513 22:28:08.543303 7886 install.go:46] Creating download dir "/tmp/krew-downloads/conftest" I0513 22:28:08.543403 7886 install.go:61] Getting sha256 (5b587c11e4b1de8679c39e07a514c68e54de57987fc3eb32dc7946e78994359a) signed version I0513 22:28:08.543421 7886 downloader.go:36] Fetching "https://github.com/instrumenta/conftest/archive/v0.5.2.zip" I0513 22:28:10.836287 7886 downloader.go:43] Reading download data into memory I0513 22:28:11.317941 7886 downloader.go:48] Read 45106 bytes of download data into memory I0513 22:28:11.318010 7886 downloader.go:174] detected .zip file I0513 22:28:11.318032 7886 downloader.go:55] Extracting download zip to "/tmp/krew-downloads/conftest" I0513 22:28:11.330572 7886 move.go:155] Creating plugin dir "/home/garethr/.krew/store/conftest" I0513 22:28:11.331392 7886 move.go:161] Creating temp plugin move operations dir "/tmp/krew-temp-move923716619" I0513 22:28:11.331450 7886 move.go:125] Finding move targets from "/tmp/krew-downloads/conftest" to "/tmp/krew-temp-move923716619" with file operation=index.FileOperation{From:"/*/plugin/*.sh", To:"."} I0513 22:28:11.331514 7886 move.go:44] Trying to move single file directly from="/tmp/krew-downloads/conftest" to="/tmp/krew-temp-move923716619" with file operation=index.FileOperation{From:"/*/plugin/*.sh", To:"."} I0513 22:28:11.331684 7886 move.go:52] Wasn't a single file, proceeding with Glob move I0513 22:28:11.331990 7886 move.go:132] Move file from "/tmp/krew-downloads/conftest/conftest-0.5.2/plugin/kubectl-conftest.sh" to "/tmp/krew-temp-move923716619/kubectl-conftest.sh" I0513 22:28:11.332105 7886 move.go:141] Move operations are complete I0513 22:28:11.332132 7886 move.go:172] Move directory "/tmp/krew-temp-move923716619" to "/home/garethr/.krew/store/conftest/5b587c11e4b1de8679c39e07a514c68e54de57987fc3eb32dc7946e78994359a" I0513 22:28:11.336782 7886 install.go:159] No file found at "/home/garethr/.krew/bin/kubectl-conftest" I0513 22:28:11.336838 7886 install.go:146] Creating symlink from "/home/garethr/.krew/store/conftest/5b587c11e4b1de8679c39e07a514c68e54de57987fc3eb32dc7946e78994359a/kubectl-conftest.sh" to "/home/garethr/.krew/bin/kubectl-conftest" I0513 22:28:11.336964 7886 install.go:150] Created symlink at "/home/garethr/.krew/bin/kubectl-conftest" CAVEATS: \ | This plugin needs the following programs: | * jq / Installed plugin: conftest garethr@surface-go ~/p/conftest> kubectl conftest A Kubectl plugin for using Conftest to test objects in Kubernetes using Open Policy Agent See https://github.com/instrumenta/conftest for more information Usage: kubectl test (TYPE[.VERSION][.GROUP] [NAME] | TYPE[.VERSION][.GROUP]/NAME) ```
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/remove-lifecycle stale |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@fejta-bot: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
This plugin allow for running conftest tests against a running Kubernetes cluster.
This makes it both easy to check a cluster matches some arbitrary policy and also
makes writing open policy agent code easier as you can quickly test it against a
real cluster with the minimum of fuss.
Checklist for plugin developers:
kubectl krew install --manifest=[...] --archive=[...]
)