Compare commits

...
10 Commits
Author SHA1 Message Date
a7a829a434 chore: update trivy version Dockerfile (#96)
* chore: update trivy version Dockerfile

* Update readme for sarif deprecate
https://github.com/aquasecurity/trivy/discussions/1571

* docs: revert template and remove sarif.tpl

* fix: update condition to use format variable

Co-authored-by: oranmoshai <oran.moshai@aquasec.com>
Co-authored-by: knqyf263 <knqyf263@gmail.com>
2022-02-02 15:19:51 -08:00
Carol Valenciaandcarolina valencia 9c21d3ca2c chore: update trivy version Dockerfile (#89)
Co-authored-by: carolina valencia <krol3@users.noreply.github.com>
2022-01-10 16:47:20 -08:00
Masayoshi Mizutani 8f4c7160b4 feat: Add list-all-pkgs option (#88) 2021-12-16 08:31:49 -08:00
Carol Valencia 81cc8cd841 chore: update trivy version - fixed sarif (#87) 2021-12-10 10:18:11 -08:00
Nick Liffen 0769bbf0d2 Update Dockerfile (#82) 2021-11-26 12:02:01 -08:00
gustavomonarin 9ec80b5796 feat(#59) add support to skip files (#60)
* feat(#59) Add support to skip files

closes #59

* Fix skipFiles parameter check

The check should be if present not if enabled.
2021-11-26 12:01:28 -08:00
rahul2393 a58433e1c9 feat: added support for rootfs command (#84) 2021-11-26 10:32:44 -08:00
Simar 7168e9ba5a feat: Update README to include a case where upload upon failure (#78)
* feat: Update README to include a case where upload is needed upon failure.

Signed-off-by: Simar <simar@linux.com>

* Update README.md
2021-11-16 14:28:39 -08:00
rahul2393 2a2157eb22 chore: Include skip options other than severity filter option when building SARIF report. (#79) 2021-11-10 13:11:56 -08:00
Simar 1ccef265f5 feat: Build a full SARIF report even if under accepted severity level. (#73)
Signed-off-by: Simar <simar@linux.com>
2021-10-26 17:45:53 -07:00
4 changed files with 128 additions and 18 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
FROM aquasec/trivy:0.20.2 FROM aquasec/trivy:0.23.0
COPY entrypoint.sh / COPY entrypoint.sh /
RUN apk --no-cache add bash RUN apk --no-cache add bash
RUN chmod +x /entrypoint.sh RUN chmod +x /entrypoint.sh
+82 -15
View File
@@ -76,8 +76,7 @@ jobs:
uses: aquasecurity/trivy-action@master uses: aquasecurity/trivy-action@master
with: with:
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}' image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
format: 'template' format: 'sarif'
template: '@/contrib/sarif.tpl'
output: 'trivy-results.sarif' output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab - name: Upload Trivy scan results to GitHub Security tab
@@ -88,6 +87,42 @@ jobs:
You can find a more in-depth example here: https://github.com/aquasecurity/trivy-sarif-demo/blob/master/.github/workflows/scan.yml You can find a more in-depth example here: https://github.com/aquasecurity/trivy-sarif-demo/blob/master/.github/workflows/scan.yml
If you would like to upload SARIF results to GitHub Code scanning even upon a non zero exit code from Trivy Scan, you can add the following to your upload step:
```yaml
name: build
on:
push:
branches:
- master
pull_request:
jobs:
build:
name: Build
runs-on: ubuntu-18.04
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build an image from Dockerfile
run: |
docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v1
if: always()
with:
sarif_file: 'trivy-results.sarif'
```
See this for more details: https://docs.github.com/en/actions/learn-github-actions/expressions#always
### Using Trivy to scan your Git repo ### Using Trivy to scan your Git repo
It's also possible to scan your git repos with Trivy's built-in repo scan. This can be handy if you want to run Trivy as a build time check on each PR that gets opened in your repo. This helps you identify potential vulnerablites that might get introduced with each PR. It's also possible to scan your git repos with Trivy's built-in repo scan. This can be handy if you want to run Trivy as a build time check on each PR that gets opened in your repo. This helps you identify potential vulnerablites that might get introduced with each PR.
@@ -112,8 +147,42 @@ jobs:
with: with:
scan-type: 'fs' scan-type: 'fs'
ignore-unfixed: true ignore-unfixed: true
format: 'template' format: 'sarif'
template: '@/contrib/sarif.tpl' output: 'trivy-results.sarif'
severity: 'CRITICAL'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: 'trivy-results.sarif'
```
### Using Trivy to scan your rootfs directories
It's also possible to scan your rootfs directories with Trivy's built-in rootfs scan. This can be handy if you want to run Trivy as a build time check on each PR that gets opened in your repo. This helps you identify potential vulnerablites that might get introduced with each PR.
If you have [GitHub code scanning](https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/about-code-scanning) available you can use Trivy as a scanning tool as follows:
```yaml
name: build
on:
push:
branches:
- master
pull_request:
jobs:
build:
name: Build
runs-on: ubuntu-18.04
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run Trivy vulnerability scanner with rootfs command
uses: aquasecurity/trivy-action@master
with:
scan-type: 'rootfs'
scan-ref: 'rootfs-example-binary'
ignore-unfixed: true
format: 'sarif'
output: 'trivy-results.sarif' output: 'trivy-results.sarif'
severity: 'CRITICAL' severity: 'CRITICAL'
@@ -183,8 +252,7 @@ jobs:
uses: aquasecurity/trivy-action@master uses: aquasecurity/trivy-action@master
with: with:
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}' image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
format: 'template' format: 'sarif'
template: '@/contrib/sarif.tpl'
output: 'trivy-results.sarif' output: 'trivy-results.sarif'
env: env:
TRIVY_USERNAME: Username TRIVY_USERNAME: Username
@@ -220,8 +288,7 @@ jobs:
uses: aquasecurity/trivy-action@master uses: aquasecurity/trivy-action@master
with: with:
image-ref: 'aws_account_id.dkr.ecr.region.amazonaws.com/imageName:${{ github.sha }}' image-ref: 'aws_account_id.dkr.ecr.region.amazonaws.com/imageName:${{ github.sha }}'
format: 'template' format: 'sarif'
template: '@/contrib/sarif.tpl'
output: 'trivy-results.sarif' output: 'trivy-results.sarif'
env: env:
AWS_ACCESS_KEY_ID: key_id AWS_ACCESS_KEY_ID: key_id
@@ -257,8 +324,7 @@ jobs:
uses: aquasecurity/trivy-action@master uses: aquasecurity/trivy-action@master
with: with:
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}' image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
format: 'template' format: 'sarif'
template: '@/contrib/sarif.tpl'
output: 'trivy-results.sarif' output: 'trivy-results.sarif'
env: env:
GOOGLE_APPLICATION_CREDENTIAL: /path/to/credential.json GOOGLE_APPLICATION_CREDENTIAL: /path/to/credential.json
@@ -291,8 +357,7 @@ jobs:
uses: aquasecurity/trivy-action@master uses: aquasecurity/trivy-action@master
with: with:
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}' image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
format: 'template' format: 'sarif'
template: '@/contrib/sarif.tpl'
output: 'trivy-results.sarif' output: 'trivy-results.sarif'
env: env:
TRIVY_USERNAME: Username TRIVY_USERNAME: Username
@@ -316,17 +381,19 @@ Following inputs can be used as `step.with` keys:
| `input` | String | | Tar reference, e.g. `alpine-latest.tar` | | `input` | String | | Tar reference, e.g. `alpine-latest.tar` |
| `image-ref` | String | | Image reference, e.g. `alpine:3.10.2` | | `image-ref` | String | | Image reference, e.g. `alpine:3.10.2` |
| `scan-ref` | String | `/github/workspace/` | Scan reference, e.g. `/github/workspace/` or `.`| | `scan-ref` | String | `/github/workspace/` | Scan reference, e.g. `/github/workspace/` or `.`|
| `format` | String | `table` | Output format (`table`, `json`, `template`) | | `format` | String | `table` | Output format (`table`, `json`, `sarif`) |
| `template` | String | | Output template (`@/contrib/sarif.tpl`, `@/contrib/gitlab.tpl`, `@/contrib/junit.tpl`)| | `template` | String | | Output template (`@/contrib/gitlab.tpl`, `@/contrib/junit.tpl`)|
| `output` | String | | Save results to a file | | `output` | String | | Save results to a file |
| `exit-code` | String | `0` | Exit code when specified vulnerabilities are found | | `exit-code` | String | `0` | Exit code when specified vulnerabilities are found |
| `ignore-unfixed` | Boolean | false | Ignore unpatched/unfixed vulnerabilities | | `ignore-unfixed` | Boolean | false | Ignore unpatched/unfixed vulnerabilities |
| `vuln-type` | String | `os,library` | Vulnerability types (os,library) | | `vuln-type` | String | `os,library` | Vulnerability types (os,library) |
| `severity` | String | `UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL` | Severities of vulnerabilities to scanned for and displayed | | `severity` | String | `UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL` | Severities of vulnerabilities to scanned for and displayed |
| `skip-dirs` | String | | Comma separated list of directories where traversal is skipped | | `skip-dirs` | String | | Comma separated list of directories where traversal is skipped |
| `skip-files` | String | | Comma separated list of files where traversal is skipped |
| `cache-dir` | String | | Cache directory | | `cache-dir` | String | | Cache directory |
| `timeout` | String | `2m0s` | Scan timeout duration | | `timeout` | String | `2m0s` | Scan timeout duration |
| `ignore-policy` | String | | Filter vulnerabilities with OPA rego language | | `ignore-policy` | String | | Filter vulnerabilities with OPA rego language |
| `list-all-pkgs` | String | | Output all packages regardless of vulnerability |
[release]: https://github.com/aquasecurity/trivy-action/releases/latest [release]: https://github.com/aquasecurity/trivy-action/releases/latest
[release-img]: https://img.shields.io/github/release/aquasecurity/trivy-action.svg?logo=github [release-img]: https://img.shields.io/github/release/aquasecurity/trivy-action.svg?logo=github
+10
View File
@@ -49,6 +49,10 @@ inputs:
description: 'comma separated list of directories where traversal is skipped' description: 'comma separated list of directories where traversal is skipped'
required: false required: false
default: '' default: ''
skip-files:
description: 'comma separated list of files to be skipped'
required: false
default: ''
cache-dir: cache-dir:
description: 'specify where the cache is stored' description: 'specify where the cache is stored'
required: false required: false
@@ -65,6 +69,10 @@ inputs:
description: 'hide progress output' description: 'hide progress output'
required: false required: false
default: 'true' default: 'true'
list-all-pkgs:
description: 'output all packages regardless of vulnerability'
required: false
default: 'false'
runs: runs:
using: 'docker' using: 'docker'
image: "Dockerfile" image: "Dockerfile"
@@ -85,3 +93,5 @@ runs:
- '-n ${{ inputs.timeout }}' - '-n ${{ inputs.timeout }}'
- '-o ${{ inputs.ignore-policy }}' - '-o ${{ inputs.ignore-policy }}'
- '-p ${{ inputs.hide-progress }}' - '-p ${{ inputs.hide-progress }}'
- '-q ${{ inputs.skip-files }}'
- '-r ${{ inputs.list-all-pkgs }}'
+35 -2
View File
@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
set -e set -e
while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:" o; do while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:" o; do
case "${o}" in case "${o}" in
a) a)
export scanType=${OPTARG} export scanType=${OPTARG}
@@ -50,12 +50,18 @@ while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:" o; do
p) p)
export hideProgress=${OPTARG} export hideProgress=${OPTARG}
;; ;;
q)
export skipFiles=${OPTARG}
;;
r)
export listAllPkgs=${OPTARG}
;;
esac esac
done done
scanType=$(echo $scanType | tr -d '\r') scanType=$(echo $scanType | tr -d '\r')
export artifactRef="${imageRef}" export artifactRef="${imageRef}"
if [ "${scanType}" = "fs" ] || [ "${scanType}" = "config" ];then if [ "${scanType}" = "fs" ] || [ "${scanType}" = "config" ] || [ "${scanType}" = "rootfs" ];then
artifactRef=$(echo $scanRef | tr -d '\r') artifactRef=$(echo $scanRef | tr -d '\r')
fi fi
input=$(echo $input | tr -d '\r') input=$(echo $input | tr -d '\r')
@@ -70,6 +76,7 @@ if [ $cacheDir ];then
GLOBAL_ARGS="$GLOBAL_ARGS --cache-dir $cacheDir" GLOBAL_ARGS="$GLOBAL_ARGS --cache-dir $cacheDir"
fi fi
SARIF_ARGS=""
ARGS="" ARGS=""
if [ $format ];then if [ $format ];then
ARGS="$ARGS --format $format" ARGS="$ARGS --format $format"
@@ -82,9 +89,11 @@ if [ $exitCode ];then
fi fi
if [ "$ignoreUnfixed" == "true" ] && [ "$scanType" != "config" ];then if [ "$ignoreUnfixed" == "true" ] && [ "$scanType" != "config" ];then
ARGS="$ARGS --ignore-unfixed" ARGS="$ARGS --ignore-unfixed"
SARIF_ARGS="$SARIF_ARGS --ignore-unfixed"
fi fi
if [ $vulnType ] && [ "$scanType" != "config" ];then if [ $vulnType ] && [ "$scanType" != "config" ];then
ARGS="$ARGS --vuln-type $vulnType" ARGS="$ARGS --vuln-type $vulnType"
SARIF_ARGS="$SARIF_ARGS --vuln-type $vulnType"
fi fi
if [ $severity ];then if [ $severity ];then
ARGS="$ARGS --severity $severity" ARGS="$ARGS --severity $severity"
@@ -96,6 +105,7 @@ if [ $skipDirs ];then
for i in $(echo $skipDirs | tr "," "\n") for i in $(echo $skipDirs | tr "," "\n")
do do
ARGS="$ARGS --skip-dirs $i" ARGS="$ARGS --skip-dirs $i"
SARIF_ARGS="$SARIF_ARGS --skip-dirs $i"
done done
fi fi
if [ $timeout ];then if [ $timeout ];then
@@ -103,11 +113,34 @@ if [ $timeout ];then
fi fi
if [ $ignorePolicy ];then if [ $ignorePolicy ];then
ARGS="$ARGS --ignore-policy $ignorePolicy" ARGS="$ARGS --ignore-policy $ignorePolicy"
SARIF_ARGS="$SARIF_ARGS --ignore-policy $ignorePolicy"
fi fi
if [ "$hideProgress" == "true" ];then if [ "$hideProgress" == "true" ];then
ARGS="$ARGS --no-progress" ARGS="$ARGS --no-progress"
fi fi
listAllPkgs=$(echo $listAllPkgs | tr -d '\r')
if [ "$listAllPkgs" == "true" ];then
ARGS="$ARGS --list-all-pkgs"
fi
if [ "$skipFiles" ];then
for i in $(echo $skipFiles | tr "," "\n")
do
ARGS="$ARGS --skip-files $i"
done
fi
echo "Running trivy with options: ${ARGS}" "${artifactRef}" echo "Running trivy with options: ${ARGS}" "${artifactRef}"
echo "Global options: " "${GLOBAL_ARGS}" echo "Global options: " "${GLOBAL_ARGS}"
trivy $GLOBAL_ARGS ${scanType} $ARGS ${artifactRef} trivy $GLOBAL_ARGS ${scanType} $ARGS ${artifactRef}
returnCode=$?
# SARIF is special. We output all vulnerabilities,
# regardless of severity level specified in this report.
# This is a feature, not a bug :)
if [[ "${format}" == "sarif" ]]; then
echo "Building SARIF report with options: ${SARIF_ARGS}" "${artifactRef}"
trivy --quiet ${scanType} --format sarif --output ${output} $SARIF_ARGS ${artifactRef}
fi
exit $returnCode