Skip to content

Commit 7d00a53

Browse files
authored
add trivy to make and add new vuln GHA (#641)
Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com>
1 parent 4f47155 commit 7d00a53

5 files changed

Lines changed: 119 additions & 1 deletion

File tree

.github/workflows/release.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# NOTE: The goreleaser job uses `environment: release` to require manual
2+
# approval before publishing. This only pauses the run if a maintainer has
3+
# configured an Environment named "release" with Required reviewers under
4+
# Settings > Environments. Until then, the approval gate is a no-op.
15
name: Release Workflow
26

37
on:
@@ -7,8 +11,14 @@ on:
711
- '*'
812

913
jobs:
14+
vulnerability-scan:
15+
name: Vulnerability Scan
16+
uses: ./.github/workflows/vulnerability-scan.yaml
17+
1018
goreleaser:
1119
name: GoReleaser Job
20+
needs: vulnerability-scan
21+
environment: release
1222
runs-on: ubuntu-latest
1323
timeout-minutes: 60
1424

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Vulnerability Scan Workflow
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
- release/*
9+
10+
jobs:
11+
vulnerability-scan:
12+
name: Vulnerability Scan
13+
uses: ./.github/workflows/vulnerability-scan.yaml
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Vulnerability Scan (Reusable)
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
vulnerability-scan:
8+
name: Vulnerability Scan
9+
runs-on: ubuntu-latest
10+
timeout-minutes: 30
11+
12+
steps:
13+
- name: Clean Up Actions Tools Cache
14+
run: rm -rf /opt/hostedtoolcache
15+
16+
- name: Checkout
17+
uses: actions/checkout@v6
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Configure Git
22+
run: |
23+
git config user.name "github-actions[bot]"
24+
git config user.email "github-actions[bot]@users.noreply.github.com"
25+
26+
- name: Set Up Go
27+
uses: actions/setup-go@v6
28+
with:
29+
go-version-file: go.mod
30+
check-latest: true
31+
32+
- name: Install Go Releaser
33+
uses: goreleaser/goreleaser-action@v6
34+
with:
35+
install-only: true
36+
37+
- name: Install Dependencies
38+
run: |
39+
sudo apt-get update
40+
sudo apt-get install -y make
41+
sudo apt-get install -y build-essential
42+
43+
- name: Install govulncheck
44+
run: go install golang.org/x/vuln/cmd/govulncheck@latest
45+
46+
- name: Install Trivy
47+
uses: aquasecurity/setup-trivy@v0.3.1
48+
49+
- name: Run Vulnerability Scans
50+
run: make vulns
51+
52+
- name: Display Vulnerability Reports
53+
if: always()
54+
run: |
55+
echo "::group::govulncheck (vulncheck.out)"
56+
cat vulncheck.out || echo "vulncheck.out not found"
57+
echo "::endgroup::"
58+
echo "::group::trivy fs (trivy.out)"
59+
cat trivy.out || echo "trivy.out not found"
60+
echo "::endgroup::"
61+
62+
- name: Write Vulnerability Reports to Job Summary
63+
if: always()
64+
run: |
65+
{
66+
echo "## Vulnerability Reports"
67+
echo ""
68+
echo "<details><summary>govulncheck (vulncheck.out)</summary>"
69+
echo ""
70+
echo '```'
71+
cat vulncheck.out 2>/dev/null || echo "vulncheck.out not found"
72+
echo '```'
73+
echo ""
74+
echo "</details>"
75+
echo ""
76+
echo "<details><summary>trivy fs (trivy.out)</summary>"
77+
echo ""
78+
echo '```'
79+
cat trivy.out 2>/dev/null || echo "trivy.out not found"
80+
echo '```'
81+
echo ""
82+
echo "</details>"
83+
} >> "$GITHUB_STEP_SUMMARY"
84+
85+
- name: Upload Vulnerability Reports
86+
uses: actions/upload-artifact@v6
87+
if: always()
88+
with:
89+
name: vulnerability-reports
90+
path: |
91+
vulncheck.out
92+
trivy.out

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ cmd/hauler/binaries
1717
testdata/certs/
1818
coverage.out
1919
vulncheck.out
20+
trivy.out
2021
CLAUDE.md
2122
**/CLAUDE.*

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SHELL=/bin/bash
77
GO_FILES=./...
88
GO_COVERPROFILE=coverage.out
99
GO_VULNCHECKS=vulncheck.out
10+
TRIVY_RESULTS=trivy.out
1011

1112
# set build variables
1213
BIN_DIRECTORY=bin
@@ -48,7 +49,8 @@ test:
4849
# check for vulnerabilities
4950
vulns:
5051
govulncheck $(GO_FILES) > $(GO_VULNCHECKS) 2>&1 || true
52+
trivy fs . > $(TRIVY_RESULTS) 2>&1 || true
5153

5254
# cleanup artifacts
5355
clean:
54-
rm -rf $(BIN_DIRECTORY) $(DIST_DIRECTORY) $(GO_COVERPROFILE) $(GO_VULNCHECKS)
56+
rm -rf $(BIN_DIRECTORY) $(DIST_DIRECTORY) $(GO_COVERPROFILE) $(GO_VULNCHECKS) $(TRIVY_RESULTS)

0 commit comments

Comments
 (0)