Skip to content

Commit 04a08f3

Browse files
committed
Add verify-govulncheck and verify-vulnerabilities targets and integrate to scan action
1 parent 88f495b commit 04a08f3

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

.github/workflows/weekly-image-scan.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ jobs:
2828
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # tag=v4.0.1
2929
with:
3030
go-version: ${{ steps.vars.outputs.go_version }}
31-
- name: Run verify container script
32-
run: make verify-container-images
31+
- name: Run verify vulnerabilities script
32+
run: make verify-vulnerabilities

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ GOLANGCI_LINT_VER := $(shell cat .github/workflows/pr-golangci-lint.yaml | grep
164164
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))
165165
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
166166

167+
GOVULNCHECK_BIN := govulncheck
168+
GOVULNCHECK_VER := v1.0.0
169+
GOVULNCHECK := $(abspath $(TOOLS_BIN_DIR)/$(GOVULNCHECK_BIN)-$(GOVULNCHECK_VER))
170+
GOVULNCHECK_PKG := golang.org/x/vuln/cmd/govulncheck
171+
167172
CONVERSION_VERIFIER_BIN := conversion-verifier
168173
CONVERSION_VERIFIER := $(abspath $(TOOLS_BIN_DIR)/$(CONVERSION_VERIFIER_BIN))
169174

@@ -653,6 +658,14 @@ verify-tiltfile: ## Verify Tiltfile format
653658
verify-container-images: ## Verify container images
654659
TRACE=$(TRACE) ./hack/verify-container-images.sh
655660

661+
.PHONY: verify-govulncheck
662+
verify-govulncheck: $(GOVULNCHECK) ## Verify code for vulnerabilities
663+
$(GOVULNCHECK) ./...
664+
665+
.PHONY: verify-vulnerabilities
666+
verify-vulnerabilities: ## Verify code and images for vulnerabilities
667+
TRACE=$(TRACE) ./hack/verify-vulnerabilities.sh
668+
656669
## --------------------------------------
657670
## Binaries
658671
## --------------------------------------
@@ -1249,6 +1262,9 @@ $(GINKGO_BIN): $(GINKGO) ## Build a local copy of ginkgo.
12491262
.PHONY: $(GOLANGCI_LINT_BIN)
12501263
$(GOLANGCI_LINT_BIN): $(GOLANGCI_LINT) ## Build a local copy of golangci-lint.
12511264

1265+
.PHONY: $(GOVULNCHECK_BIN)
1266+
$(GOVULNCHECK_BIN): $(GOVULNCHECK) ## Build a local copy of govulncheck.
1267+
12521268
$(CONTROLLER_GEN): # Build controller-gen from tools folder.
12531269
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(CONTROLLER_GEN_PKG) $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER)
12541270

@@ -1300,6 +1316,9 @@ $(GINKGO): # Build ginkgo from tools folder.
13001316
$(GOLANGCI_LINT): # Build golangci-lint from tools folder.
13011317
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOLANGCI_LINT_PKG) $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
13021318

1319+
$(GOVULNCHECK): # Build govulncheck.
1320+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOVULNCHECK_PKG) $(GOVULNCHECK_BIN) $(GOVULNCHECK_VER)
1321+
13031322
## --------------------------------------
13041323
## Helpers
13051324
## --------------------------------------

hack/verify-vulnerabilities.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# Copyright 2023 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
if [[ "${TRACE-0}" == "1" ]]; then
22+
set -o xtrace
23+
fi
24+
25+
# Scan the images
26+
make verify-container-images && R1=$? || R1=$?
27+
make verify-govulncheck && R2=$? || R2=$?
28+
29+
echo ""
30+
BRed='\033[1;31m'
31+
BGreen='\033[1;32m'
32+
NC='\033[0m' # No
33+
34+
if [ "$R1" -ne "0" ] || [ "$R2" -ne "0" ]
35+
then
36+
echo -e "${BRed}Check for vulnerabilities failed! There are vulnerability to be fixed${NC}"
37+
exit 1
38+
fi
39+
40+
echo -e "${BGreen}Check for vulnerabilities passed! No vulnerability found${NC}"

0 commit comments

Comments
 (0)