Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35a21f8ab5 | ||
|
|
2d0deb8963 | ||
|
|
f0a79362eb | ||
|
|
27f86d4916 |
No files matched your search
@@ -53,6 +53,16 @@ jobs:
|
||||
RELEASE_TAG: ${{ inputs.resume_tag }}
|
||||
RESUME_SOURCE_SHA: ${{ inputs.resume_source_sha }}
|
||||
run: python3 scripts/ci-release-resume.py
|
||||
- name: Preserve updated image scanner for resume
|
||||
id: pin_resume_scanner
|
||||
if: inputs.resume_tag != ''
|
||||
run: |
|
||||
set -eu
|
||||
scanner_dir="$(mktemp -d "${RUNNER_TEMP:?RUNNER_TEMP is unavailable}/crank-release-scanner.XXXXXX")"
|
||||
cp scripts/scan-images.sh "$scanner_dir/scan-images.sh"
|
||||
cp scripts/check-image-scan.py "$scanner_dir/check-image-scan.py"
|
||||
chmod +x "$scanner_dir/scan-images.sh"
|
||||
printf 'path=%s\n' "$scanner_dir/scan-images.sh" >> "$GITHUB_OUTPUT"
|
||||
- name: Checkout validated release source
|
||||
if: inputs.resume_tag != ''
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
@@ -302,6 +312,8 @@ jobs:
|
||||
docker login '${{ env.REGISTRY }}' -u "$DEPLOY_REGISTRY_USER" --password-stdin
|
||||
|
||||
- name: Build and push release images
|
||||
env:
|
||||
RELEASE_IMAGE_SCANNER: ${{ steps.pin_resume_scanner.outputs.path || 'scripts/scan-images.sh' }}
|
||||
run: |
|
||||
docker build -f apps/admin-api/Dockerfile \
|
||||
-t '${{ env.ADMIN_API_IMAGE }}:${{ env.IMAGE_TAG }}' \
|
||||
@@ -338,7 +350,7 @@ jobs:
|
||||
--env-file .tmp/release-migration-smoke.env --profile local-db up -d --wait
|
||||
docker compose -f deploy/community/docker-compose.images.yml \
|
||||
--env-file .tmp/release-migration-smoke.env --profile local-db logs migrate | grep '"status":"applied"'
|
||||
scripts/scan-images.sh \
|
||||
"$RELEASE_IMAGE_SCANNER" \
|
||||
'${{ env.ADMIN_API_IMAGE }}:${{ env.IMAGE_TAG }}' \
|
||||
'${{ env.MCP_SERVER_IMAGE }}:${{ env.IMAGE_TAG }}' \
|
||||
'${{ env.UI_IMAGE }}:${{ env.IMAGE_TAG }}'
|
||||
|
||||
+15
-1
@@ -45,6 +45,10 @@ trivy_version="0.70.0"
|
||||
archive="trivy_${trivy_version}_Linux-64bit.tar.gz"
|
||||
expected_sha256="8b4376d5d6befe5c24d503f10ff136d9e0c49f9127a4279fd110b727929a5aa9"
|
||||
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"
|
||||
db_repository_primary="ghcr.io/aquasecurity/trivy-db:2"
|
||||
db_repository_fallback="mirror.gcr.io/aquasec/trivy-db:2"
|
||||
|
||||
output_dir="${CRANK_IMAGE_SCAN_OUTPUT_DIR:-.tmp/image-scan-evidence}"
|
||||
if ! mkdir -p "$output_dir"; then
|
||||
@@ -104,7 +108,15 @@ PY
|
||||
if ! curl --fail --silent --show-error --location --max-time 300 \
|
||||
"$download_url" --output "$temp_dir/$archive" \
|
||||
>"$output_dir/scanner-download.log" 2>&1; then
|
||||
fail_all "could not download pinned Trivy ${trivy_version}"
|
||||
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
|
||||
fail_all "could not download pinned Trivy ${trivy_version} from release URL or GitHub asset API"
|
||||
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
|
||||
@@ -120,6 +132,8 @@ fi
|
||||
|
||||
# Download one fresh vulnerability database; every scan reuses it read-only.
|
||||
if ! "$trivy_bin" image --config /dev/null --download-db-only --cache-dir "$cache_dir" \
|
||||
--db-repository "$db_repository_primary" \
|
||||
--db-repository "$db_repository_fallback" \
|
||||
--no-progress --skip-version-check \
|
||||
>"$output_dir/db-download.log" 2>&1; then
|
||||
fail_all "could not download the Trivy vulnerability database"
|
||||
|
||||
@@ -214,6 +214,25 @@ class WorkflowResumeTests(unittest.TestCase):
|
||||
self.assertIn("if: inputs.resume_tag == '' && startsWith(gitea.ref, 'refs/tags/v')", workflow)
|
||||
self.assertIn("if: inputs.resume_tag == ''\n run: |\n ls -lh dist", workflow)
|
||||
|
||||
def test_resume_preserves_updated_scanner_before_old_source_checkout(self):
|
||||
workflow = (ROOT / ".gitea/workflows/release.yml").read_text()
|
||||
pin = workflow.index("- name: Preserve updated image scanner for resume")
|
||||
old_checkout = workflow.index("- name: Checkout validated release source")
|
||||
source_assert = workflow.index("- name: Assert exact release source checkout")
|
||||
image_build = workflow.index("- name: Build and push release images")
|
||||
self.assertLess(pin, old_checkout)
|
||||
self.assertLess(old_checkout, source_assert)
|
||||
self.assertLess(source_assert, image_build)
|
||||
pin_step = workflow[pin:old_checkout]
|
||||
self.assertIn("if: inputs.resume_tag != ''", pin_step)
|
||||
self.assertIn('cp scripts/scan-images.sh "$scanner_dir/scan-images.sh"', pin_step)
|
||||
self.assertIn('cp scripts/check-image-scan.py "$scanner_dir/check-image-scan.py"', pin_step)
|
||||
build_step = workflow[image_build:]
|
||||
self.assertIn("RELEASE_IMAGE_SCANNER: ${{ steps.pin_resume_scanner.outputs.path || 'scripts/scan-images.sh' }}", build_step)
|
||||
self.assertIn('"$RELEASE_IMAGE_SCANNER" \\', build_step)
|
||||
self.assertIn("ref: ${{ steps.resume.outputs.release_tag }}", workflow)
|
||||
self.assertIn('test "$(git rev-parse HEAD)" = "$EXPECTED_SOURCE_SHA"', workflow)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -27,9 +27,18 @@ import os
|
||||
import sys
|
||||
|
||||
args = sys.argv[1:]
|
||||
if os.environ.get("FAKE_CURL_FAIL") == "1":
|
||||
sys.stderr.write("curl: (7) failed to connect\\n")
|
||||
url = next((value for value in args if value.startswith("https://")), "")
|
||||
api_download = url == "https://api.github.com/repos/aquasecurity/trivy/releases/assets/398381981"
|
||||
failed = os.environ.get("FAKE_CURL_FAIL") == "1"
|
||||
failed = failed or (not api_download and os.environ.get("FAKE_CURL_DIRECT_FAIL") == "1")
|
||||
failed = failed or (api_download and os.environ.get("FAKE_CURL_API_FAIL") == "1")
|
||||
if failed:
|
||||
sys.stderr.write("curl: (22) fixture download failure for " + url + "\\n")
|
||||
sys.exit(7)
|
||||
if api_download:
|
||||
if "--header" not in args or args[args.index("--header") + 1] != "Accept: application/octet-stream":
|
||||
sys.stderr.write("curl: missing octet-stream Accept header\\n")
|
||||
sys.exit(2)
|
||||
output = None
|
||||
for index, value in enumerate(args):
|
||||
if value in ("--output", "-o"):
|
||||
@@ -37,7 +46,8 @@ for index, value in enumerate(args):
|
||||
if output is None:
|
||||
sys.stderr.write("curl: missing --output\\n")
|
||||
sys.exit(2)
|
||||
with open(os.environ["FAKE_CURL_ARCHIVE"], "rb") as source:
|
||||
archive_path = os.environ.get("FAKE_CURL_API_ARCHIVE", os.environ["FAKE_CURL_ARCHIVE"]) if api_download else os.environ["FAKE_CURL_ARCHIVE"]
|
||||
with open(archive_path, "rb") as source:
|
||||
payload = source.read()
|
||||
with open(output, "wb") as target:
|
||||
target.write(payload)
|
||||
@@ -176,6 +186,9 @@ class ScanImagesWrapperTests(unittest.TestCase):
|
||||
images=(VULN_TAG, CLEAN_TAG),
|
||||
trivy_fail_id=None,
|
||||
curl_fail=False,
|
||||
curl_direct_fail=False,
|
||||
curl_api_fail=False,
|
||||
api_checksum_mismatch=False,
|
||||
extra_env=None,
|
||||
workdir_files=None,
|
||||
run_in_workdir=False,
|
||||
@@ -214,6 +227,8 @@ class ScanImagesWrapperTests(unittest.TestCase):
|
||||
|
||||
archive_path = root / "trivy-fixture.tar.gz"
|
||||
archive_path.write_bytes(fixture_archive)
|
||||
api_archive_path = root / "trivy-api-fixture.tar.gz"
|
||||
api_archive_path.write_bytes(fixture_archive + b"tampered" if api_checksum_mismatch else fixture_archive)
|
||||
|
||||
reports = root / "reports"
|
||||
reports.mkdir()
|
||||
@@ -248,6 +263,7 @@ class ScanImagesWrapperTests(unittest.TestCase):
|
||||
"PATH": f"{bin_dir}:{env['PATH']}",
|
||||
"CRANK_IMAGE_SCAN_OUTPUT_DIR": str(evidence),
|
||||
"FAKE_CURL_ARCHIVE": str(archive_path),
|
||||
"FAKE_CURL_API_ARCHIVE": str(api_archive_path),
|
||||
"FAKE_IMAGE_MAP": str(image_map),
|
||||
"FAKE_REPORT_DIR": str(reports),
|
||||
"FAKE_DOCKER_LOG": str(docker_log),
|
||||
@@ -258,6 +274,10 @@ class ScanImagesWrapperTests(unittest.TestCase):
|
||||
env["FAKE_TRIVY_FAIL_ID"] = trivy_fail_id
|
||||
if curl_fail:
|
||||
env["FAKE_CURL_FAIL"] = "1"
|
||||
if curl_direct_fail:
|
||||
env["FAKE_CURL_DIRECT_FAIL"] = "1"
|
||||
if curl_api_fail:
|
||||
env["FAKE_CURL_API_FAIL"] = "1"
|
||||
if extra_env:
|
||||
env.update(extra_env)
|
||||
|
||||
@@ -412,6 +432,18 @@ class ScanImagesWrapperTests(unittest.TestCase):
|
||||
self.assertEqual(result.returncode, 2, result.stderr)
|
||||
self.assertEqual(receipt["overall"]["status"], "error")
|
||||
|
||||
def test_database_download_uses_official_priority_and_fallback(self):
|
||||
result, _, _, _, _, trivy_calls = self.run_scan(images=(CLEAN_TAG,))
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
downloads = [call["args"] for call in trivy_calls if "--download-db-only" in call["args"]]
|
||||
self.assertEqual(len(downloads), 1)
|
||||
args = downloads[0]
|
||||
repositories = [args[index + 1] for index, item in enumerate(args) if item == "--db-repository"]
|
||||
self.assertEqual(
|
||||
repositories,
|
||||
["ghcr.io/aquasecurity/trivy-db:2", "mirror.gcr.io/aquasec/trivy-db:2"],
|
||||
)
|
||||
|
||||
def test_rerun_cannot_reuse_an_old_successful_raw_report(self):
|
||||
result, _, evidence, receipt, _, _ = self.run_scan(images=(CLEAN_TAG,), repeat_without_output=True)
|
||||
self.assertEqual(result.returncode, 2, result.stderr)
|
||||
@@ -430,6 +462,37 @@ class ScanImagesWrapperTests(unittest.TestCase):
|
||||
self.assertEqual(docker_calls, [])
|
||||
self.assertEqual(trivy_calls, [])
|
||||
|
||||
def test_pinned_asset_api_fallback_downloads_and_verifies_same_archive(self):
|
||||
result, _, evidence, receipt, _, trivy_calls = self.run_scan(
|
||||
images=(CLEAN_TAG,), curl_direct_fail=True
|
||||
)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(receipt["overall"]["status"], "pass")
|
||||
self.assertIn("fixture download failure", (evidence / "scanner-download.log").read_text())
|
||||
self.assertIn("GitHub release asset API", (evidence / "scanner-api-download.log").read_text())
|
||||
self.assertTrue(any("--download-db-only" in call["args"] for call in trivy_calls))
|
||||
scanner = json.loads((evidence / "scanner.json").read_text(encoding="utf-8"))
|
||||
self.assertEqual(scanner["expected_version"], "0.70.0")
|
||||
|
||||
def test_pinned_asset_api_fallback_failure_fails_closed_with_both_logs(self):
|
||||
result, _, evidence, receipt, _, trivy_calls = self.run_scan(
|
||||
images=(CLEAN_TAG,), curl_direct_fail=True, curl_api_fail=True
|
||||
)
|
||||
self.assertEqual(result.returncode, 2)
|
||||
self.assertEqual(receipt["overall"]["status"], "error")
|
||||
self.assertIn("fixture download failure", (evidence / "scanner-download.log").read_text())
|
||||
self.assertIn("fixture download failure", (evidence / "scanner-api-download.log").read_text())
|
||||
self.assertEqual(trivy_calls, [])
|
||||
|
||||
def test_pinned_asset_api_fallback_checksum_mismatch_never_executes_trivy(self):
|
||||
result, _, evidence, receipt, _, trivy_calls = self.run_scan(
|
||||
images=(CLEAN_TAG,), curl_direct_fail=True, api_checksum_mismatch=True
|
||||
)
|
||||
self.assertEqual(result.returncode, 2)
|
||||
self.assertEqual(receipt["overall"]["status"], "error")
|
||||
self.assertIn("checksum mismatch", result.stderr)
|
||||
self.assertEqual(trivy_calls, [])
|
||||
|
||||
def test_unknown_image_is_error_and_is_never_scanned(self):
|
||||
missing = "crank/missing:ci"
|
||||
result, _, _, receipt, _, trivy_calls = self.run_scan(images=(missing, CLEAN_TAG))
|
||||
@@ -445,7 +508,8 @@ class ScanImagesWrapperTests(unittest.TestCase):
|
||||
result, _, evidence, receipt, _, _ = self.run_scan(curl_fail=True)
|
||||
self.assertEqual(result.returncode, 2, result.stderr)
|
||||
self.assertEqual(receipt["overall"]["status"], "error")
|
||||
self.assertIn("failed to connect", (evidence / "scanner-download.log").read_text())
|
||||
self.assertIn("fixture download failure", (evidence / "scanner-download.log").read_text())
|
||||
self.assertIn("fixture download failure", (evidence / "scanner-api-download.log").read_text())
|
||||
|
||||
def test_evidence_kept_even_when_gate_is_red(self):
|
||||
_, _, evidence, receipt, _, _ = self.run_scan()
|
||||
|
||||
Reference in new issue
Block a user