Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7294c6a408 | ||
|
|
df28e4135d | ||
|
|
1d28acf359 |
@@ -0,0 +1,5 @@
|
||||
FROM aquasec/trivy:latest
|
||||
COPY entrypoint.sh /
|
||||
RUN apk --no-cache add bash
|
||||
RUN chmod +x /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
@@ -12,6 +12,8 @@
|
||||
|
||||
- [Usage](#usage)
|
||||
- [Workflow](#workflow)
|
||||
- [Docker Image Scanning](#using-trivy-with-github-code-scanning)
|
||||
- [Git Repository Scanning](#using-trivy-to-scan-your-git-repo)
|
||||
- [Customizing](#customizing)
|
||||
- [Inputs](#inputs)
|
||||
|
||||
@@ -86,6 +88,45 @@ jobs:
|
||||
|
||||
You can find a more in-depth example here: https://github.com/aquasecurity/trivy-sarif-demo/blob/master/.github/workflows/scan.yml
|
||||
|
||||
### 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.
|
||||
|
||||
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: Build an image from Dockerfile
|
||||
run: |
|
||||
docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
|
||||
|
||||
- name: Run Trivy vulnerability scanner in repo mode
|
||||
uses: aquasecurity/trivy-action@master
|
||||
with:
|
||||
scan-type: 'fs'
|
||||
ignore-unfixed: true
|
||||
format: 'template'
|
||||
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'
|
||||
```
|
||||
|
||||
## Customizing
|
||||
|
||||
### inputs
|
||||
@@ -94,7 +135,9 @@ Following inputs can be used as `step.with` keys:
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
|------------------|---------|------------------------------------|-----------------------------------------------|
|
||||
| `scan-type` | String | `image` | Scan type, e.g. `image` or `fs`|
|
||||
| `image-ref` | String | | Image reference, e.g. `alpine:3.10.2` |
|
||||
| `scan-ref` | String | `/github/workspace/` | Scan reference, e.g. `/github/workspace/` or `.`|
|
||||
| `format` | String | `table` | Output format (`table`, `json`, `template`) |
|
||||
| `template` | String | | Output template (`@/contrib/sarif.tpl`, `@/contrib/gitlab.tpl`, `@/contrib/junit.tpl`)|
|
||||
| `output` | String | | Save results to a file |
|
||||
|
||||
+21
-19
@@ -2,16 +2,17 @@ name: 'Aqua Security Trivy'
|
||||
description: 'Scans container images for vulnerabilities with Trivy'
|
||||
author: 'Aqua Security'
|
||||
inputs:
|
||||
scan-type:
|
||||
description: 'Scan type to use for scanning vulnerability'
|
||||
required: false
|
||||
default: 'image'
|
||||
image-ref:
|
||||
description: 'image reference'
|
||||
required: true
|
||||
artifact-type:
|
||||
description: 'artifact type (image or fs)'
|
||||
required: true
|
||||
default: "image"
|
||||
aritfact-ref:
|
||||
description: 'artifact reference (image reference or file path)'
|
||||
description: 'image reference(for backward compatibility)'
|
||||
required: true
|
||||
scan-ref:
|
||||
description: 'Scan reference'
|
||||
required: false
|
||||
default: '.'
|
||||
exit-code:
|
||||
description: 'exit code when vulnerabilities were found'
|
||||
required: false
|
||||
@@ -19,7 +20,7 @@ inputs:
|
||||
ignore-unfixed:
|
||||
description: 'ignore unfixed vulnerabilities'
|
||||
required: false
|
||||
default: "false"
|
||||
default: 'false'
|
||||
vuln-type:
|
||||
description: 'comma-separated list of vulnerability types (os,library)'
|
||||
required: false
|
||||
@@ -42,14 +43,15 @@ inputs:
|
||||
default: ''
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'docker://docker.io/aquasec/trivy:latest'
|
||||
image: "Dockerfile"
|
||||
args:
|
||||
- '${{ inputs.artifact-type }}'
|
||||
- '--format=${{ inputs.format }}'
|
||||
- '--template=${{ inputs.template }}'
|
||||
- '--exit-code=${{ inputs.exit-code }}'
|
||||
- '--ignore-unfixed=${{ inputs.ignore-unfixed }}'
|
||||
- '--vuln-type=${{ inputs.vuln-type }}'
|
||||
- '--severity=${{ inputs.severity }}'
|
||||
- '--output=${{ inputs.output }}'
|
||||
- '${{ inputs.artifact-ref }}'
|
||||
- '-a ${{ inputs.scan-type }}'
|
||||
- '-b ${{ inputs.format }}'
|
||||
- '-c ${{ inputs.template }}'
|
||||
- '-d ${{ inputs.exit-code }}'
|
||||
- '-e ${{ inputs.ignore-unfixed }}'
|
||||
- '-f ${{ inputs.vuln-type }}'
|
||||
- '-g ${{ inputs.severity }}'
|
||||
- '-h ${{ inputs.output }}'
|
||||
- '-i ${{ inputs.image-ref }}'
|
||||
- '-j ${{ inputs.scan-ref }}'
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
while getopts "a:b:c:d:e:f:g:h:i:j:" o; do
|
||||
case "${o}" in
|
||||
a)
|
||||
export scanType=${OPTARG}
|
||||
;;
|
||||
b)
|
||||
export format=${OPTARG}
|
||||
;;
|
||||
c)
|
||||
export template=${OPTARG}
|
||||
;;
|
||||
d)
|
||||
export exitCode=${OPTARG}
|
||||
;;
|
||||
e)
|
||||
export ignoreUnfixed=${OPTARG}
|
||||
;;
|
||||
f)
|
||||
export vulnType=${OPTARG}
|
||||
;;
|
||||
g)
|
||||
export severity=${OPTARG}
|
||||
;;
|
||||
h)
|
||||
export output=${OPTARG}
|
||||
;;
|
||||
i)
|
||||
export imageRef=${OPTARG}
|
||||
;;
|
||||
j)
|
||||
export scanRef=${OPTARG}
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
scanType=$(echo $scanType | tr -d '\r')
|
||||
export artifactRef="${imageRef}"
|
||||
if [ "${scanType}" = "fs" ];then
|
||||
artifactRef=$(echo $scanRef | tr -d '\r')
|
||||
fi
|
||||
|
||||
ARGS=""
|
||||
if [ $format ];then
|
||||
ARGS="$ARGS --format $format"
|
||||
fi
|
||||
if [ $template ] ;then
|
||||
ARGS="$ARGS --template $template"
|
||||
fi
|
||||
if [ $exitCode ];then
|
||||
ARGS="$ARGS --exit-code $exitCode"
|
||||
fi
|
||||
if [ "$ignoreUnfixed" == "true" ];then
|
||||
ARGS="$ARGS --ignore-unfixed"
|
||||
fi
|
||||
if [ $vulnType ];then
|
||||
ARGS="$ARGS --vuln-type $vulnType"
|
||||
fi
|
||||
if [ $severity ];then
|
||||
ARGS="$ARGS --severity $severity"
|
||||
fi
|
||||
if [ $output ];then
|
||||
ARGS="$ARGS --output $output"
|
||||
fi
|
||||
|
||||
echo "Runnin trivy with options" "${ARGS}" "${artifactRef}"
|
||||
trivy ${scanType} $ARGS ${artifactRef}
|
||||
Reference in New Issue
Block a user