-
Notifications
You must be signed in to change notification settings - Fork 40
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: add trivy secret scanning #440
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
[ | ||
{ | ||
"line": "1", | ||
"code": "AVD-AWS-0028", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "terraform", | ||
"isSecurity": true, | ||
"message": "Instance does not require IMDS access to require a token", | ||
"file": "test_data/aws.tf" | ||
}, | ||
{ | ||
"line": "1", | ||
"code": "AVD-AWS-0131", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "terraform", | ||
"isSecurity": true, | ||
"message": "Root block device is not encrypted.", | ||
"file": "test_data/aws.tf" | ||
}, | ||
{ | ||
"code": "DS026", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "docker", | ||
"isSecurity": true, | ||
"message": "Add HEALTHCHECK instruction in your Dockerfile", | ||
"file": "test_data/basic.Dockerfile" | ||
}, | ||
{ | ||
"code": "DS002", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "docker", | ||
"isSecurity": true, | ||
"message": "Specify at least 1 USER command in Dockerfile with non-root user as argument", | ||
"file": "test_data/basic.Dockerfile" | ||
}, | ||
{ | ||
"code": "KSV116", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "yaml", | ||
"isSecurity": true, | ||
"message": "pod security-context-demo in default namespace should set spec.securityContext.runAsGroup, spec.securityContext.supplementalGroups[*] and spec.securityContext.fsGroup to integer greater than 0", | ||
"file": "test_data/basic.yaml" | ||
}, | ||
{ | ||
"code": "KSV104", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "yaml", | ||
"isSecurity": true, | ||
"message": "container sec-ctx-demo of pod security-context-demo in default namespace should specify a seccomp profile", | ||
"file": "test_data/basic.yaml" | ||
}, | ||
{ | ||
"line": "14", | ||
"code": "KSV106", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "yaml", | ||
"isSecurity": true, | ||
"message": "container should drop all", | ||
"file": "test_data/basic.yaml" | ||
}, | ||
{ | ||
"line": "14", | ||
"code": "KSV020", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "yaml", | ||
"isSecurity": true, | ||
"message": "Container 'sec-ctx-demo' of Pod 'security-context-demo' should set 'securityContext.runAsUser' > 10000", | ||
"file": "test_data/basic.yaml" | ||
}, | ||
{ | ||
"line": "14", | ||
"code": "KSV003", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "yaml", | ||
"isSecurity": true, | ||
"message": "Container 'sec-ctx-demo' of Pod 'security-context-demo' should add 'ALL' to 'securityContext.capabilities.drop'", | ||
"file": "test_data/basic.yaml" | ||
}, | ||
{ | ||
"line": "14", | ||
"code": "KSV013", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "yaml", | ||
"isSecurity": true, | ||
"message": "Container 'sec-ctx-demo' of Pod 'security-context-demo' should specify an image tag", | ||
"file": "test_data/basic.yaml" | ||
}, | ||
{ | ||
"line": "14", | ||
"code": "KSV021", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "yaml", | ||
"isSecurity": true, | ||
"message": "Container 'sec-ctx-demo' of Pod 'security-context-demo' should set 'securityContext.runAsGroup' > 10000", | ||
"file": "test_data/basic.yaml" | ||
}, | ||
{ | ||
"line": "14", | ||
"code": "KSV014", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "yaml", | ||
"isSecurity": true, | ||
"message": "Container 'sec-ctx-demo' of Pod 'security-context-demo' should set 'securityContext.readOnlyRootFilesystem' to true", | ||
"file": "test_data/basic.yaml" | ||
}, | ||
{ | ||
"line": "14", | ||
"code": "KSV030", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "yaml", | ||
"isSecurity": true, | ||
"message": "Either Pod or Container should set 'securityContext.seccompProfile.type' to 'RuntimeDefault'", | ||
"file": "test_data/basic.yaml" | ||
}, | ||
{ | ||
"line": "14", | ||
"code": "KSV011", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "yaml", | ||
"isSecurity": true, | ||
"message": "Container 'sec-ctx-demo' of Pod 'security-context-demo' should set 'resources.limits.cpu'", | ||
"file": "test_data/basic.yaml" | ||
}, | ||
{ | ||
"line": "14", | ||
"code": "KSV012", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "yaml", | ||
"isSecurity": true, | ||
"message": "Container 'sec-ctx-demo' of Pod 'security-context-demo' should set 'securityContext.runAsNonRoot' to true", | ||
"file": "test_data/basic.yaml" | ||
}, | ||
{ | ||
"line": "14", | ||
"code": "KSV018", | ||
"level": "LEVEL_HIGH", | ||
"linter": "trivy", | ||
"targetType": "yaml", | ||
"isSecurity": true, | ||
"message": "Container 'sec-ctx-demo' of Pod 'security-context-demo' should set 'resources.limits.memory'", | ||
"file": "test_data/basic.yaml" | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,23 +26,40 @@ tools: | |
lint: | ||
definitions: | ||
- name: trivy | ||
files: [lockfile, docker, yaml, terraform] | ||
tools: [trivy] | ||
suggest_if: files_present | ||
known_good_version: 0.37.1 | ||
commands: | ||
- name: fs | ||
- name: fs-vuln | ||
files: [lockfile] | ||
output: sarif | ||
run: trivy fs ${target} --format json --no-progress --cache-dir ${shared_cachedir} | ||
run: | ||
trivy fs ${target} --scanners vuln --format json --no-progress --cache-dir | ||
${shared_cachedir} | ||
success_codes: [0] | ||
read_output_from: stdout | ||
# Trivy does not support batching | ||
batch: false | ||
is_security: true | ||
parser: | ||
runtime: python | ||
run: python3 ${plugin}/linters/trivy/trivy_fs_to_sarif.py | ||
run: python3 ${plugin}/linters/trivy/trivy_fs_vuln_to_sarif.py | ||
- name: fs-secret | ||
files: [ALL] | ||
Comment on lines
+47
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before we end up turning this on for everyone, couple verification questions:
If any of these answers are in the negative direction, we may want to consider disabling this subcommand by default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be disabled by default.
Despite these, it has a few benefits over trufflehog - you can define your own regexes to search for and you can define regexes to not alert on (e.g. if you only use AWS keys, you can only search for those, making this tool faster). I think having trufflehog enabled for everybody, and then trivy secret scanning available but disabled by default for users looking to customize their secret scanning further is the best way to go. |
||
output: sarif | ||
run: | ||
trivy fs ${target} --scanners secret --format json --no-progress --cache-dir | ||
${shared_cachedir} | ||
success_codes: [0] | ||
read_output_from: stdout | ||
# Trivy does not support batching | ||
batch: false | ||
is_security: true | ||
parser: | ||
runtime: python | ||
run: python3 ${plugin}/linters/trivy/trivy_fs_secret_to_sarif.py | ||
- name: config | ||
files: [docker, yaml, terraform] | ||
output: sarif | ||
run: trivy config ${target} --format json --cache-dir ${shared_cachedir} | ||
success_codes: [0] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# This aws key is an example and not a real key. | ||
aws_access_key_id = "AKIAXYZDQCEN4EXAMPLE" | ||
aws_secret_access_key = "Tg0pz8Jii8hkLx4+PnUisM8GmKs3a2DK+EXAMPLE" | ||
|
||
# The below keys are copied from https://github.com/dustin-decker/secretsandstuff | ||
github_secret = "369963c1434c377428ca8531fbc46c0c43d037a0" | ||
|
||
basic_auth = "https://admin:[email protected]/basic_auth" | ||
|
||
priv_key = """ | ||
-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAACm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nPz1PdgxO4sRlnntSBEwkQBzMkLOpq2h2BuJ2TlMP/TWuwLQ | ||
sDkv1Yk1pD0roGmtMzbujnURGxqRJ8gUmuIot4hpfyRSssvnRQQZ3lQCQCwHiE+HJxXWf5 | ||
c58zOMjW7o21tI8e13uUnbRoQVJM9XYqk1usPXIkYPYL9uOw3AW/Zn+cnDrsXvTK9ZxgGD | ||
/90b1BNwVqMlUK+QggHNwl5qD8eoXK5cDvav66te+E+V7FYFQ06w3tytRVz8SjoaiChN02 | ||
muIjvl6G7Hoj1hObM2t/ZheN1EShS11z868hhS6Mx7GvIdtkXuvdiBYMiBLOshJQxB8Mzx | ||
iug9W+Di3upLf0UMC1TqADGphsIHRU7RbmHQ8Rwp7dogswmDfpRSapPt9p0D+6Ad5VBzi3 | ||
f3BPXj76UBLMEJCrZR1P28vnAA7AyNHaLvMPlWDMG5v3V/UV+ugyFcoBAOyjiQgYST8F3e | ||
Hx7UPVlTK8dyvk1Z+Yw0nrfNClI= | ||
-----END OPENSSH PRIVATE KEY----- | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing linter trivy test config 1`] = ` | ||
{ | ||
"issues": [], | ||
"lintActions": [ | ||
{ | ||
"command": "config", | ||
"fileGroupName": "yaml", | ||
"linter": "trivy", | ||
"paths": [ | ||
".trunk/trunk.yaml", | ||
], | ||
"verb": "TRUNK_VERB_CHECK", | ||
}, | ||
{ | ||
"command": "config", | ||
"fileGroupName": "yaml", | ||
"linter": "trivy", | ||
"paths": [ | ||
"plugin.yaml", | ||
], | ||
"verb": "TRUNK_VERB_CHECK", | ||
}, | ||
{ | ||
"command": "config", | ||
"fileGroupName": "terraform", | ||
"linter": "trivy", | ||
"paths": [ | ||
"test_data/aws.tf", | ||
], | ||
"verb": "TRUNK_VERB_CHECK", | ||
}, | ||
{ | ||
"command": "config", | ||
"fileGroupName": "docker", | ||
"linter": "trivy", | ||
"paths": [ | ||
"test_data/basic.Dockerfile", | ||
], | ||
"verb": "TRUNK_VERB_CHECK", | ||
}, | ||
{ | ||
"command": "config", | ||
"fileGroupName": "yaml", | ||
"linter": "trivy", | ||
"paths": [ | ||
"test_data/basic.yaml", | ||
], | ||
"verb": "TRUNK_VERB_CHECK", | ||
}, | ||
], | ||
"taskFailures": [], | ||
"unformattedFiles": [], | ||
} | ||
`; |
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.
Please also delete the
expected_issues.json
file