Skip to content

Commit e4bd188

Browse files
committed
Add govulncheck CVE detection to PR checks
1 parent cc7a343 commit e4bd188

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

.github/workflows/govulncheck.yaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# This workflow runs govulncheck on PRs to detect known CVEs in controller source directory and Go dependencies.
2+
3+
name: govulncheck - CVE Detection
4+
5+
on:
6+
pull_request:
7+
paths:
8+
- 'cmd/trainer-controller-manager/**'
9+
- 'pkg/**'
10+
- 'api/**'
11+
- 'go.mod'
12+
- 'go.sum'
13+
14+
jobs:
15+
govulncheck:
16+
name: govulncheck
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version-file: go.mod
27+
28+
- name: Install govulncheck
29+
run: |
30+
go install golang.org/x/vuln/cmd/govulncheck@latest
31+
echo "Go version: $(go version)"
32+
govulncheck -version
33+
34+
- name: Run govulncheck
35+
run: |
36+
govulncheck -format json ./... > govulncheck-output.json
37+
38+
JQ_PARSE='
39+
[.[] | select(.osv)] as $osvs |
40+
[.[] | select(.finding)] as $findings |
41+
($osvs | map({(.osv.id): .osv}) | add) as $osv_map |
42+
[
43+
$findings
44+
| group_by(.finding.osv)[]
45+
| .[0].finding as $f
46+
| $osv_map[$f.osv] as $osv
47+
| {
48+
osv_id: $f.osv,
49+
cve: ([$osv.aliases[]? | select(startswith("CVE-"))] | first // $f.osv),
50+
summary: ($osv.summary // "N/A"),
51+
module: $f.trace[0].module,
52+
version: $f.trace[0].version,
53+
fixed: $f.fixed_version
54+
}
55+
]
56+
| sort_by(.module, .osv_id)
57+
'
58+
59+
VULN_COUNT=$(jq -s "$JQ_PARSE | length" govulncheck-output.json)
60+
61+
if [ "$VULN_COUNT" -eq 0 ]; then
62+
echo "No vulnerabilities found."
63+
echo "## **Summary report of govulncheck:**" >> "$GITHUB_STEP_SUMMARY"
64+
echo "" >> "$GITHUB_STEP_SUMMARY"
65+
echo "No vulnerabilities found." >> "$GITHUB_STEP_SUMMARY"
66+
else
67+
jq -s "$JQ_PARSE"' |
68+
"## **Summary report of govulncheck:**\n\n| CVE | Vuln ID | Description | Module | Current | Fixed |\n|-----|---------|-------------|--------|---------|-------|\n" +
69+
(map("| \(.cve) | [\(.osv_id)](https://pkg.go.dev/vuln/\(.osv_id)) | \(.summary[:80]) | `\(.module)` | \(.version) | \(.fixed) |") | join("\n")) +
70+
"\n\n**Total: \(length) vulnerabilities found**"
71+
' -r govulncheck-output.json >> "$GITHUB_STEP_SUMMARY"
72+
73+
echo ""
74+
echo "=== govulncheck Results ==="
75+
echo ""
76+
jq -s "$JQ_PARSE"' |
77+
.[] | "\(.cve) \(.osv_id) \(.module)@\(.version) -> \(.fixed)\n \(.summary)"
78+
' -r govulncheck-output.json
79+
echo ""
80+
echo "Total: $VULN_COUNT vulnerabilities found"
81+
exit 1
82+
fi

0 commit comments

Comments
 (0)