Skip to content

Commit 5c7abde

Browse files
authored
ci: add trivy security scanning workflow (#571)
This commit provides a basic GHA to enable Trivy FS scanning on the notebooks-v1 and notebooks-v2 branches. In order to support `workflow_dispatch` and `cron` triggers - this GHA needs to live on the default branch (`main`). But while the workflow lives on the `main` branch - it will only scan `notebooks-v1` and/or `notebooks-v2` branches depending on how its invoked. It scans from the root of repo and reports on `CRITICAL`, `HIGH` or `MEDIUM` vulnerabilities that have fixes available. It will also scan for secrets. It will always exit with status code 0 and upload its results to the GitHub Security tab. Custom ruleId metadata is injected into the report to help differentiate whether reported findings originated in `notebooks-v1` or `notebooks-v2`. - custom `ruleId` also ensures flagging a false positive in `notebooks-v1` will not auto-apply to `notebooks-v2` branch if similar vulnerabilities exist and vice-versa. The workflow is configured to fire every day at 6:00 AM UTC and also supports manually invoking it. I personally did not see any reason to run this on pull_requests and/or pushes to `notebooks-v1` or `notebooks-v2` branches as vulnerabilities could be disclosed / fixes made available **at any time**. Therefore, having it set on a daily schedule as well as supported ad-hoc runs seems a reasonable way to manage. Addtionally, the build has an `if:` conditional to prevent the `schedule` runs from running on forks in an attempt to be a good/responsible github citizen. Signed-off-by: Andy Stoneberg <astonebe@redhat.com>
1 parent 23d26ca commit 5c7abde

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Trivy FS scanning
2+
3+
on:
4+
schedule:
5+
- cron: '0 6 * * *' # Every day at 6:00 AM UTC
6+
workflow_dispatch:
7+
inputs:
8+
branch:
9+
description: 'Branch to scan'
10+
required: true
11+
default: 'notebooks-v2'
12+
type: choice
13+
options:
14+
- notebooks-v1
15+
- notebooks-v2
16+
17+
permissions:
18+
actions: read
19+
security-events: write
20+
21+
jobs:
22+
build:
23+
if: github.event_name == 'workflow_dispatch' || ( github.event_name == 'schedule' && github.repository == 'kubeflow/notebooks' )
24+
name: Trivy FS scan
25+
runs-on: ubuntu-latest
26+
strategy:
27+
matrix:
28+
branch: ${{ github.event_name == 'workflow_dispatch' && fromJSON(format('["{0}"]', github.event.inputs.branch)) || fromJSON('["notebooks-v1", "notebooks-v2"]') }}
29+
steps:
30+
- name: Checkout code
31+
id: checkout
32+
uses: actions/checkout@v4
33+
with:
34+
ref: refs/heads/${{ matrix.branch }} # using explicit refs syntax due to requirements of upload-sarif action
35+
36+
- name: Run Trivy vulnerability scanner in fs mode
37+
uses: aquasecurity/trivy-action@0.33.1
38+
with:
39+
scan-type: 'fs'
40+
format: 'sarif'
41+
severity: 'CRITICAL,HIGH,MEDIUM'
42+
limit-severities-for-sarif: true
43+
ignore-unfixed: true
44+
output: 'trivy-fs-scan-results-${{ matrix.branch }}.sarif'
45+
46+
- name: Add branch metadata to SARIF
47+
run: |
48+
# Modify ruleId to include branch information for identification
49+
jq '.runs[0].results[] |= (.ruleId = "trivy/${{ matrix.branch }}/" + .ruleId)' \
50+
trivy-fs-scan-results-${{ matrix.branch }}.sarif > trivy-fs-scan-results-${{ matrix.branch }}-processed.sarif
51+
mv trivy-fs-scan-results-${{ matrix.branch }}-processed.sarif trivy-fs-scan-results-${{ matrix.branch }}.sarif
52+
53+
- name: Upload Trivy scan results to GitHub Security tab
54+
uses: github/codeql-action/upload-sarif@v3
55+
with:
56+
sarif_file: 'trivy-fs-scan-results-${{ matrix.branch }}.sarif'
57+
ref: ${{ steps.checkout.outputs.ref }}
58+
sha: ${{ steps.checkout.outputs.commit }}

0 commit comments

Comments
 (0)