Compare commits

...
4 Commits
Author SHA1 Message Date
Roger Coll b43daad0c3 feat: add exit-code parameter to sarif format (#213) 2023-06-05 11:19:20 -06:00
abriko dedfa59531 Enhance GitHub Dependency Snapshot upload (#233) 2023-06-05 11:12:39 -06:00
Daniel Chabr f96f79aa22 bump trivy to v0.42.0 (#237)
* chore(deps): update trivy to v0.42.0

* revert formatting

* revert formatting again

* update sarif version in tests
2023-06-05 11:08:24 -06:00
Herman Wika Horn 82ec0dd604 Include args when using trivy config file (#231)
Previously, arguments provided using regular flags
were ignored if a trivy config file was provided

Note that this pull request makes no effort to
deduce or merge desired argument if the same
configuration with different values are provided
both within the config file and as flags. Behaviour
for this case would develop on the implementation
of trivy
2023-05-31 14:47:20 -06:00
7 changed files with 22 additions and 7 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
name: "build" name: "build"
on: [push, pull_request] on: [push, pull_request]
env: env:
TRIVY_VERSION: 0.40.0 TRIVY_VERSION: 0.42.0
BATS_LIB_PATH: '/usr/lib/' BATS_LIB_PATH: '/usr/lib/'
jobs: jobs:
build: build:
+1 -1
View File
@@ -1,4 +1,4 @@
FROM ghcr.io/aquasecurity/trivy:0.40.0 FROM ghcr.io/aquasecurity/trivy:0.42.0
COPY entrypoint.sh / COPY entrypoint.sh /
RUN apk --no-cache add bash curl npm RUN apk --no-cache add bash curl npm
RUN chmod +x /entrypoint.sh RUN chmod +x /entrypoint.sh
+5 -1
View File
@@ -105,6 +105,7 @@ if [ $template ] ;then
fi fi
if [ $exitCode ];then if [ $exitCode ];then
ARGS="$ARGS --exit-code $exitCode" ARGS="$ARGS --exit-code $exitCode"
SARIF_ARGS="$SARIF_ARGS --exit-code $exitCode"
fi fi
if [ "$ignoreUnfixed" == "true" ] && [ "$scanType" != "config" ];then if [ "$ignoreUnfixed" == "true" ] && [ "$scanType" != "config" ];then
ARGS="$ARGS --ignore-unfixed" ARGS="$ARGS --ignore-unfixed"
@@ -169,6 +170,8 @@ if [ "$skipFiles" ];then
fi fi
trivyConfig=$(echo $trivyConfig | tr -d '\r') trivyConfig=$(echo $trivyConfig | tr -d '\r')
# To make sure that uploda GitHub Dependency Snapshot succeeds, disable the script that fails first.
set +e
if [ "${format}" == "sarif" ] && [ "${limitSeveritiesForSARIF}" != "true" ]; then if [ "${format}" == "sarif" ] && [ "${limitSeveritiesForSARIF}" != "true" ]; then
# SARIF is special. We output all vulnerabilities, # SARIF is special. We output all vulnerabilities,
# regardless of severity level specified in this report. # regardless of severity level specified in this report.
@@ -177,7 +180,7 @@ if [ "${format}" == "sarif" ] && [ "${limitSeveritiesForSARIF}" != "true" ]; the
trivy --quiet ${scanType} --format sarif --output ${output} $SARIF_ARGS ${artifactRef} trivy --quiet ${scanType} --format sarif --output ${output} $SARIF_ARGS ${artifactRef}
elif [ $trivyConfig ]; then elif [ $trivyConfig ]; then
echo "Running Trivy with trivy.yaml config from: " $trivyConfig echo "Running Trivy with trivy.yaml config from: " $trivyConfig
trivy --config $trivyConfig ${scanType} ${artifactRef} trivy --config $trivyConfig ${ARGS} ${scanType} ${artifactRef}
returnCode=$? returnCode=$?
else else
echo "Running trivy with options: trivy ${scanType} ${ARGS}" "${artifactRef}" echo "Running trivy with options: trivy ${scanType} ${ARGS}" "${artifactRef}"
@@ -186,6 +189,7 @@ else
returnCode=$? returnCode=$?
fi fi
set -e
if [[ "${format}" == "github" ]]; then if [[ "${format}" == "github" ]]; then
if [[ "$(echo $githubPAT | xargs)" != "" ]]; then if [[ "$(echo $githubPAT | xargs)" != "" ]]; then
printf "\n Uploading GitHub Dependency Snapshot" printf "\n Uploading GitHub Dependency Snapshot"
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"version": "2.1.0", "version": "2.1.0",
"$schema": "https://json.schemastore.org/sarif-2.1.0-rtm.5.json", "$schema": "https://json.schemastore.org/sarif-2.1.0.json",
"runs": [ "runs": [
{ {
"tool": { "tool": {
@@ -64,7 +64,7 @@
} }
} }
], ],
"version": "0.40.0" "version": "0.42.0"
} }
}, },
"results": [ "results": [
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"version": "2.1.0", "version": "2.1.0",
"$schema": "https://json.schemastore.org/sarif-2.1.0-rtm.5.json", "$schema": "https://json.schemastore.org/sarif-2.1.0.json",
"runs": [ "runs": [
{ {
"tool": { "tool": {
@@ -37,7 +37,7 @@
} }
} }
], ],
"version": "0.40.0" "version": "0.42.0"
} }
}, },
"results": [ "results": [
+3
View File
@@ -0,0 +1,3 @@
vulnerability:
type: os
output: yamlconfig.test
+8
View File
@@ -81,3 +81,11 @@ bats_load_library bats-file
echo "$output" echo "$output"
assert_files_equal yamlconfig.test ./test/data/yamlconfig.test assert_files_equal yamlconfig.test ./test/data/yamlconfig.test
} }
@test "trivy image with trivy.yaml config and args" {
# trivy --config=./test/data/trivy-reduced.yaml image alpine:3.10
run ./entrypoint.sh "-v ./test/data/trivy-reduced.yaml" "-a image" "-i alpine:3.10" "-b json" "-g CRITICAL"
run diff yamlconfig.test ./test/data/yamlconfig.test
echo "$output"
assert_files_equal yamlconfig.test ./test/data/yamlconfig.test
}