Skip to content
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

testing: executing govulncheck #2393

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e23fdb4
testing
jaxesn Aug 28, 2023
6bc47ab
test
jaxesn Aug 28, 2023
40025b5
test
jaxesn Aug 28, 2023
a1ae943
test
jaxesn Aug 28, 2023
c828f99
consolidate govulncheck execution into a script
danbudris Sep 26, 2023
c6d507d
fetch builder base go version and go vulnerabilities from vex for com…
danbudris Sep 26, 2023
ce12bdc
make sure to bind variable
danbudris Sep 26, 2023
5965934
make sure to bind variable
danbudris Sep 26, 2023
0bfadf2
echo correct variable
danbudris Sep 26, 2023
073579d
output matched cves as an array
danbudris Sep 26, 2023
fc6a3a2
pipe govulncheck results to jq, fix shell expansion
danbudris Sep 26, 2023
72bc956
set trace for x
danbudris Sep 26, 2023
f9d66b6
updates to vulncheck execution
danbudris Sep 26, 2023
1f583e2
remove debug setting from bash for govulncheck
danbudris Sep 27, 2023
a8c70d0
add more clear logging of mitigated vs unmitigated golang CVEs to gov…
danbudris Sep 27, 2023
abef686
fix unset array vars and fix logging for CVEs
danbudris Sep 27, 2023
99d5e53
fixup: add diagnostic bits to script
danbudris Sep 27, 2023
610b61e
fixup: move goproxy setting
danbudris Sep 27, 2023
b6d8477
remove package proxy bypass for govulncheck
danbudris Sep 27, 2023
7f7d9ac
remove proxy unset in govulncheck execution
danbudris Sep 27, 2023
2ed74f4
fix typo
danbudris Sep 27, 2023
b500e8c
fixup: fix wrong jq flag in vuln read
danbudris Sep 27, 2023
bf4d5b7
fixup: cleanup
danbudris Sep 28, 2023
597aca5
add a modcache clean
danbudris Sep 28, 2023
8a36273
try turning off gosumdb
danbudris Sep 28, 2023
edfe7fb
turn off gosumdb
danbudris Sep 28, 2023
d803d63
test disabling gosumdb for cosign force-pushed verison
danbudris Sep 28, 2023
fa027b5
testing goproxy direct
danbudris Sep 28, 2023
1a5c75d
test gonoproxy for sigstore
danbudris Sep 28, 2023
ba08599
fixup: remove diagnostic go env
danbudris Sep 28, 2023
b0fe9a4
unset gosumdb for sigstore due to force pushed tag head in 1.9
danbudris Sep 28, 2023
a3c0ce4
use module level scan
danbudris Sep 28, 2023
801f895
remove module level scan
danbudris Sep 28, 2023
c49cf0f
dont clean up gosum
danbudris Sep 28, 2023
06e2824
add goprivate for cosign sigstore
danbudris Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ TARGET_END_LOG?="------------------- `$(DATE_CMD) +'%Y-%m-%dT%H:%M:%S.$(DATE_NAN
####################################################

#################### TARGETS FOR OVERRIDING ########
BUILD_TARGETS?=validate-checksums attribution $(if $(IMAGE_NAMES),local-images,) $(if $(filter true,$(HAS_HELM_CHART)),helm/build,) $(if $(filter true,$(HAS_S3_ARTIFACTS)),upload-artifacts,) attribution-pr
BUILD_TARGETS?=run-govulncheck validate-checksums attribution $(if $(IMAGE_NAMES),local-images,) $(if $(filter true,$(HAS_HELM_CHART)),helm/build,) $(if $(filter true,$(HAS_S3_ARTIFACTS)),upload-artifacts,) attribution-pr
RELEASE_TARGETS?=validate-checksums $(if $(IMAGE_NAMES),images,) $(if $(filter true,$(HAS_HELM_CHART)),helm/push,) $(if $(filter true,$(HAS_S3_ARTIFACTS)),upload-artifacts,)
####################################################

