Skip to content

Commit c893f14

Browse files
committed
ci: add Grype CVE scanning workflow
Scans all dependencies for known vulnerabilities on push, PR, and weekly schedule. Uploads SARIF to the Security tab and a human-readable table report as an artifact. Fails on high severity with a fix available.
1 parent fc23d58 commit c893f14

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

.github/workflows/cve.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: CVE Scanning
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches: ['main']
9+
pull_request:
10+
branches: ['main']
11+
schedule:
12+
- cron: '0 6 * * 1' # Weekly Monday 6am UTC
13+
14+
jobs:
15+
grype:
16+
name: Grype dependency scan
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
security-events: write
21+
steps:
22+
- name: Harden Runner
23+
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
24+
with:
25+
egress-policy: audit
26+
27+
- name: Checkout
28+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
29+
30+
- name: Scan project
31+
uses: anchore/scan-action@e1165082ffb1fe366ebaf02d8526e7c4989ea9d2 # v7
32+
id: scan
33+
with:
34+
path: .
35+
fail-build: true
36+
severity-cutoff: high
37+
only-fixed: true
38+
config: .grype.yaml
39+
40+
- name: Upload SARIF report
41+
if: ${{ always() }}
42+
uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4
43+
with:
44+
sarif_file: ${{ steps.scan.outputs.sarif }}
45+
46+
- name: Generate table report
47+
if: ${{ always() }}
48+
run: |
49+
export PATH="$(dirname $(find /opt/hostedtoolcache/grype -name grype -type f | head -1)):$PATH"
50+
grype dir:. \
51+
--config .grype.yaml \
52+
--only-fixed \
53+
--output table | tee grype-report.txt || true
54+
55+
- name: Upload scan reports
56+
if: ${{ always() }}
57+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
58+
with:
59+
name: grype-scan
60+
path: |
61+
grype-report.txt
62+
${{ steps.scan.outputs.json }}
63+
retention-days: 30

.grype.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fail-on-severity: high
2+
sort-by: severity
3+
4+
ignore:
5+
- fix-state: 'wont-fix'
6+
- fix-state: 'not-fixed'

0 commit comments

Comments
 (0)