Skip to content

Commit 3dc022a

Browse files
committed
Verify container images
1.The script allows to scan the controller manager image locally 2.Also add github actions for trivy scanning
1 parent 69ab4cc commit 3dc022a

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

.github/workflows/scan.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: scan-images
2+
3+
on:
4+
schedule:
5+
# every Monday at 12:00PM
6+
- cron: "0 12 * * 1"
7+
8+
# Remove all permissions from GITHUB_TOKEN except metadata.
9+
permissions: {}
10+
11+
jobs:
12+
scan:
13+
name: Trivy
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check out code
17+
uses: actions/[email protected]
18+
- name: Make images
19+
run: make REGISTRY=gcr.io/k8s-staging-cluster-api-aws PULL_POLICY=IfNotPresent TAG=dev ARCH=amd64 docker-build
20+
- name: Run Trivy vulnerability scanner on CAPA image
21+
uses: aquasecurity/[email protected]
22+
with:
23+
image-ref: 'gcr.io/k8s-staging-cluster-api-aws/cluster-api-aws-controller-arm64:dev'
24+
format: 'table'
25+
exit-code: '1'

hack/verify-container-images.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2022 The Kubernetes Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
20+
TRIVY_VERSION=0.34.0
21+
22+
GO_OS="$(go env GOOS)"
23+
if [[ "${GO_OS}" == "linux" ]]; then
24+
TRIVY_OS="Linux"
25+
elif [[ "${GO_OS}" == "darwin"* ]]; then
26+
TRIVY_OS="macOS"
27+
fi
28+
29+
GO_ARCH="$(go env GOARCH)"
30+
if [[ "${GO_ARCH}" == "amd" ]]; then
31+
TRIVY_ARCH="32bit"
32+
elif [[ "${GO_ARCH}" == "amd64"* ]]; then
33+
TRIVY_ARCH="64bit"
34+
elif [[ "${GO_ARCH}" == "arm" ]]; then
35+
TRIVY_ARCH="ARM"
36+
elif [[ "${GO_ARCH}" == "arm64" ]]; then
37+
TRIVY_ARCH="ARM64"
38+
fi
39+
40+
TOOL_BIN=hack/tools/bin
41+
mkdir -p ${TOOL_BIN}
42+
43+
# Downloads trivy scanner
44+
curl -L -o ${TOOL_BIN}/trivy.tar.gz \
45+
https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_${TRIVY_OS}-${TRIVY_ARCH}.tar.gz \
46+
47+
tar xfO ${TOOL_BIN}/trivy.tar.gz trivy > ${TOOL_BIN}/trivy
48+
chmod +x ${TOOL_BIN}/trivy
49+
rm ${TOOL_BIN}/trivy.tar.gz
50+
51+
## Builds the container images to be scanned
52+
make REGISTRY=gcr.io/k8s-staging-cluster-api-aws PULL_POLICY=IfNotPresent TAG=dev docker-build
53+
54+
# Scan the images
55+
${TOOL_BIN}/trivy image -q gcr.io/k8s-staging-cluster-api-aws/cluster-api-aws-controller-${GO_ARCH}:dev

0 commit comments

Comments
 (0)