fix(ci): load checksum-verified Trivy from runner tool cache
This commit is contained in:
1 parent
cfe11a0a04
commit
4a7b230f35
2 files changed
+69
-13
No files matched your search
+31
-13
@@ -1,8 +1,8 @@
|
||||
#!/bin/sh
|
||||
# Scan the built Crank server images with a pinned Trivy and fail closed.
|
||||
#
|
||||
# The wrapper downloads and checksum-verifies one fixed Trivy release, downloads
|
||||
# one fresh vulnerability database, then scans every requested image by its
|
||||
# The wrapper loads or downloads and checksum-verifies one fixed Trivy release,
|
||||
# downloads one fresh vulnerability database, then scans every requested image by its
|
||||
# immutable Docker id with a fully pinned policy. It never trusts a local
|
||||
# trivy.yaml, .trivyignore, VEX file or skip list: --config and --ignorefile
|
||||
# point at /dev/null and every inherited TRIVY_* variable is removed before
|
||||
@@ -14,6 +14,7 @@
|
||||
#
|
||||
# db/metadata.json copy of the actual downloaded Trivy DB metadata
|
||||
# db-download.log database download log
|
||||
# scanner-cache-source.log archive source provenance
|
||||
# scanner.json pinned scanner version and scan policy receipt
|
||||
# <NN-slug>.json raw Trivy JSON report per image
|
||||
# <NN-slug>.scan.log Trivy scan log per image
|
||||
@@ -47,6 +48,8 @@ expected_sha256="8b4376d5d6befe5c24d503f10ff136d9e0c49f9127a4279fd110b727929a5aa
|
||||
download_url="https://github.com/aquasecurity/trivy/releases/download/v${trivy_version}/${archive}"
|
||||
# Fixed GitHub asset ID for the Trivy 0.70.0 Linux 64-bit release archive.
|
||||
asset_api_url="https://api.github.com/repos/aquasecurity/trivy/releases/assets/398381981"
|
||||
tool_cache_root="${RUNNER_TOOL_CACHE:-/opt/hostedtoolcache}"
|
||||
cached_archive="$tool_cache_root/trivy/$trivy_version/$archive"
|
||||
db_repository_primary="ghcr.io/aquasecurity/trivy-db:2"
|
||||
db_repository_fallback="mirror.gcr.io/aquasec/trivy-db:2"
|
||||
|
||||
@@ -104,19 +107,34 @@ PY
|
||||
exit 2
|
||||
}
|
||||
|
||||
# Download and checksum-verify the pinned scanner exactly once.
|
||||
if ! curl --fail --silent --show-error --location --max-time 300 \
|
||||
"$download_url" --output "$temp_dir/$archive" \
|
||||
>"$output_dir/scanner-download.log" 2>&1; then
|
||||
rm -f "$temp_dir/$archive"
|
||||
# Load the exact-version archive from the runner cache when preinstalled;
|
||||
# otherwise use the bounded network routes. The shared cache is read-only here.
|
||||
cache_source_log="$output_dir/scanner-cache-source.log"
|
||||
: > "$cache_source_log"
|
||||
if [ -f "$cached_archive" ]; then
|
||||
printf 'archive_source=runner-tool-cache\n' > "$cache_source_log"
|
||||
if ! cp "$cached_archive" "$temp_dir/$archive"; then
|
||||
fail_all "could not copy the pinned Trivy archive from runner tool cache"
|
||||
fi
|
||||
else
|
||||
printf 'archive_source=network\n' > "$cache_source_log"
|
||||
if ! curl --fail --silent --show-error --location --max-time 300 \
|
||||
--header 'Accept: application/octet-stream' \
|
||||
"$asset_api_url" --output "$temp_dir/$archive" \
|
||||
>"$output_dir/scanner-api-download.log" 2>&1; then
|
||||
fail_all "could not download pinned Trivy ${trivy_version} from release URL or GitHub asset API"
|
||||
"$download_url" --output "$temp_dir/$archive" \
|
||||
>"$output_dir/scanner-download.log" 2>&1; then
|
||||
rm -f "$temp_dir/$archive"
|
||||
if ! curl --fail --silent --show-error --location --max-time 300 \
|
||||
--header 'Accept: application/octet-stream' \
|
||||
"$asset_api_url" --output "$temp_dir/$archive" \
|
||||
>"$output_dir/scanner-api-download.log" 2>&1; then
|
||||
printf 'network_download=failed\n' >> "$cache_source_log"
|
||||
fail_all "could not download pinned Trivy ${trivy_version} from release URL or GitHub asset API"
|
||||
fi
|
||||
printf 'archive_source=github-release-asset-api\n' > "$cache_source_log"
|
||||
printf 'Downloaded pinned Trivy %s from GitHub release asset API.\n' "$trivy_version" \
|
||||
>>"$output_dir/scanner-api-download.log"
|
||||
else
|
||||
printf 'archive_source=github-release-download\n' > "$cache_source_log"
|
||||
fi
|
||||
printf 'Downloaded pinned Trivy %s from GitHub release asset API.\n' "$trivy_version" \
|
||||
>>"$output_dir/scanner-api-download.log"
|
||||
fi
|
||||
if ! printf '%s %s\n' "$expected_sha256" "$temp_dir/$archive" \
|
||||
| sha256sum --check --status; then
|
||||
|
||||
Reference in new issue
Block a user