Expand Down Expand Up @@ -560,6 +560,11 @@ endif
.PHONY: binaries
binaries: $(BINARY_TARGETS)

.PHONY: run-govulncheck
run-govulncheck: $(BINARY_TARGETS)
source $(BUILD_LIB)/govulncheck.sh \
&& rungovulncheck $(GOLANG_VERSION) $(REPO)

$(KUSTOMIZE_TARGET):
@mkdir -p $(OUTPUT_DIR)
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -s -- $(OUTPUT_DIR)
Expand Down
90 changes: 90 additions & 0 deletions build/lib/govulncheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env bash
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
source "${SCRIPT_ROOT}/common.sh"

rungovulncheck() {
local -r goversion=$1
local -r repo=$2

build::common::use_go_version $goversion
echo "Installing govulncheck...."
go install golang.org/x/vuln/cmd/govulncheck@latest

echo "Running govulncheck..."
# Use direct GOPROXY and don't check GOSUMDB hashes for sigstore/cosign, as the 1.9 tag used in several projects was force-pushed and fails the athens proxy pull
govluncheckoutput=$(GONOPROXY="github.com/sigstore/cosign" GONOSUMDB="github.com/sigstore/cosign" GOPRIVATE="github.com/sigstore/cosign" $(go env GOPATH)/bin/govulncheck -C $repo -json ./...)
echo $govluncheckoutput

echo "Analyzing CVEs..."
detectedcves=$(echo $govluncheckoutput | jq '.osv | select( . != null ) | .aliases[0]')
if [ "$detectedcves" == "" ];then
echo "No CVEs detected "
exit 0
fi
echo $detectedcves

builderbasegoversion=$(getbuilderbasegoversion $goversion)
cleanedbuilderbasegoversion="v${builderbasegoversion/-/-eks-}"
cleanedbuilderbasegoversion="eks-distro-golang:${cleanedbuilderbasegoversion//./-}"
echo "builder base golang version: $cleanedbuilderbasegoversion"

fixedcves=$(getgolangvex | jq --arg v "$cleanedbuilderbasegoversion" '[.vulnerabilities[] | select( .product_status.fixed[] | contains($v)) | .cve'])
if [ "$fixedcves" == "" ];then
echo "No CVE fixes present"
fi
echo "CVEs addressed by EKS Go Patches: $fixedcves"

declare -a unmitigatedcves
declare -a mitigatedcves
for cve in $detectedcves
do
echo "Checking if detected CVE $cve is addressed by golang patches..."
cvefixed=$(echo $fixedcves | jq "index($cve) | select( . != null)")
if [ "$cvefixed" == "" ];
then
echo "Unmitigated CVE Detected: $cve is not addressed by a known patch to $goversion"
unmitigatedcves+=($cve)
else
echo "Mitigated CVE Detected: $cve is addressed by a known patch to $goversion"
mitigatedcves+=($cve)
fi
done

if [ -n "${unmitigatedcves-}" ]; then
echo "unmitigated_cves=${unmitigatedcves[@]}"
echo $govluncheckoutput | jq --arg v $unmitigatedcves '.osv | select( . != null ) | select( .aliases[0] == $v)'
fi


if [ -n "${mitigatedcves-}" ]; then
echo "mitigated_cves=${mitigatedcves[@]}"
fi
}

getbuilderbasegoversion() {
local -r goversion=$1
local -r cleanedversion=${goversion//.}
curl -s https://raw.githubusercontent.com/aws/eks-distro-build-tooling/main/builder-base/versions.yaml | yq ".GOLANG_VERSION_$cleanedversion"
}

getgolangvex() {
curl -s https://raw.githubusercontent.com/aws/eks-distro-build-tooling/main/projects/golang/go/VulnerabilityManagement/eks-distro-golang-vex.json
}