Skip to content

Commit 53f5c5c

Browse files
committed
ci: add automated Trivy security scanning via GitHub Actions
- Add a GitHub Action workflow to perform Trivy security scans on the repository - Configure scheduled, push, and pull request triggers for the scan - Upload vulnerability scan results to the GitHub Security tab in SARIF format - Include additional scan step with table output and failure on detected vulnerabilities Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent 170eebb commit 53f5c5c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

.github/workflows/trivy-scan.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Trivy Security Scan
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
pull_request:
7+
branches:
8+
- master
9+
push:
10+
branches:
11+
- master
12+
workflow_dispatch:
13+
14+
jobs:
15+
trivy-scan:
16+
name: Trivy Security Scan
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
security-events: write
21+
actions: read
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Run Trivy vulnerability scanner in repo mode
28+
uses: aquasecurity/trivy-action@0.33.1
29+
with:
30+
scan-type: 'fs'
31+
scan-ref: '.'
32+
scanners: 'vuln,secret,misconfig'
33+
format: 'sarif'
34+
output: 'trivy-results.sarif'
35+
severity: 'CRITICAL,HIGH,MEDIUM'
36+
37+
- name: Upload Trivy results to GitHub Security tab
38+
uses: github/codeql-action/upload-sarif@v3
39+
if: always()
40+
with:
41+
sarif_file: 'trivy-results.sarif'
42+
43+
- name: Run Trivy vulnerability scanner (table format)
44+
uses: aquasecurity/trivy-action@0.33.1
45+
with:
46+
scan-type: 'fs'
47+
scan-ref: '.'
48+
scanners: 'vuln,secret,misconfig'
49+
format: 'table'
50+
severity: 'CRITICAL,HIGH,MEDIUM'
51+
exit-code: '1'

0 commit comments

Comments
 (0)