Skip to content

Commit 4bb58bb

Browse files
authored
Merge pull request #278 from Nordix/security
Add Security scan tools + fix CVEs
2 parents 3e6f456 + 65335d9 commit 4bb58bb

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

Makefile

+55-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
.PHONY: default
3-
default: base-image load-balancer proxy tapa ipam nsp ctraffic frontend
3+
default:
4+
$(MAKE) -s $(IMAGES)
45

56
.PHONY: all
67
all: default
@@ -12,6 +13,8 @@ help: ## Display this help.
1213
# Variables
1314
############################################################################
1415

16+
IMAGES ?= base-image load-balancer proxy tapa ipam nsp ctraffic frontend
17+
1518
# Versions
1619
VERSION ?= latest
1720
VERSION_LOAD_BALANCER ?= $(VERSION)
@@ -42,11 +45,14 @@ GINKGO = $(shell pwd)/bin/ginkgo
4245
MOCKGEN = $(shell pwd)/bin/mockgen
4346
PROTOC_GEN_GO = $(shell pwd)/bin/protoc-gen-go
4447
PROTOC_GEN_GO_GRPC = $(shell pwd)/bin/protoc-gen-go-grpc
48+
NANCY = $(shell pwd)/bin/nancy
4549
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
4650

4751
BUILD_DIR ?= build
4852
BUILD_STEPS ?= build tag push
4953

54+
OUTPUT_DIR ?= _output/
55+
5056
#############################################################################
5157
# Container: Build, tag, push
5258
#############################################################################
@@ -67,39 +73,39 @@ push:
6773

6874
.PHONY: base-image
6975
base-image: ## Build the base-image
70-
VERSION=$(VERSION_BASE_IMAGE) IMAGE=base-image $(MAKE) $(BUILD_STEPS)
76+
VERSION=$(VERSION_BASE_IMAGE) IMAGE=base-image $(MAKE) -s $(BUILD_STEPS)
7177

7278
.PHONY: debug-image
7379
debug-image: ## Build the debug-image
7480
docker build -t $(DEBUG_IMAGE) -f ./build/debug/Dockerfile .
7581

7682
.PHONY: load-balancer
7783
load-balancer: ## Build the load-balancer.
78-
VERSION=$(VERSION_LOAD_BALANCER) IMAGE=load-balancer $(MAKE) $(BUILD_STEPS)
84+
VERSION=$(VERSION_LOAD_BALANCER) IMAGE=load-balancer $(MAKE) -s $(BUILD_STEPS)
7985

8086
.PHONY: proxy
8187
proxy: ## Build the proxy.
82-
VERSION=$(VERSION_PROXY) IMAGE=proxy $(MAKE) $(BUILD_STEPS)
88+
VERSION=$(VERSION_PROXY) IMAGE=proxy $(MAKE) -s $(BUILD_STEPS)
8389

8490
.PHONY: tapa
8591
tapa: ## Build the tapa.
86-
VERSION=$(VERSION_TAPA) IMAGE=tapa $(MAKE) $(BUILD_STEPS)
92+
VERSION=$(VERSION_TAPA) IMAGE=tapa $(MAKE) -s $(BUILD_STEPS)
8793

8894
.PHONY: ipam
8995
ipam: ## Build the ipam.
90-
VERSION=$(VERSION_IPAM) IMAGE=ipam $(MAKE) $(BUILD_STEPS)
96+
VERSION=$(VERSION_IPAM) IMAGE=ipam $(MAKE) -s $(BUILD_STEPS)
9197

9298
.PHONY: nsp
9399
nsp: ## Build the nsp.
94-
VERSION=$(VERSION_NSP) IMAGE=nsp $(MAKE) $(BUILD_STEPS)
100+
VERSION=$(VERSION_NSP) IMAGE=nsp $(MAKE) -s $(BUILD_STEPS)
95101

