Skip to content

Commit 9438b49

Browse files
bsordsimar7
andauthored
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>
1 parent ac8de07 commit 9438b49

4 files changed

Lines changed: 54 additions & 7 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM aquasec/trivy:0.18.1
1+
FROM aquasec/trivy:0.19.1
22
COPY entrypoint.sh /
33
RUN apk --no-cache add bash
44
RUN chmod +x /entrypoint.sh

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,41 @@ jobs:
123123
sarif_file: 'trivy-results.sarif'
124124
```
125125
126+
### Using Trivy to scan Infrastucture as Code
127+
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.
128+
129+
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:
130+
```yaml
131+
name: build
132+
on:
133+
push:
134+
branches:
135+
- master
136+
pull_request:
137+
jobs:
138+
build:
139+
name: Build
140+
runs-on: ubuntu-18.04
141+
steps:
142+
- name: Checkout code
143+
uses: actions/checkout@v2
144+
145+
- name: Run Trivy vulnerability scanner in IaC mode
146+
uses: aquasecurity/trivy-action@master
147+
with:
148+
scan-type: 'config'
149+
hide-progress: false
150+
format: 'table'
151+
exit-code: '1'
152+
ignore-unfixed: true
153+
severity: 'CRITICAL,HIGH'
154+
155+
- name: Upload Trivy scan results to GitHub Security tab
156+
uses: github/codeql-action/upload-sarif@v1
157+
with:
158+
sarif_file: 'trivy-results.sarif'
159+
```
160+
126161
### Using Trivy to scan your private registry
127162
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.
128163

action.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ inputs:
6161
description: 'filter vulnerabilities with OPA rego language'
6262
required: false
6363
default: ''
64+
hide-progress:
65+
description: 'hide progress output'
66+
required: false
67+
default: 'true'
6468
runs:
6569
using: 'docker'
6670
image: "Dockerfile"
@@ -80,3 +84,4 @@ runs:
8084
- '-m ${{ inputs.cache-dir }}'
8185
- '-n ${{ inputs.timeout }}'
8286
- '-o ${{ inputs.ignore-policy }}'
87+
- '-p ${{ inputs.hide-progress }}'

entrypoint.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
set -e
3-
while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:" o; do
3+
while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:" o; do
44
case "${o}" in
55
a)
66
export scanType=${OPTARG}
@@ -47,19 +47,23 @@ while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:" o; do
4747
o)
4848
export ignorePolicy=${OPTARG}
4949
;;
50+
p)
51+
export hideProgress=${OPTARG}
52+
;;
5053
esac
5154
done
5255

5356
scanType=$(echo $scanType | tr -d '\r')
5457
export artifactRef="${imageRef}"
55-
if [ "${scanType}" = "fs" ];then
58+
if [ "${scanType}" = "fs" ] || [ "${scanType}" = "config" ];then
5659
artifactRef=$(echo $scanRef | tr -d '\r')
5760
fi
5861
input=$(echo $input | tr -d '\r')
5962
if [ $input ]; then
6063
artifactRef="--input $input"
6164
fi
6265
ignoreUnfixed=$(echo $ignoreUnfixed | tr -d '\r')
66+
hideProgress=$(echo $hideProgress | tr -d '\r')
6367

6468
GLOBAL_ARGS=""
6569
if [ $cacheDir ];then
@@ -76,10 +80,10 @@ fi
7680
if [ $exitCode ];then
7781
ARGS="$ARGS --exit-code $exitCode"
7882
fi
79-
if [ "$ignoreUnfixed" == "true" ];then
83+
if [ "$ignoreUnfixed" == "true" ] && [ "$scanType" != "config" ];then
8084
ARGS="$ARGS --ignore-unfixed"
8185
fi
82-
if [ $vulnType ];then
86+
if [ $vulnType ] && [ "$scanType" != "config" ];then
8387
ARGS="$ARGS --vuln-type $vulnType"
8488
fi
8589
if [ $severity ];then
@@ -100,7 +104,10 @@ fi
100104
if [ $ignorePolicy ];then
101105
ARGS="$ARGS --ignore-policy $ignorePolicy"
102106
fi
107+
if [ "$hideProgress" == "true" ];then
108+
ARGS="$ARGS --no-progress"
109+
fi
103110

104-
echo "Running trivy with options: " --no-progress "${ARGS}" "${artifactRef}"
111+
echo "Running trivy with options: ${ARGS}" "${artifactRef}"
105112
echo "Global options: " "${GLOBAL_ARGS}"
106-
trivy $GLOBAL_ARGS ${scanType} --no-progress $ARGS ${artifactRef}
113+
trivy $GLOBAL_ARGS ${scanType} $ARGS ${artifactRef}

0 commit comments

Comments
 (0)