Skip to content

Commit

Permalink
cherry picking the crictl version bump and trivy-db logic to avoid th…
Browse files Browse the repository at this point in the history
…rottling (#5233)

Co-authored-by: Cameron Meissner <[email protected]>
Co-authored-by: Cameron Meissner <[email protected]>
  • Loading branch information
3 people authored Nov 12, 2024
1 parent 68fa912 commit 2e71a96
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,3 @@ Reference: https://docs.opensource.microsoft.com/tools/cg/cgmanifest.html
Package:

- Calico Windows: https://docs.projectcalico.org/release-notes/

2 changes: 1 addition & 1 deletion parts/linux/cloud-init/artifacts/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@
"versionsV2": [
{
"renovateTag": "<DO_NOT_UPDATE>",
"latestVersion": "1.29.0"
"latestVersion": "1.31.1"
}
],
"downloadURL": "https://acs-mirror.azureedge.net/cri-tools/v${version}/binaries/crictl-v${version}-linux-${CPU_ARCH}.tar.gz"
Expand Down
27 changes: 22 additions & 5 deletions vhdbuilder/packer/trivy-scan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ set -euxo pipefail
TRIVY_REPORT_DIRNAME=/opt/azure/containers
TRIVY_REPORT_ROOTFS_JSON_PATH=${TRIVY_REPORT_DIRNAME}/trivy-report-rootfs.json
TRIVY_REPORT_IMAGE_TABLE_PATH=${TRIVY_REPORT_DIRNAME}/trivy-report-images-table.txt
TRIVY_DB_REPOSITORIES="mcr.microsoft.com/mirror/ghcr/aquasecurity/trivy-db:2,ghcr.io/aquasecurity/trivy-db:2,public.ecr.aws/aquasecurity/trivy-db"

TRIVY_VERSION="0.53.0"
TRIVY_VERSION="0.57.0"
TRIVY_ARCH=""

MODULE_NAME="vuln-to-kusto-vhd"
Expand Down Expand Up @@ -38,6 +39,20 @@ export SYSTEM_COLLECTIONURI=${25}
export SYSTEM_TEAMPROJECT=${26}
export BUILD_BUILDID=${27}

retrycmd_if_failure() {
retries=$1; wait_sleep=$2; timeout=$3; shift && shift && shift
for i in $(seq 1 $retries); do
timeout $timeout "${@}" && break || \
if [ $i -eq $retries ]; then
echo Executed \"$@\" $i times;
return 1
else
sleep $wait_sleep
fi
done
echo Executed \"$@\" $i times;
}

install_azure_cli() {
OS_SKU=${1}
OS_VERSION=${2}
Expand Down Expand Up @@ -114,7 +129,9 @@ chmod a+x ${MODULE_NAME}
# shellcheck disable=SC2155
export PATH="$(pwd):$PATH"

./trivy --scanners vuln rootfs -f json --skip-dirs /var/lib/containerd --ignore-unfixed --severity ${SEVERITY} -o "${TRIVY_REPORT_ROOTFS_JSON_PATH}" /
# we do a delayed retry here since it's possible we'll get rate-limited by ghcr.io, which hosts the vulnerability DB
retrycmd_if_failure 10 30 600 ./trivy --scanners vuln rootfs -f json --db-repository ${TRIVY_DB_REPOSITORIES} --skip-dirs /var/lib/containerd --ignore-unfixed --severity ${SEVERITY} -o "${TRIVY_REPORT_ROOTFS_JSON_PATH}" /

if [[ -f ${TRIVY_REPORT_ROOTFS_JSON_PATH} ]]; then
./vuln-to-kusto-vhd scan-report \
--vhd-buildrunnumber=${BUILD_RUN_NUMBER} \
Expand All @@ -136,12 +153,12 @@ Note: images without CVEs are also listed" >> "${TRIVY_REPORT_IMAGE_TABLE_PATH}"

for CONTAINER_IMAGE in $IMAGE_LIST; do
# append to table
./trivy --scanners vuln image --ignore-unfixed --severity ${SEVERITY} --skip-db-update -f table ${CONTAINER_IMAGE} >> ${TRIVY_REPORT_IMAGE_TABLE_PATH} || true
./trivy --scanners vuln image --ignore-unfixed --severity ${SEVERITY} --db-repository ${TRIVY_DB_REPOSITORIES} --skip-db-update -f table ${CONTAINER_IMAGE} >> ${TRIVY_REPORT_IMAGE_TABLE_PATH} || true

# export to Kusto, one by one
BASE_CONTAINER_IMAGE=$(basename ${CONTAINER_IMAGE})
TRIVY_REPORT_IMAGE_JSON_PATH=${TRIVY_REPORT_DIRNAME}/trivy-report-image-${BASE_CONTAINER_IMAGE}.json
./trivy --scanners vuln image -f json --ignore-unfixed --severity ${SEVERITY} --skip-db-update -o ${TRIVY_REPORT_IMAGE_JSON_PATH} $CONTAINER_IMAGE || true
./trivy --scanners vuln image -f json --ignore-unfixed --severity ${SEVERITY} --db-repository ${TRIVY_DB_REPOSITORIES} --skip-db-update -o ${TRIVY_REPORT_IMAGE_JSON_PATH} $CONTAINER_IMAGE || true

if [[ -f ${TRIVY_REPORT_IMAGE_JSON_PATH} ]]; then
./vuln-to-kusto-vhd scan-report \
Expand All @@ -160,7 +177,7 @@ for CONTAINER_IMAGE in $IMAGE_LIST; do
fi
done

rm ./trivy
rm ./trivy

chmod a+r "${TRIVY_REPORT_ROOTFS_JSON_PATH}"
chmod a+r "${TRIVY_REPORT_IMAGE_TABLE_PATH}"
Expand Down

0 comments on commit 2e71a96

Please sign in to comment.