Skip to content

Commit f9b0056

Browse files
committed
add targets for verifying code and images for vulnerabilities
Signed-off-by: Prajyot-Parab <[email protected]>
1 parent 034149e commit f9b0056

File tree

7 files changed

+1795
-50
lines changed

7 files changed

+1795
-50
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Weekly security scan
2+
3+
on:
4+
schedule:
5+
# Cron for every Monday at 2:00 UTC.
6+
- cron: "0 2 * * 1"
7+
8+
# Remove all permissions from GITHUB_TOKEN except metadata.
9+
permissions: {}
10+
11+
jobs:
12+
scan:
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
branch: [ main, release-0.6, release-0.5 ]
17+
name: Trivy
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Check out code
21+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
22+
with:
23+
ref: ${{ matrix.branch }}
24+
- name: Calculate go version
25+
id: vars
26+
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT
27+
- name: Set up Go
28+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # tag=v4.1.0
29+
with:
30+
go-version: ${{ steps.vars.outputs.go_version }}
31+
- name: Run verify security target
32+
run: make verify-security

Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ ROOT_DIR_RELATIVE := .
1818

1919
include $(ROOT_DIR_RELATIVE)/common.mk
2020

21+
GO_VERSION ?= 1.20.10
22+
2123
# Image URL to use all building/pushing image targets
2224
IMG ?= controller:latest
2325
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
@@ -46,6 +48,8 @@ MOCKGEN := $(TOOLS_BIN_DIR)/mockgen
4648
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
4749
CONVERSION_VERIFIER := $(TOOLS_BIN_DIR)/conversion-verifier
4850
SETUP_ENVTEST := $(TOOLS_BIN_DIR)/setup-envtest
51+
GOVULNCHECK := $(TOOLS_BIN_DIR)/govulncheck
52+
TRIVY := $(TOOLS_BIN_DIR)/trivy
4953

5054
STAGING_REGISTRY ?= gcr.io/k8s-staging-capi-ibmcloud
5155
STAGING_BUCKET ?= artifacts.k8s-staging-capi-ibmcloud.appspot.com
@@ -513,6 +517,27 @@ verify-gen: generate ## Verfiy go generated files are up to date
513517
verify-conversions: $(CONVERSION_VERIFIER) ## Verifies expected API conversion are in place
514518
$(CONVERSION_VERIFIER)
515519

520+
.PHONY: verify-container-images
521+
verify-container-images: $(TRIVY) ## Verify container images
522+
TRACE=$(TRACE) ./hack/verify-container-images.sh
523+
524+
.PHONY: verify-govulncheck
525+
verify-govulncheck: $(GOVULNCHECK) ## Verify code for vulnerabilities
526+
$(GOVULNCHECK) ./... && R1=$$? || R1=$$?; \
527+
$(GOVULNCHECK) -C "$(TOOLS_DIR)" ./... && R2=$$? || R2=$$?; \
528+
if [ "$$R1" -ne "0" ] || [ "$$R2" -ne "0" ]; then \
529+
exit 1; \
530+
fi
531+
532+
.PHONY: verify-security
533+
verify-security: ## Verify code and images for vulnerabilities
534+
$(MAKE) verify-container-images && R1=$$? || R1=$$?; \
535+
$(MAKE) verify-govulncheck && R2=$$? || R2=$$?; \
536+
if [ "$$R1" -ne "0" ] || [ "$$R2" -ne "0" ]; then \
537+
echo "Check for vulnerabilities failed! There are vulnerabilities to be fixed"; \
538+
exit 1; \
539+
fi
540+
516541
## --------------------------------------
517542
## Cleanup / Verification
518543
## --------------------------------------
@@ -544,6 +569,10 @@ clean-temporary: ## Remove all temporary files and folders
544569
clean-release: ## Remove the release folder
545570
rm -rf $(RELEASE_DIR)
546571

572+
.PHONY: clean-release-git
573+
clean-release-git: ## Restores the git files usually modified during a release
574+
git restore ./*manager_image_patch.yaml ./*manager_pull_policy.yaml
575+
547576
.PHONY: clean-generated-conversions
548577
clean-generated-conversions: ## Remove files generated by conversion-gen from the mentioned dirs
549578
(IFS=','; for i in $(SRC_DIRS); do find $$i -type f -name 'zz_generated.conversion*' -exec rm -f {} \;; done)
@@ -562,3 +591,11 @@ clean-kind: ## Cleans up the kind cluster with the name $CAPI_KIND_CLUSTER_NAME
562591
kind-cluster: ## Create a new kind cluster designed for development with Tilt
563592
hack/kind-install.sh
564593

594+
## --------------------------------------
595+
## Helpers
596+
## --------------------------------------
597+
598+
##@ helpers:
599+
600+
go-version: ## Print the go version we use to compile our binaries and images
601+
@echo $(GO_VERSION)

hack/tools/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,11 @@ $(CONVERSION_VERIFIER): $(BIN_DIR) go.mod go.sum ## Build a local copy of conver
121121
SETUP_ENVTEST := $(BIN_DIR)/setup-envtest
122122
$(SETUP_ENVTEST): $(BIN_DIR) go.mod go.sum ## Build a local copy of setup-envtest.
123123
go build -tags=capibmtools -o $@ sigs.k8s.io/controller-runtime/tools/setup-envtest
124+
125+
GOVULNCHECK := $(BIN_DIR)/govulncheck
126+
$(GOVULNCHECK): $(BIN_DIR) go.mod go.sum ## Build a local copy of govulncheck.
127+
go build -tags=capibmtools -o $@ golang.org/x/vuln/cmd/govulncheck
128+
129+
TRIVY := $(BIN_DIR)/trivy
130+
$(TRIVY): $(BIN_DIR) go.mod go.sum ## Build a local copy of trivy.
131+
go build -tags=capibmtools -o $@ github.com/aquasecurity/trivy/cmd/trivy

0 commit comments

Comments
 (0)