Skip to content

Commit 1fd18b2

Browse files
authored
chore: add trivy cve scan and fix workflow (#266)
* chore: add trivy cve scan workflow Signed-off-by: Fiona-Waters <fiwaters6@gmail.com> * fix: add security label and report non fixable cves to github Signed-off-by: Fiona-Waters <fiwaters6@gmail.com> * fix: add category and remove unnecessary label Signed-off-by: Fiona-Waters <fiwaters6@gmail.com> --------- Signed-off-by: Fiona-Waters <fiwaters6@gmail.com>
1 parent e4a2be8 commit 1fd18b2

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Trivy Vulnerability Scan
2+
3+
on:
4+
schedule:
5+
- cron: '0 2 * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
trivy-remediate:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
security-events: write
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Install uv
21+
uses: astral-sh/setup-uv@v5
22+
with:
23+
enable-cache: true
24+
25+
- name: Run Trivy Scan (JSON for Auto-Fix - Fixable only)
26+
uses: aquasecurity/trivy-action@0.33.1
27+
with:
28+
scan-type: 'fs'
29+
format: 'json'
30+
output: 'trivy-results.json'
31+
severity: 'HIGH,CRITICAL'
32+
ignore-unfixed: true
33+
34+
- name: Run Trivy Scan (SARIF for Security Tab - Includes UNFIXED)
35+
uses: aquasecurity/trivy-action@0.33.1
36+
with:
37+
scan-type: 'fs'
38+
format: 'sarif'
39+
output: 'trivy-results.sarif'
40+
severity: 'HIGH,CRITICAL'
41+
ignore-unfixed: false
42+
43+
- name: Upload Trivy scan results to GitHub Security tab
44+
uses: github/codeql-action/upload-sarif@v4
45+
with:
46+
sarif_file: 'trivy-results.sarif'
47+
category: kubeflow-sdk-trivy-scanner
48+
- name: Process CVEs and Apply Fixes
49+
id: fixer
50+
run: |
51+
# Parse JSON for packages with CVSS >= 7.0 (NVD or RedHat)
52+
FIX_DATA=$(jq -r '.Results[].Vulnerabilities[]? |
53+
select(
54+
((.CVSS.nvd.V3Score // 0) >= 7.0 or (.CVSS.redhat.V3Score // 0) >= 7.0)
55+
and .FixedVersion != null
56+
) |
57+
"\(.PkgName)==\(.FixedVersion) | \(.PrimaryURL)"' trivy-results.json | sort -u)
58+
59+
if [ -z "$FIX_DATA" ]; then
60+
echo "No high-risk fixable vulnerabilities found tonight."
61+
echo "updates_found=false" >> $GITHUB_OUTPUT
62+
exit 0
63+
fi
64+
65+
echo "updates_found=true" >> $GITHUB_OUTPUT
66+
67+
echo "fix_details<<EOF" >> $GITHUB_OUTPUT
68+
echo "$FIX_DATA" >> $GITHUB_OUTPUT
69+
echo "EOF" >> $GITHUB_OUTPUT
70+
71+
# Apply fixes via uv
72+
echo "$FIX_DATA" | while read -r line; do
73+
TARGET=$(echo "$line" | cut -d'|' -f1 | xargs)
74+
echo "Applying fix: uv lock --upgrade-package $TARGET"
75+
uv lock --upgrade-package "$TARGET"
76+
done
77+
78+
- name: Create Pull Request
79+
if: steps.fixer.outputs.updates_found == 'true'
80+
uses: peter-evans/create-pull-request@v6
81+
with:
82+
token: ${{ secrets.GITHUB_TOKEN }}
83+
commit-message: "fix: nightly automated dependency update (CVSS 7.0+)"
84+
title: "fix: nightly security dependency updates"
85+
body: |
86+
## Security Update
87+
This is an automated PR triggered by the nightly Trivy security scan.
88+
89+
The following dependencies were updated to resolve vulnerabilities with a **CVSS score of 7.0 or higher**:
90+
91+
| Package & Version | Advisory Link |
92+
| :--- | :--- |
93+
${{ steps.fixer.outputs.fix_details }}
94+
95+
**Verification:** Updated via `uv lock --upgrade-package`.
96+
branch: security-nightly-updates-${{ github.run_id }}
97+
delete-branch: true
98+
labels: |
99+
"area/security"

0 commit comments

Comments
 (0)