Skip to content

Commit 7c90472

Browse files
add trivy
1 parent 5305019 commit 7c90472

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Vulnerability Scan & Triage
2+
3+
on:
4+
# schedule:
5+
# # Run nightly at 2am UTC
6+
# - cron: '0 2 * * *'
7+
workflow_dispatch:
8+
inputs:
9+
image_tag:
10+
description: 'Image tag to scan (default: latest)'
11+
required: false
12+
default: 'latest'
13+
dry_run:
14+
description: 'Dry run (analyze but do not create Linear issues)'
15+
required: false
16+
type: boolean
17+
default: false
18+
19+
env:
20+
IMAGE: ghcr.io/sourcebot-dev/sourcebot
21+
22+
permissions:
23+
contents: read
24+
packages: read
25+
26+
jobs:
27+
scan:
28+
name: Trivy Scan
29+
runs-on: ubuntu-latest
30+
outputs:
31+
has_vulnerabilities: ${{ steps.check.outputs.has_vulnerabilities }}
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v4
35+
36+
- name: Log in to GHCR
37+
uses: docker/login-action@v3
38+
with:
39+
registry: ghcr.io
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Run Trivy vulnerability scan
44+
uses: aquasecurity/trivy-action@master
45+
with:
46+
image-ref: "${{ env.IMAGE }}:${{ inputs.image_tag || 'latest' }}"
47+
format: "json"
48+
output: "trivy-results.json"
49+
severity: "CRITICAL,HIGH,MEDIUM"
50+
# Only report vulns that have a fix available
51+
ignore-unfixed: true
52+
trivy-config: trivy.yaml
53+
54+
- name: Check for vulnerabilities
55+
id: check
56+
run: |
57+
VULN_COUNT=$(jq '[.Results[]?.Vulnerabilities // [] | .[] | select(.FixedVersion != null and .FixedVersion != "")] | length' trivy-results.json)
58+
echo "Found $VULN_COUNT fixable vulnerabilities"
59+
if [ "$VULN_COUNT" -gt 0 ]; then
60+
echo "has_vulnerabilities=true" >> "$GITHUB_OUTPUT"
61+
else
62+
echo "has_vulnerabilities=false" >> "$GITHUB_OUTPUT"
63+
fi
64+
65+
- name: Upload scan results
66+
if: steps.check.outputs.has_vulnerabilities == 'true'
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: trivy-results
70+
path: trivy-results.json
71+
retention-days: 30

trivy.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Docs: https://aquasecurity.github.io/trivy/latest/docs/references/configuration/config-file/
2+
3+
scan:
4+
scanners:
5+
- vuln
6+
7+
pkg-types:
8+
- os
9+
- library

0 commit comments

Comments
 (0)