Skip to content

Commit cdb56c6

Browse files
committed
workflow: improve trivy vulnerability scanning
Fail trivy vuln scan cleanly and create a periodic trivy scan to upload results to Github's security. Signed-off-by: Tuomas Katila <[email protected]>
1 parent 3a32b64 commit cdb56c6

File tree

3 files changed

+34
-44
lines changed

3 files changed

+34
-44
lines changed

.github/workflows/devel.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ jobs:
1515
contents: read
1616
security-events: write
1717
uses: "./.github/workflows/lib-trivy.yaml"
18-
with:
19-
upload-to-github-security-tab: true
2018

2119
validate:
2220
uses: "./.github/workflows/lib-validate.yaml"

.github/workflows/lib-trivy.yaml

-42
Original file line numberDiff line numberDiff line change
@@ -81,52 +81,10 @@ jobs:
8181
- name: Checkout
8282
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
8383
- name: Run Trivy in fs mode
84-
continue-on-error: true
8584
uses: aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # 0.29.0
8685
with:
8786
scan-type: fs
8887
scan-ref: .
8988
exit-code: 1
9089
list-all-pkgs: true
91-
format: json
92-
output: trivy-report.json
93-
- name: Show report in human-readable format
94-
uses: aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # 0.29.0
95-
with:
96-
scan-type: convert
97-
vuln-type: ''
98-
severity: ''
99-
image-ref: trivy-report.json
10090
format: table
101-
- name: Convert report to sarif
102-
if: ${{ inputs.upload-to-github-security-tab }}
103-
uses: aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # 0.29.0
104-
with:
105-
scan-type: convert
106-
vuln-type: ''
107-
severity: ''
108-
image-ref: trivy-report.json
109-
format: sarif
110-
output: trivy-report.sarif
111-
- name: Upload sarif report to GitHub Security tab
112-
if: ${{ inputs.upload-to-github-security-tab }}
113-
uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3
114-
with:
115-
sarif_file: trivy-report.sarif
116-
- name: Convert report to csv
117-
if: ${{ inputs.export-csv }}
118-
uses: aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # 0.29.0
119-
with:
120-
scan-type: convert
121-
vuln-type: ''
122-
severity: ''
123-
image-ref: trivy-report.json
124-
format: template
125-
template: "@.github/workflows/template/trivy-csv.tpl"
126-
output: trivy-report.csv
127-
- name: Upload CSV report as an artifact
128-
if: ${{ inputs.export-csv }}
129-
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
130-
with:
131-
name: trivy-report
132-
path: trivy-report.csv

.github/workflows/trivy-periodic.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Trivy vuln scan to Github Security
2+
on:
3+
schedule:
4+
- cron: '0 3 * * *'
5+
6+
permissions:
7+
contents: read
8+
security-events: write
9+
actions: read
10+
11+
jobs:
12+
trivy-scan-vulns:
13+
permissions:
14+
security-events: write
15+
runs-on: ubuntu-24.04
16+
name: Scan vulnerabilities
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
20+
- name: Run Trivy in fs mode
21+
# Don't fail in case of vulnerabilities, report them in the next step
22+
continue-on-error: true
23+
uses: aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # 0.29.0
24+
with:
25+
scan-type: fs
26+
scan-ref: .
27+
exit-code: 1
28+
list-all-pkgs: true
29+
format: sarif
30+
output: trivy-report.sarif
31+
- name: Upload sarif report to GitHub Security tab
32+
uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3
33+
with:
34+
sarif_file: trivy-report.sarif

0 commit comments

Comments
 (0)