1+ # https://aquasecurity.github.io/trivy
12name : Trivy
23
34on :
45 pull_request :
56 push :
67 branches :
78 - main
8- - master
9+
10+ env :
11+ # Use the Go toolchain installed by setup-go
12+ # https://github.com/actions/setup-go/issues/457
13+ GOTOOLCHAIN : local
914
1015jobs :
16+ cache :
17+ # Run only one of these jobs at a time across the entire project.
18+ concurrency : { group: trivy-cache }
19+ # Do not fail this workflow when this job fails.
20+ continue-on-error : true
21+
22+ runs-on : ubuntu-latest
23+ steps :
24+ - uses : actions/checkout@v4
25+ - name : Download Trivy
26+ uses : ./.github/actions/trivy
27+ env :
28+ TRIVY_DEBUG : true
29+ TRIVY_DOWNLOAD_DB_ONLY : true
30+ TRIVY_NO_PROGRESS : true
31+ TRIVY_SCANNERS : license,secret,vuln
32+
1133 licenses :
34+ # Run this job after the cache job regardless of its success or failure.
35+ needs : [cache]
36+ if : >-
37+ ${{ !cancelled() }}
38+
1239 runs-on : ubuntu-latest
1340 steps :
1441 - uses : actions/checkout@v4
@@ -20,52 +47,56 @@ jobs:
2047
2148 # Report success only when detected licenses are listed in [/trivy.yaml].
2249 - name : Scan licenses
23- uses :
aquasecurity/[email protected] 50+ uses : ./.github/actions/trivy
2451 env :
2552 TRIVY_DEBUG : true
53+ TRIVY_EXIT_CODE : 1
54+ TRIVY_SCANNERS : license
2655 with :
27- scan-type : filesystem
28- scanners : license
29- exit-code : 1
56+ cache : restore,use
57+ database : skip
3058
3159 vulnerabilities :
32- if : ${{ github.repository == 'CrunchyData/postgres-operator' }}
33-
60+ # Run this job after the cache job regardless of its success or failure.
61+ needs : [cache]
62+ if : >-
63+ ${{ github.repository == 'CrunchyData/postgres-operator' && !cancelled() }}
3464 permissions :
35- # for github/codeql-action/upload-sarif to upload SARIF results
36- security-events : write
65+ security-events : write
3766
3867 runs-on : ubuntu-latest
39-
4068 steps :
4169 - uses : actions/checkout@v4
4270
43- # Run trivy and log detected and fixed vulnerabilities
44- # This report should match the uploaded code scan report below
45- # and is a convenience/redundant effort for those who prefer to
46- # read logs and/or if anything goes wrong with the upload.
47- - name : Log all detected vulnerabilities
48- uses :
aquasecurity/[email protected] 71+ # Print any detected secrets or vulnerabilities to the workflow log for
72+ # human consumption. This step fails only when Trivy is unable to scan.
73+ # A later step uploads results to GitHub as a pull request check.
74+ - name : Log detected vulnerabilities
75+ uses : ./.github/actions/trivy
76+ env :
77+ TRIVY_SCANNERS : secret,vuln
4978 with :
50- scan-type : filesystem
51- hide-progress : true
52- ignore-unfixed : true
53- scanners : secret,vuln
79+ cache : restore,use
80+ database : skip
5481
55- # Upload actionable results to the GitHub Security tab.
56- # Pull request checks fail according to repository settings.
57- # - https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github
58- # - https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning
82+ # Produce a SARIF report of actionable results. This step fails only when
83+ # Trivy is unable to scan.
5984 - name : Report actionable vulnerabilities
60- uses :
aquasecurity/[email protected] 85+ uses : ./.github/actions/trivy
86+ env :
87+ TRIVY_IGNORE_UNFIXED : true
88+ TRIVY_FORMAT : ' sarif'
89+ TRIVY_OUTPUT : ' trivy-results.sarif'
90+ TRIVY_SCANNERS : secret,vuln
6191 with :
62- scan-type : filesystem
63- ignore-unfixed : true
64- format : ' sarif'
65- output : ' trivy-results.sarif'
66- scanners : secret,vuln
92+ cache : use
93+ database : skip
94+ setup : none
6795
68- - name : Upload Trivy scan results to GitHub Security tab
96+ # Submit the SARIF report to GitHub code scanning. Pull requests checks
97+ # succeed or fail according to branch protection rules.
98+ # - https://docs.github.com/en/code-security/code-scanning
99+ - name : Upload results to GitHub
69100 uses : github/codeql-action/upload-sarif@v3
70101 with :
71102 sarif_file : ' trivy-results.sarif'
0 commit comments