Skip to content

Commit 393380d

Browse files
committed
feat: security scanning pipeline
1 parent 57430f0 commit 393380d

4 files changed

Lines changed: 108 additions & 0 deletions

File tree

.github/workflows/_reusable-build.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
permissions:
2020
contents: read
2121
packages: write
22+
security-events: write
2223

2324
steps:
2425
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
@@ -42,6 +43,21 @@ jobs:
4243
containerfiles: cmd/upcloud-csi-plugin/Containerfile
4344
platforms: linux/amd64
4445

46+
- name: Trivy scan (pre-push)
47+
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
48+
with:
49+
image-ref: ${{ steps.build-image.outputs.image }}:${{ inputs.tags }}
50+
format: 'sarif'
51+
output: 'trivy-results.sarif'
52+
severity: 'CRITICAL,HIGH'
53+
ignore-unfixed: true
54+
exit-code: '1'
55+
56+
- name: Upload Trivy scan results
57+
uses: github/codeql-action/upload-sarif@dd903d2e4f5405488e5ef1422510ee31c8b32357 # v3.36.2
58+
with:
59+
sarif_file: 'trivy-results.sarif'
60+
4561
- name: Push image
4662
id: push-image
4763
uses: redhat-actions/push-to-registry@5ed88d269cf581ea9ef6dd6806d01562096bee9c # v2.8

.github/workflows/test.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ name: UpCloud CSI driver test
33
on:
44
push:
55
branches: ["main"]
6+
paths:
7+
- 'internal/**'
8+
- 'cmd/**'
9+
- 'vendor/**'
10+
- 'go.*'
11+
- '.github/**'
12+
- 'test/**'
13+
- '.github/workflows/test.yaml'
614
pull_request:
715

816
env:
@@ -27,6 +35,7 @@ jobs:
2735
- 'go.*'
2836
- '.github/**'
2937
- 'test/**'
38+
- '.github/workflows/test.yaml'
3039
3140
- if: steps.filter.outputs.go == 'true'
3241
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0

.github/workflows/trivy-scan.yaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: trivy
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
paths:
7+
- "**/*.go"
8+
- go.mod
9+
- go.sum
10+
- cmd/upcloud-csi-plugin/Containerfile
11+
- '.github/workflows/trivy-scan.yaml'
12+
pull_request:
13+
schedule:
14+
- cron: '5 5 * * 2'
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
analyze:
21+
permissions:
22+
contents: read
23+
security-events: write
24+
actions: read
25+
name: Trivy scan
26+
runs-on: ubuntu-24.04
27+
steps:
28+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
29+
with:
30+
fetch-depth: 0
31+
32+
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
33+
id: filter
34+
with:
35+
filters: |
36+
source:
37+
- '**/*.go'
38+
- go.mod
39+
- go.sum
40+
- 'cmd/upcloud-csi-plugin/Containerfile'
41+
- '.github/workflows/trivy-scan.yaml'
42+
43+
- if: steps.filter.outputs.source == 'true' || github.event_name != 'pull_request'
44+
name: Log in to GHCR
45+
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
46+
with:
47+
registry: ghcr.io
48+
username: ${{ github.actor }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
51+
- if: steps.filter.outputs.source == 'true' || github.event_name != 'pull_request'
52+
name: Run Trivy vulnerability scanner (filesystem)
53+
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
54+
with:
55+
scan-type: 'fs'
56+
scan-ref: .
57+
format: 'sarif'
58+
output: 'trivy-fs-results.sarif'
59+
severity: 'CRITICAL,HIGH'
60+
ignore-unfixed: true
61+
62+
- if: steps.filter.outputs.source == 'true' || github.event_name != 'pull_request'
63+
name: Upload filesystem scan results to GitHub Security tab
64+
uses: github/codeql-action/upload-sarif@dd903d2e4f5405488e5ef1422510ee31c8b32357 # v3.36.2
65+
with:
66+
sarif_file: 'trivy-fs-results.sarif'
67+
68+
- if: github.event_name == 'schedule'
69+
name: Run Trivy vulnerability scanner (image)
70+
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
71+
with:
72+
image-ref: 'ghcr.io/${{ github.repository }}:main'
73+
format: 'sarif'
74+
output: 'trivy-image-results.sarif'
75+
severity: 'CRITICAL,HIGH'
76+
ignore-unfixed: true
77+
78+
- if: github.event_name == 'schedule'
79+
name: Upload image scan results to GitHub Security tab
80+
uses: github/codeql-action/upload-sarif@dd903d2e4f5405488e5ef1422510ee31c8b32357 # v3.36.2
81+
with:
82+
sarif_file: 'trivy-image-results.sarif'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ This repository uses the following security and supply-chain measures:
4545
- **Action pinning** — All GitHub Actions pinned by commit SHA with a human-readable version comment; enforced globally.
4646
- **Static analysis**`golangci-lint` with 50+ linters (`gosec`, `staticcheck`, `errcheck`, etc.) runs on every PR.
4747
- **Container image** — Distroless-inspired Alpine runtime, multistage build, pinned base image versions.
48+
- **Container scanning (Trivy)**`aquasecurity/trivy-action` scans the built image for OS and application CVEs before push to GHCR; scheduled weekly rescan catches newly discovered vulnerabilities. Go module dependencies also scanned on every push/PR.
4849
- **Release integrity** — Helm chart validates that `appVersion` matches the git tag and that the container image exists before publishing.
4950
- **Artifact Hub** — Helm chart metadata published to Artifact Hub for discoverability.
5051

0 commit comments

Comments
 (0)