Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.

Commit 19b87a1

Browse files
authored
chore: add vulnerability scanning with Trivy (#39)
1 parent cbe478f commit 19b87a1

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

.github/workflows/build.yaml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ on:
99
branches:
1010
- main
1111

12+
schedule:
13+
# Run daily at 10:15 am UTC (3:15am PT/5:15am CT)
14+
- cron: "15 10 * * *"
15+
1216
workflow_dispatch:
1317

1418
permissions:
@@ -25,7 +29,7 @@ permissions:
2529

2630
jobs:
2731
build:
28-
name: Build
32+
name: build
2933
runs-on: ubuntu-20.04
3034
steps:
3135
- name: Cancel Previous Runs
@@ -57,3 +61,26 @@ jobs:
5761
distribution: goreleaser
5862
version: latest
5963
args: release --rm-dist --snapshot --skip-publish
64+
65+
scan-source:
66+
name: scan/source
67+
runs-on: ubuntu-20.04
68+
steps:
69+
- name: Cancel previous runs
70+
if: github.event_name == 'pull_request'
71+
uses: styfle/cancel-workflow-action@0.9.1
72+
73+
- name: Checkout
74+
uses: actions/checkout@v2
75+
76+
- name: Install Go
77+
uses: actions/setup-go@v2
78+
with:
79+
go-version: '^1.16.7'
80+
81+
- name: Install dependencies
82+
run: ./scripts/install_deps.sh
83+
84+
- name: Scan with AquaSec Trivy
85+
run: ./scripts/scan.sh
86+
continue-on-error: true

scripts/install_deps.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@ GORELEASER_VERSION="0.178.0"
5151
run_trace false curl "${curl_flags[@]}" "https://github.com/goreleaser/goreleaser/releases/download/v${GORELEASER_VERSION}/goreleaser_Linux_x86_64.tar.gz" \| \
5252
tar --extract --gzip --directory="$TMPBIN" --file=- "goreleaser"
5353

54+
# trivy to scan container images
55+
TRIVY_VERSION="0.19.2"
56+
run_trace false curl "${curl_flags[@]}" "https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" \| \
57+
tar --extract --gzip --directory="$TMPBIN" --file=- "trivy"
58+
5459
run_trace false sudo install --mode=0755 --target-directory="$BINDIR" "$TMPBIN/*"
5560

5661
run_trace false command -v \
5762
golangci-lint \
5863
goreleaser \
59-
gotestsum
64+
gotestsum \
65+
trivy
6066

6167
run_trace false sudo rm --verbose --recursive --force "$TMPDIR"

scripts/scan.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Check dependencies and configuration for security issues
4+
5+
set -euo pipefail
6+
PROJECT_ROOT=$(git rev-parse --show-toplevel)
7+
cd "$PROJECT_ROOT"
8+
source "./scripts/lib.sh"
9+
10+
run_trace false trivy --version
11+
12+
trivy_flags=(
13+
"--vuln-type=os,library"
14+
"--severity=MEDIUM,HIGH,CRITICAL"
15+
"--exit-code=1"
16+
"--security-checks=vuln,config"
17+
)
18+
19+
if [ -n "${CI:-}" ]; then
20+
trivy_flags+=(
21+
"--no-progress"
22+
)
23+
fi
24+
25+
run_trace false trivy filesystem "${trivy_flags[@]}" "$PROJECT_ROOT"

0 commit comments

Comments
 (0)