96102
.PHONY: ctraffic
97103
ctraffic: ## Build the ctraffic.
98-
VERSION=$(VERSION_CTRAFFIC) IMAGE=ctraffic $(MAKE) $(BUILD_STEPS)
104+
VERSION=$(VERSION_CTRAFFIC) IMAGE=ctraffic $(MAKE) -s $(BUILD_STEPS)
99105

100106
.PHONY: frontend
101107
frontend: ## Build the frontend.
102-
VERSION=$(VERSION_FRONTEND) IMAGE=frontend $(MAKE) $(BUILD_STEPS)
108+
VERSION=$(VERSION_FRONTEND) IMAGE=frontend $(MAKE) -s $(BUILD_STEPS)
103109

104110
#############################################################################
105111
##@ Testing & Code check
@@ -133,6 +139,38 @@ cover:
133139
.PHONY: check
134140
check: lint test ## Run the linter and the Unit tests.
135141

142+
#############################################################################
143+
##@ Security Scan
144+
#############################################################################
145+
146+
# https://github.com/anchore/grype
147+
.PHONY: grype
148+
grype: ## Run grype scanner on images.
149+
@BUILD_STEPS=grype-scan $(MAKE) -s $(IMAGES)
150+
151+
.PHONY: grype-scan
152+
grype-scan: output-dir
153+
docker run --rm \
154+
--volume /var/run/docker.sock:/var/run/docker.sock \
155+
--name Grype anchore/grype:v0.47.0 \
156+
$(REGISTRY)/$(IMAGE):$(VERSION) --add-cpes-if-none > $(OUTPUT_DIR)/grype_$(IMAGE)_$(VERSION).txt
157+
158+
# https://github.com/aquasecurity/trivy
159+
.PHONY: trivy
160+
trivy: ## Run trivy scanner on images.
161+
@BUILD_STEPS=trivy-scan $(MAKE) -s $(IMAGES)
162+
163+
.PHONY: trivy-scan
164+
trivy-scan: output-dir
165+
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
166+
-v $(HOME)/Library/Caches:/root/.cache/ aquasec/trivy:0.31.3 image \
167+
$(REGISTRY)/$(IMAGE):$(VERSION) > $(OUTPUT_DIR)/trivy_$(IMAGE)_$(VERSION).txt
168+
169+
# https://github.com/sonatype-nexus-community/nancy
170+
.PHONY: nancy
171+
nancy: nancy-tool ## Run nancy scanner on dependencies.
172+
go list -json -deps ./... | nancy sleuth
173+
136174
#############################################################################
137175
##@ Code generation
138176
#############################################################################
@@ -160,6 +198,10 @@ proto: ipam-proto nsp-proto ambassador-proto ## Compile the proto.
160198
# Tools
161199
#############################################################################
162200

201+
.PHONY: output-dir
202+
output-dir:
203+
mkdir -p $(OUTPUT_DIR)
204+
163205
.PHONY: golangci-lint
164206
golangci-lint:
165207
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/[email protected])
@@ -189,6 +231,10 @@ mockgen:
189231
ginkgo:
190232
$(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/v2/[email protected])
191233

234+
.PHONY: nancy-tool
235+
nancy-tool:
236+
$(call go-get-tool,$(NANCY),github.com/sonatype-nexus-community/[email protected])
237+
192238
# go-get-tool will 'go get' any package $2 and install it to $1.
193239
define go-get-tool
194240
@[ -f $(1) ] || { \

build/base-image/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ RUN apk update && apk add iproute2 tcpdump iputils net-tools \
44
&& setcap 'cap_sys_ptrace,cap_dac_override+ep' /bin/netstat \
55
&& setcap 'cap_net_raw+ep' /bin/ping \
66
&& setcap 'cap_net_raw+ep' /usr/bin/tcpdump
7-
ADD https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.2/grpc_health_probe-linux-amd64 /bin/grpc_health_probe
7+
ADD https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.12/grpc_health_probe-linux-amd64 /bin/grpc_health_probe
88
RUN chmod a+x /bin/grpc_health_probe

0 commit comments

Comments
 (0)