Compare commits
30
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f85b76679f | ||
|
|
bceef37a45 | ||
|
|
7294c6a408 | ||
|
|
df28e4135d | ||
|
|
1d28acf359 | ||
|
|
7684771c94 | ||
|
|
8595c5d059 | ||
|
|
d8496b917f | ||
|
|
ddc1a12251 | ||
|
|
2e51a7d82c | ||
|
|
6087d9d64e | ||
|
|
888827683a | ||
|
|
7e2e12baea | ||
|
|
202e8283bd | ||
|
|
507a96efe4 | ||
|
|
6c3dd513ad | ||
|
|
2b5de51086 | ||
|
|
de7cb7d4ba | ||
|
|
9403afcefd | ||
|
|
28ef387ad0 | ||
|
|
159e7e8ec2 | ||
|
|
4edb45e6ff | ||
|
|
6d50808eba | ||
|
|
8cc32f763c | ||
|
|
3fadcda6be | ||
|
|
d424596f39 | ||
|
|
6b9375bd16 | ||
|
|
f498173417 | ||
|
|
c88ebc55b9 | ||
|
|
1eb53c0425 |
@@ -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"]
|
||||||
@@ -1,15 +1,19 @@
|
|||||||
# Trivy Action
|
# Trivy Action
|
||||||
|
|
||||||
> [GitHub Action](https://github.com/features/actions) for Trivy
|
> [GitHub Action](https://github.com/features/actions) for [Trivy](https://github.com/aquasecurity/trivy)
|
||||||
|
|
||||||
[![GitHub Release][release-img]][release]
|
[![GitHub Release][release-img]][release]
|
||||||
[![GitHub Marketplace][marketplace-img]][marketplace]
|
[![GitHub Marketplace][marketplace-img]][marketplace]
|
||||||
[![License][license-img]][license]
|
[![License][license-img]][license]
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
- [Workflow](#workflow)
|
- [Workflow](#workflow)
|
||||||
|
- [Docker Image Scanning](#using-trivy-with-github-code-scanning)
|
||||||
|
- [Git Repository Scanning](#using-trivy-to-scan-your-git-repo)
|
||||||
- [Customizing](#customizing)
|
- [Customizing](#customizing)
|
||||||
- [Inputs](#inputs)
|
- [Inputs](#inputs)
|
||||||
|
|
||||||
@@ -29,41 +33,122 @@ jobs:
|
|||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-18.04
|
runs-on: ubuntu-18.04
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v1
|
|
||||||
with:
|
|
||||||
go-version: 1.14
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Build an image from Dockerfile
|
- name: Build an image from Dockerfile
|
||||||
run: |
|
run: |
|
||||||
docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
|
docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
|
||||||
- name: Run vulnerability scanner
|
|
||||||
uses: aquasecurity/trivy-action@0.0.5
|
- name: Run Trivy vulnerability scanner
|
||||||
|
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: 'table'
|
format: 'table'
|
||||||
exit-code: '1'
|
exit-code: '1'
|
||||||
|
ignore-unfixed: true
|
||||||
|
vuln-type: 'os,library'
|
||||||
severity: 'CRITICAL,HIGH'
|
severity: 'CRITICAL,HIGH'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Using Trivy with GitHub Code Scanning
|
||||||
|
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
|
||||||
|
uses: aquasecurity/trivy-action@master
|
||||||
|
with:
|
||||||
|
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
|
||||||
|
format: 'template'
|
||||||
|
template: '@/contrib/sarif.tpl'
|
||||||
|
output: 'trivy-results.sarif'
|
||||||
|
|
||||||
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
|
uses: github/codeql-action/upload-sarif@v1
|
||||||
|
with:
|
||||||
|
sarif_file: 'trivy-results.sarif'
|
||||||
|
```
|
||||||
|
|
||||||
|
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
|
## Customizing
|
||||||
|
|
||||||
### inputs
|
### inputs
|
||||||
|
|
||||||
Following inputs can be used as `step.with` keys:
|
Following inputs can be used as `step.with` keys:
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|-------------|--------|------------------------------------|-----------------------------------------------|
|
|------------------|---------|------------------------------------|-----------------------------------------------|
|
||||||
| `image-ref` | String | | Image reference, e.g. `alpine:3.10.2` |
|
| `scan-type` | String | `image` | Scan type, e.g. `image` or `fs`|
|
||||||
| `format` | String | `table` | Output format (`table`, `json`) |
|
| `image-ref` | String | | Image reference, e.g. `alpine:3.10.2` |
|
||||||
| `exit-code` | String | `0` | exit code when vulnerabilities were found |
|
| `scan-ref` | String | `/github/workspace/` | Scan reference, e.g. `/github/workspace/` or `.`|
|
||||||
| `severity` | String | `UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL` | severities of vulnerabilities to be displayed |
|
| `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 |
|
||||||
|
| `exit-code` | String | `0` | Exit code when vulnerabilities were found |
|
||||||
|
| `ignore-unfixed` | Boolean | false | Ignore unpatched/unfixed vulnerabilities |
|
||||||
|
| `vuln-type` | String | `os,library` | Vulnerability types (os,library) |
|
||||||
|
| `severity` | String | `UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL` | Severities of vulnerabilities to be displayed |
|
||||||
|
|
||||||
[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
|
||||||
[marketplace]: https://github.com/marketplace/actions/trivy-vulnerability-scanner
|
[marketplace]: https://github.com/marketplace/actions/aqua-security-trivy
|
||||||
[marketplace-img]: https://img.shields.io/badge/marketplace-trivy--action-blue?logo=github
|
[marketplace-img]: https://img.shields.io/badge/marketplace-trivy--action-blue?logo=github
|
||||||
[license]: https://github.com/aquasecurity/trivy-action/blob/master/LICENSE
|
[license]: https://github.com/aquasecurity/trivy-action/blob/master/LICENSE
|
||||||
[license-img]: https://img.shields.io/github/license/aquasecurity/trivy-action
|
[license-img]: https://img.shields.io/github/license/aquasecurity/trivy-action
|
||||||
|
|||||||
+39
-10
@@ -1,28 +1,57 @@
|
|||||||
name: 'Trivy Vulnerability Scanner'
|
name: 'Aqua Security Trivy'
|
||||||
description: 'Scan container image for vulnerabilities with Trivy'
|
description: 'Scans container images for vulnerabilities with Trivy'
|
||||||
author: 'Aqua Security'
|
author: 'Aqua Security'
|
||||||
inputs:
|
inputs:
|
||||||
|
scan-type:
|
||||||
|
description: 'Scan type to use for scanning vulnerability'
|
||||||
|
required: false
|
||||||
|
default: 'image'
|
||||||
image-ref:
|
image-ref:
|
||||||
description: 'image reference'
|
description: 'image reference(for backward compatibility)'
|
||||||
required: true
|
required: true
|
||||||
|
scan-ref:
|
||||||
|
description: 'Scan reference'
|
||||||
|
required: false
|
||||||
|
default: '.'
|
||||||
exit-code:
|
exit-code:
|
||||||
description: 'exit code when vulnerabilities were found'
|
description: 'exit code when vulnerabilities were found'
|
||||||
required: false
|
required: false
|
||||||
default: '0'
|
default: '0'
|
||||||
|
ignore-unfixed:
|
||||||
|
description: 'ignore unfixed vulnerabilities'
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
|
vuln-type:
|
||||||
|
description: 'comma-separated list of vulnerability types (os,library)'
|
||||||
|
required: false
|
||||||
|
default: 'os,library'
|
||||||
severity:
|
severity:
|
||||||
description: 'severities of vulnerabilities to be displayed'
|
description: 'severities of vulnerabilities to be displayed'
|
||||||
required: false
|
required: false
|
||||||
default: 'UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL'
|
default: 'UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL'
|
||||||
format:
|
format:
|
||||||
description: 'output format (table, json)'
|
description: 'output format (table, json, template)'
|
||||||
required: false
|
required: false
|
||||||
default: 'table'
|
default: 'table'
|
||||||
|
template:
|
||||||
|
description: 'use an existing template for rendering output (@/contrib/sarif.tpl, @/contrib/gitlab.tpl, @/contrib/junit.tpl'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
output:
|
||||||
|
description: 'writes results to a file with the specified file name'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: 'docker://docker.io/aquasec/trivy:latest'
|
image: "Dockerfile"
|
||||||
args:
|
args:
|
||||||
- 'image'
|
- '-a ${{ inputs.scan-type }}'
|
||||||
- '--format=${{ inputs.format }}'
|
- '-b ${{ inputs.format }}'
|
||||||
- '--exit-code=${{ inputs.exit-code }}'
|
- '-c ${{ inputs.template }}'
|
||||||
- '--severity=${{ inputs.severity }}'
|
- '-d ${{ inputs.exit-code }}'
|
||||||
- '${{ inputs.image-ref }}'
|
- '-e ${{ inputs.ignore-unfixed }}'
|
||||||
|
- '-f ${{ inputs.vuln-type }}'
|
||||||
|
- '-g ${{ inputs.severity }}'
|
||||||
|
- '-h ${{ inputs.output }}'
|
||||||
|
- '-i ${{ inputs.image-ref }}'
|
||||||
|
- '-j ${{ inputs.scan-ref }}'
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 505 KiB |
@@ -0,0 +1,69 @@
|
|||||||
|
#!/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
|
||||||
|
ignoreUnfixed=$(echo $ignoreUnfixed | tr -d '\r')
|
||||||
|
|
||||||
|
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 "Running trivy with options: " "${ARGS}" "${artifactRef}"
|
||||||
|
trivy ${scanType} --no-progress $ARGS ${artifactRef}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
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 }}'
|
||||||
|
exit-code: '1'
|
||||||
|
ignore-unfixed: true
|
||||||
|
vuln-type: 'os,library'
|
||||||
|
format: 'template'
|
||||||
|
template: '@/contrib/sarif.tpl'
|
||||||
|
output: 'trivy-results.sarif'
|
||||||
|
severity: 'CRITICAL,HIGH'
|
||||||
|
|
||||||
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
|
uses: github/codeql-action/upload-sarif@v1
|
||||||
|
with:
|
||||||
|
sarif_file: 'trivy-results.sarif'
|
||||||
Reference in New Issue
Block a user