-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add targets for verifying code and images for vulnerabilities #1422
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Weekly security scan | ||
|
||
on: | ||
schedule: | ||
# Cron for every Monday at 2:00 UTC. | ||
- cron: "0 2 * * 1" | ||
|
||
# Remove all permissions from GITHUB_TOKEN except metadata. | ||
permissions: {} | ||
|
||
jobs: | ||
scan: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
branch: [ main, release-0.6, release-0.5 ] | ||
name: Trivy | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1 | ||
with: | ||
ref: ${{ matrix.branch }} | ||
- name: Calculate go version | ||
id: vars | ||
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT | ||
- name: Set up Go | ||
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # tag=v4.1.0 | ||
with: | ||
go-version: ${{ steps.vars.outputs.go_version }} | ||
- name: Run verify security target | ||
run: make verify-security |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ ROOT_DIR_RELATIVE := . | |
|
||
include $(ROOT_DIR_RELATIVE)/common.mk | ||
|
||
GO_VERSION ?= 1.20.10 | ||
|
||
# Image URL to use all building/pushing image targets | ||
IMG ?= controller:latest | ||
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) | ||
|
@@ -46,6 +48,8 @@ MOCKGEN := $(TOOLS_BIN_DIR)/mockgen | |
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen | ||
CONVERSION_VERIFIER := $(TOOLS_BIN_DIR)/conversion-verifier | ||
SETUP_ENVTEST := $(TOOLS_BIN_DIR)/setup-envtest | ||
GOVULNCHECK := $(TOOLS_BIN_DIR)/govulncheck | ||
TRIVY := $(TOOLS_BIN_DIR)/trivy | ||
|
||
STAGING_REGISTRY ?= gcr.io/k8s-staging-capi-ibmcloud | ||
STAGING_BUCKET ?= artifacts.k8s-staging-capi-ibmcloud.appspot.com | ||
|
@@ -513,6 +517,27 @@ verify-gen: generate ## Verfiy go generated files are up to date | |
verify-conversions: $(CONVERSION_VERIFIER) ## Verifies expected API conversion are in place | ||
$(CONVERSION_VERIFIER) | ||
|
||
.PHONY: verify-container-images | ||
verify-container-images: $(TRIVY) ## Verify container images | ||
TRACE=$(TRACE) ./hack/verify-container-images.sh | ||
|
||
.PHONY: verify-govulncheck | ||
verify-govulncheck: $(GOVULNCHECK) ## Verify code for vulnerabilities | ||
$(GOVULNCHECK) ./... && R1=$$? || R1=$$?; \ | ||
$(GOVULNCHECK) -C "$(TOOLS_DIR)" ./... && R2=$$? || R2=$$?; \ | ||
if [ "$$R1" -ne "0" ] || [ "$$R2" -ne "0" ]; then \ | ||
exit 1; \ | ||
fi | ||
|
||
.PHONY: verify-security | ||
verify-security: ## Verify code and images for vulnerabilities | ||
Prajyot-Parab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$(MAKE) verify-container-images && R1=$$? || R1=$$?; \ | ||
$(MAKE) verify-govulncheck && R2=$$? || R2=$$?; \ | ||
if [ "$$R1" -ne "0" ] || [ "$$R2" -ne "0" ]; then \ | ||
echo "Check for vulnerabilities failed! There are vulnerabilities to be fixed"; \ | ||
exit 1; \ | ||
fi | ||
|
||
## -------------------------------------- | ||
## Cleanup / Verification | ||
## -------------------------------------- | ||
|
@@ -544,6 +569,10 @@ clean-temporary: ## Remove all temporary files and folders | |
clean-release: ## Remove the release folder | ||
rm -rf $(RELEASE_DIR) | ||
|
||
.PHONY: clean-release-git | ||
clean-release-git: ## Restores the git files usually modified during a release | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where are we calling this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 33 of file - verify-container-images.sh |
||
git restore ./*manager_image_patch.yaml ./*manager_pull_policy.yaml | ||
|
||
.PHONY: clean-generated-conversions | ||
clean-generated-conversions: ## Remove files generated by conversion-gen from the mentioned dirs | ||
(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 | |
kind-cluster: ## Create a new kind cluster designed for development with Tilt | ||
hack/kind-install.sh | ||
|
||
## -------------------------------------- | ||
## Helpers | ||
## -------------------------------------- | ||
|
||
##@ helpers: | ||
|
||
go-version: ## Print the go version we use to compile our binaries and images | ||
@echo $(GO_VERSION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be a follow up PR required for maintaining the golang version in one place and use it everywhere including dockerfiles, makefile and GitHub action