Skip to content

eBPF-based security platform

backend: refuse an sbom-scan that cannot list the objects to copy

John Fastabendafb6bbfcd081
diff --git a/tools/backend/jobs/sbom-scan b/tools/backend/jobs/sbom-scan
index 75036575..738e14f7 100755
--- a/tools/backend/jobs/sbom-scan
+++ b/tools/backend/jobs/sbom-scan
@@ -125,8 +125,11 @@ file://?*)
s3://?*)
# Only the objects the job reads, every one of them: each run
# scans every image again.
+ names=$(python3 "$here/sbom-rows.py" files) ||
+ die "cannot list the objects to copy, nothing loaded"
+ [ -n "$names" ] || die "no object to copy is known, nothing loaded"
set --
- for name in $(python3 "$here/sbom-rows.py" files); do
+ for name in $names; do
set -- "$@" --include "*/$name"
done
directory=$work/store
diff --git a/tools/backend/test/sbom-scan-s3.expected b/tools/backend/test/sbom-scan-s3.expected
index 4c49490e..da5be711 100644
--- a/tools/backend/test/sbom-scan-s3.expected
+++ b/tools/backend/test/sbom-scan-s3.expected
@@ -6,6 +6,8 @@ rows: 2
stub-aws: s3 cp --recursive --only-show-errors s3://fleet-images/sboms <directory> --exclude * --include */image.json --include */sbom.cdx.json
sbom-scan: cannot copy s3://fleet-images/sboms, nothing loaded
copy fails: status 1
+sbom-scan: cannot list the objects to copy, nothing loaded
+no object list: status 1
sbom-scan: the store https://registry.example.com/sboms is neither file://<directory> nor s3://<bucket>
https store: status 1
sbom-scan: the store s3:// is neither file://<directory> nor s3://<bucket>
diff --git a/tools/backend/test/sbom-scan-s3.sh b/tools/backend/test/sbom-scan-s3.sh
index e57aa5b0..57ecfe97 100644
--- a/tools/backend/test/sbom-scan-s3.sh
+++ b/tools/backend/test/sbom-scan-s3.sh
@@ -5,8 +5,8 @@
# jobs/sbom-scan over an s3:// store, with test/stub-aws.sh in place of
# the AWS command line: the job copies the objects it reads and scans
# them as it does a file:// store. Then what it refuses, each with a
-# message and without loading anything: a copy that fails, a store of
-# another kind or none, a file:// directory that is not there and a
+# message and without loading anything: a copy that fails, a list of the
+# objects to copy that cannot be had, a store of another kind or none, a file:// directory that is not there and a
# matcher that cannot say its version.
set -eu
@@ -49,6 +49,11 @@ refused()
rows
refused 'copy fails' 1 env STUB_S3_STATUS=1 "$job" \
--store s3://fleet-images/sboms --trivy "$test/stub-trivy.sh"
+mkdir "$work/bin"
+printf '#!/bin/sh\nexit 1\n' >"$work/bin/python3"
+chmod 0755 "$work/bin/python3"
+refused 'no object list' 1 env PATH="$work/bin:$PATH" "$job" \
+ --store s3://fleet-images/sboms --trivy "$test/stub-trivy.sh"
refused 'https store' 1 "$job" --store https://registry.example.com/sboms \
--trivy "$test/stub-trivy.sh"
refused 'empty s3 store' 1 "$job" --store s3:// --trivy "$test/stub-trivy.sh"