Skip to content

Commit 6cfda81

Browse files
authored
Merge pull request #3959 from wyike/action
Update scan action
2 parents 7919371 + e34e1b8 commit 6cfda81

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

.github/workflows/scan.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: scan-images
22

33
on:
44
schedule:
5-
# every Monday at 12:00PM
5+
# every Monday at 12:00AM
66
- cron: "0 12 * * 1"
77

88
# Remove all permissions from GITHUB_TOKEN except metadata.
@@ -14,12 +14,10 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- 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]
17+
uses: actions/[email protected]
18+
- name: Setup go
19+
uses: actions/[email protected]
2220
with:
23-
image-ref: 'gcr.io/k8s-staging-cluster-api-aws/cluster-api-aws-controller-arm64:dev'
24-
format: 'table'
25-
exit-code: '1'
21+
go-version: 1.19
22+
- name: Run verify container script
23+
run: make verify-container-images

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ verify-gen: generate ## Verify generated files
314314
echo "generated files are out of date, run make generate"; exit 1; \
315315
fi
316316

317+
.PHONY: verify-container-images
318+
verify-container-images: ## Verify container images
319+
TRACE=$(TRACE) ./hack/verify-container-images.sh
320+
317321
.PHONY: apidiff
318322
apidiff: APIDIFF_OLD_COMMIT ?= $(shell git rev-parse origin/main)
319323
apidiff: $(GO_APIDIFF) ## Check for API differences

hack/verify-container-images.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# This refers https://github.com/kubernetes-sigs/cluster-api/blob/main/hack/verify-container-images.sh
17+
1618
set -o errexit
1719
set -o nounset
1820
set -o pipefail
1921

20-
TRIVY_VERSION=0.34.0
22+
if [[ "${TRACE-0}" == "1" ]]; then
23+
set -o xtrace
24+
fi
25+
26+
TRIVY_VERSION=0.35.0
2127

2228
GO_OS="$(go env GOOS)"
2329
if [[ "${GO_OS}" == "linux" ]]; then
@@ -51,5 +57,21 @@ rm ${TOOL_BIN}/trivy.tar.gz
5157
## Builds the container images to be scanned
5258
make REGISTRY=gcr.io/k8s-staging-cluster-api-aws PULL_POLICY=IfNotPresent TAG=dev docker-build
5359

60+
BRed='\033[1;31m'
61+
BGreen='\033[1;32m'
62+
NC='\033[0m' # No
63+
5464
# Scan the images
55-
${TOOL_BIN}/trivy image -q gcr.io/k8s-staging-cluster-api-aws/cluster-api-aws-controller-${GO_ARCH}:dev
65+
echo -e "\n${BGreen}List of dependencies that can bumped to fix the vulnerabilities:${NC}"
66+
${TOOL_BIN}/trivy image -q --exit-code 1 --ignore-unfixed --severity MEDIUM,HIGH,CRITICAL gcr.io/k8s-staging-cluster-api-aws/cluster-api-aws-controller-${GO_ARCH}:dev && R1=$? || R1=$?
67+
echo -e "\n${BGreen}List of dependencies having fixes/no fixes for review only:${NC}"
68+
${TOOL_BIN}/trivy image -q --severity MEDIUM,HIGH,CRITICAL gcr.io/k8s-staging-cluster-api-aws/cluster-api-aws-controller-${GO_ARCH}:dev
69+
70+
if [ "$R1" -ne "0" ]
71+
then
72+
echo -e "\n${BRed}Container images check failed! There are vulnerability to be fixed${NC}"
73+
exit 1
74+
fi
75+
76+
echo -e "\n${BGreen}Container images check passed! No unfixed vulnerability found${NC}"
77+

0 commit comments

Comments
 (0)