-
Notifications
You must be signed in to change notification settings - Fork 2
67 lines (57 loc) · 2.05 KB
/
vulnerability_scanning.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: Workflow to scan vulnerability
on:
workflow_call:
inputs:
docker_tags:
type: string
required: true
runner:
## ['cn', 'us', 'cn1', 'cn2', 'cn3', 'us1', 'us2', 'us3', ' ubuntu-latest']
type: string
required: true
trivyignores:
type: string
required: false
default: ""
jobs:
scanning:
name: vulnerability scanning
runs-on: ${{ inputs.runner }}
timeout-minutes: 20
steps:
- id: trivy-db
name: Check trivy db sha
env:
GH_TOKEN: ${{ github.token }}
run: |
endpoint='/orgs/aquasecurity/packages/container/trivy-db/versions'
headers='Accept: application/vnd.github+json'
jqFilter='.[] | select(.metadata.container.tags[] | contains("latest")) | .name | sub("sha256:";"")'
sha=$(gh api -H "${headers}" "${endpoint}" | jq --raw-output "${jqFilter}")
echo "Trivy DB sha256:${sha}"
echo "::set-output name=sha::${sha}"
- uses: actions/cache@v3
with:
path: .trivy
key: ${{ runner.os }}-trivy-db-${{ steps.trivy-db.outputs.sha }}
# TODO : add global trivy ignore
- name: Run Trivy vulnerability scanner in image mode
uses: aquasecurity/trivy-action@master
with:
# image-ref: ${{ secrets.REGISTRY }}/${{ inputs.project }}/${{ inputs.component }}:${{ inputs.docker_image_version }}
image-ref: ${{ inputs.docker_tags }}
format: 'table'
exit-code: '1'
hide-progress: true
ignore-unfixed: true
cache-dir: .trivy
# vuln-type: 'os,library'
trivyignores: '${{ inputs.trivyignores }}'
severity: 'UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL'
- name: Fix .trivy permissions
if: always()
run: sudo chown -R $(stat . -c %u:%g) .trivy
- name: clean local docker images after scanning.
if: always()
run: |
docker rmi -f $(docker images --filter="reference=${{ inputs.docker_tags }}" --quiet)