Compare commits

...

5 Commits

Author SHA1 Message Date
Simar
d62898dfb3 Bump to latest Trivy release 2021-10-26 11:44:53 -07:00
Emil Lengman
6bce46377c bump to version 0.20.0 to add requirements.txt support (#69) 2021-10-26 11:43:48 -07:00
Simar
101d9bacf6 Update action.yaml 2021-10-26 11:42:59 -07:00
Peter Kipping
8eccb55397 Bump base image version to 0.19.2 to fix issue with config scanning. (#58) 2021-08-17 11:50:20 -07:00
Brandon Sorgdrager
9438b49cc3 Enable config scanning (#56)
* Bump trivy image to enable use of config scan-type

* move --no-progress switch behind input arg and set default

* prevent unrelated args from passing with config scan-type

* fix invalid option passing

* set artifactRef if scanType = config

* Add workflow example for IAC/YAML scanning

* Update README.md

Co-authored-by: Simar <1254783+simar7@users.noreply.github.com>

* Update README.md

Co-authored-by: Simar <1254783+simar7@users.noreply.github.com>

* clean hideProgress input

Co-authored-by: Simar <1254783+simar7@users.noreply.github.com>
2021-07-27 14:49:55 -07:00
4 changed files with 56 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
FROM aquasec/trivy:0.18.1
FROM aquasec/trivy:0.20.2
COPY entrypoint.sh /
RUN apk --no-cache add bash
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -123,6 +123,41 @@ jobs:
sarif_file: 'trivy-results.sarif'
```
### Using Trivy to scan Infrastucture as Code
It's also possible to scan your IaC 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: Run Trivy vulnerability scanner in IaC mode
uses: aquasecurity/trivy-action@master
with:
scan-type: 'config'
hide-progress: false
format: 'table'
exit-code: '1'
ignore-unfixed: true
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'
```
### Using Trivy to scan your private registry
It's also possible to scan your private registry with Trivy's built-in image scan. All you have to do is set ENV vars.

View File

@@ -54,13 +54,17 @@ inputs:
required: false
default: ''
timeout:
description: 'timeout (default 2m0s)'
description: 'timeout (default 5m0s)'
required: false
default: ''
ignore-policy:
description: 'filter vulnerabilities with OPA rego language'
required: false
default: ''
hide-progress:
description: 'hide progress output'
required: false
default: 'true'
runs:
using: 'docker'
image: "Dockerfile"
@@ -80,3 +84,4 @@ runs:
- '-m ${{ inputs.cache-dir }}'
- '-n ${{ inputs.timeout }}'
- '-o ${{ inputs.ignore-policy }}'
- '-p ${{ inputs.hide-progress }}'

View File

@@ -1,6 +1,6 @@
#!/bin/bash
set -e
while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:" o; do
while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:" o; do
case "${o}" in
a)
export scanType=${OPTARG}
@@ -47,12 +47,15 @@ while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:" o; do
o)
export ignorePolicy=${OPTARG}
;;
p)
export hideProgress=${OPTARG}
;;
esac
done
scanType=$(echo $scanType | tr -d '\r')
export artifactRef="${imageRef}"
if [ "${scanType}" = "fs" ];then
if [ "${scanType}" = "fs" ] || [ "${scanType}" = "config" ];then
artifactRef=$(echo $scanRef | tr -d '\r')
fi
input=$(echo $input | tr -d '\r')
@@ -60,6 +63,7 @@ if [ $input ]; then
artifactRef="--input $input"
fi
ignoreUnfixed=$(echo $ignoreUnfixed | tr -d '\r')
hideProgress=$(echo $hideProgress | tr -d '\r')
GLOBAL_ARGS=""
if [ $cacheDir ];then
@@ -76,10 +80,10 @@ fi
if [ $exitCode ];then
ARGS="$ARGS --exit-code $exitCode"
fi
if [ "$ignoreUnfixed" == "true" ];then
if [ "$ignoreUnfixed" == "true" ] && [ "$scanType" != "config" ];then
ARGS="$ARGS --ignore-unfixed"
fi
if [ $vulnType ];then
if [ $vulnType ] && [ "$scanType" != "config" ];then
ARGS="$ARGS --vuln-type $vulnType"
fi
if [ $severity ];then
@@ -100,7 +104,10 @@ fi
if [ $ignorePolicy ];then
ARGS="$ARGS --ignore-policy $ignorePolicy"
fi
if [ "$hideProgress" == "true" ];then
ARGS="$ARGS --no-progress"
fi
echo "Running trivy with options: " --no-progress "${ARGS}" "${artifactRef}"
echo "Running trivy with options: ${ARGS}" "${artifactRef}"
echo "Global options: " "${GLOBAL_ARGS}"
trivy $GLOBAL_ARGS ${scanType} --no-progress $ARGS ${artifactRef}
trivy $GLOBAL_ARGS ${scanType} $ARGS ${artifactRef}