1010 # every UTC 6PM from Mon to Fri
1111 - cron : " 0 18 * * 1-5"
1212
13- # Declare default permissions as read only.
14- permissions : read-all
13+ permissions : {}
1514
1615jobs :
17- Trivy-scan :
18- runs-on : ubuntu-latest
16+ Trivy :
17+ runs-on : ubuntu-22.04
1918 steps :
2019 - name : Checkout code
2120 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -27,27 +26,52 @@ jobs:
2726 run : python -m pip install --require-hashes --no-deps -r .ci/requirements.txt
2827 - name : Freeze dependencies
2928 run : pip-compile --extra=docs,base,mmlab,anomaly -o requirements.txt pyproject.toml
30- - name : Trivy Scanning (spdx.json)
31- uses : aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # 0.29.0
29+
30+ - name : Run Trivy Scan (vuln)
31+ uses : aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # v0.29.0
3232 with :
33- trivy-config : " .ci/trivy-json.yaml"
34- scan-type : " fs"
33+ scan-type : fs
34+ scan-ref : requirements.txt
35+ scanners : vuln
36+ output : trivy-results-vuln.txt
37+
38+ - name : Run Trivy Scan (dockerfile and secrets)
39+ uses : aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # v0.29.0
40+ with :
41+ scan-type : fs
3542 scan-ref : .
36- - name : Trivy Scanning
43+ scanners : misconfig,secret
44+ output : trivy-results-misconfig.txt
45+ skip-setup-trivy : true
46+
47+ - name : Trivy Scanning (spdx)
3748 uses : aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # 0.29.0
3849 with :
39- trivy-config : " .ci/trivy.yaml"
40- scan-type : " fs"
50+ scan-type : fs
4151 scan-ref : .
52+ format : spdx-json
53+ output : trivy-results-spdx.json
54+ skip-setup-trivy : true
55+
4256 - name : Upload Trivy results artifact
4357 uses : actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
4458 with :
4559 name : trivy-results
46- path : " ${{ github.workspace }}/trivy-results.*"
60+ path : " ${{ github.workspace }}/trivy-results-*"
61+ retention-days : 7
4762 # Use always() to always run this step to publish scan results when there are test failures
4863 if : ${{ always() }}
64+
65+ - name : Upload deps list
66+ uses : actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
67+ if : always()
68+ with :
69+ name : python-deps-list
70+ path : " ${{ github.workspace }}/requirements.txt"
71+ retention-days : 7
72+
4973 Bandit :
50- runs-on : ubuntu-latest
74+ runs-on : ubuntu-22.04
5175 steps :
5276 - name : Checkout repository
5377 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6690 - name : Upload Bandit artifact
6791 uses : actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
6892 with :
69- name : bandit-report
70- path : .tox/bandit-report.txt
93+ name : bandit-results
94+ path : .tox/bandit-results.txt
95+ retention-days : 7
7196 # Use always() to always run this step to publish scan results when there are test failures
7297 if : ${{ always() }}
98+
99+ CodeQL :
100+ name : Analyze (${{ matrix.language }})
101+ runs-on : ubuntu-22.04
102+ permissions :
103+ # required for all workflows
104+ security-events : write
105+
106+ strategy :
107+ fail-fast : false
108+ matrix :
109+ include :
110+ - language : python
111+ build-mode : none
112+ - language : actions # to scan workflows
113+ build-mode : none
114+ steps :
115+ - name : Checkout repository
116+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
117+
118+ # Initializes the CodeQL tools for scanning.
119+ - name : Initialize CodeQL
120+ uses : github/codeql-action/init@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.0
121+ with :
122+ languages : ${{ matrix.language }}
123+ build-mode : ${{ matrix.build-mode }}
124+
125+ - name : Perform CodeQL Analysis
126+ uses : github/codeql-action/analyze@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.0
127+ with :
128+ category : " /language:${{matrix.language}}"
129+
130+ - name : Generate CodeQL Report
131+ uses : rsdmike/github-security-report-action@a149b24539044c92786ec39af8ba38c93496495d # v3.0.4
132+ with :
133+ token : ${{ secrets.GITHUB_TOKEN }}
134+ template : report
135+ outputDir : codeql-${{ matrix.language }}
136+
137+ - name : Rename Report
138+ shell : bash
139+ continue-on-error : true
140+ run : |
141+ cd codeql-${{ matrix.language }}
142+ mv "report.pdf" "codeql-${{ matrix.language }}.pdf"
143+
144+ - name : Upload Report
145+ uses : actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
146+ with :
147+ name : codeql-${{ matrix.language }}-results
148+ path : codeql-${{ matrix.language }}/*.pdf
149+ retention-days : 7
150+
151+ Summarize :
152+ needs : [Trivy, Bandit, CodeQL]
153+ if : always()
154+ runs-on : ubuntu-22.04
155+ steps :
156+ # Create directory first
157+ - name : Create results directory
158+ run : mkdir -p all-results
159+
160+ # Download artifacts with error handling
161+ - name : Download all results
162+ uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
163+ continue-on-error : true # Don't fail if some tools didn't generate results
164+ with :
165+ pattern : " *-results"
166+ merge-multiple : true
167+ path : all-results
168+
169+ # Only upload if there are files
170+ - name : Upload combined results
171+ if : hashFiles('all-results/**/*') != ''
172+ uses : actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
173+ with :
174+ name : security-scan-results
175+ path : all-results
176+ retention-days : 7
0 commit comments