-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(general): Add docker to pre commit hooks #5458
feat(general): Add docker to pre commit hooks #5458
Conversation
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.
nice work, added some comments
.pre-commit-hooks.yaml
Outdated
- id: checkov_container | ||
name: Checkov | ||
description: This hook runs checkov. | ||
entry: bridgecrew/checkov:latest -d . |
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.
we usually recommend to run docker with --tty
for better output handle.
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.
For reference, this is how pre-commit
runs docker_image hooks:
I pushed up a commit to add --tty
and the output looks like this now:
❯ pre-commit run -av checkov_secrets_container
Checkov Secrets..........................................................Passed
- hook id: checkov_secrets_container
- duration: 17.04s
secrets scan results:
Passed checks: 0, Failed checks: 0, Skipped checks: 49
❯ pre-commit run -av checkov_secrets_container
Checkov Secrets..........................................................Failed
- hook id: checkov_secrets_container
- duration: 17.16s
- exit code: 1
secrets scan results:
Passed checks: 0, Failed checks: 1, Skipped checks: 49
Check: CKV_SECRET_6: "Base64 High Entropy String"
FAILED for resource: a2478cff5623ee9e46dfe2ab06e96bfe5168f732
File: /foo/bar-values.yaml:7-8
Guide: https://docs.paloaltonetworks.com/content/techdocs/en_US/prisma/prisma-cloud/prisma-cloud-code-security-policy-reference/secrets-policies/secrets-policy-index/git-secrets-6.html
7 | superSecret: c2Vjcm******************************************************************************************************************************************************************************
❯ pre-commit run -a checkov_secrets_container
Checkov Secrets..........................................................Failed
- hook id: checkov_secrets_container
- exit code: 1
secrets scan results:
Passed checks: 0, Failed checks: 1, Skipped checks: 49
Check: CKV_SECRET_6: "Base64 High Entropy String"
FAILED for resource: a2478cff5623ee9e46dfe2ab06e96bfe5168f732
File: /foo/bar-values.yaml:7-8
Guide: https://docs.paloaltonetworks.com/content/techdocs/en_US/prisma/prisma-cloud/prisma-cloud-code-security-policy-reference/secrets-policies/secrets-policy-index/git-secrets-6.html
7 | superSecret: c2Vjcm******************************************************************************************************************************************************************************
❯ pre-commit run -a checkov_secrets_container
Checkov Secrets..........................................................Passed
@gruebel question about the container tag. As mentioned I picked The downside to using Any thoughts on how you would want to maintain this? Should I pin to whatever tag is available today ( |
790f813
to
392b40a
Compare
392b40a
to
e1ee3e9
Compare
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.
LGTM
Least maintenance is best, going to be a pain either way if you have pinned a version from pip locally and another pinned version in pre-commit unless you can specify version as a var in pre-commit?. |
There are limitations based on how
|
The |
then i think its best to stick with the latest, bit of a draw back in using docker in this case. |
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.
LGTM but we should include how to override the latest
tag in the docs. Thanks!
Co-authored-by: Taylor <[email protected]>
Co-authored-by: Taylor <[email protected]>
Thanks @tsmithv11. Suggestions merged, and branch updated from |
* Add pre-commit hook support for container image * Move -f into args to support passing arguments properly * Improve argument documentation * Update documentation to include pre-commit hooks * Add --tty to container entries * Update documentation per feedback * Update docs/4.Integrations/pre-commit.md Co-authored-by: Taylor <[email protected]> * Update docs/4.Integrations/pre-commit.md Co-authored-by: Taylor <[email protected]> --------- Co-authored-by: Taylor <[email protected]>
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # n/a
Description
Include a description of what makes it a violation and any relevant external links.
This PR adds support for running pre-commit hooks using the container image, rather than depending on the
checkov
binary or python module.Note that due to a limitation in
pre-commit
I had to make a choice about what the default container tag should be. I opted forlatest
to reduce the overhead of maintenance. However, it is possible to override this by declaring theentry
field in thepre-commit
config.Example:
Related:
pre-commit/pre-commit#2968
Fix
How does someone fix the issue in code and/or in runtime?
To test this PR, add the following to your
.pre-commit-config.yaml
Checklist: