Files
marqdo/ci/images/scan.sh
T
cflmyandCursor a61f3442bc
ci/woodpecker/push/eco Pipeline is pending
ci/woodpecker/pr/eco Pipeline is pending
ci: complete component release propagation for issue #10
Add authoritative component-release helpers, evidence-aware reconcile with
freshness and root upstream dispatch, least-privilege secrets, image scan
and multi-arch build gates, and pin active component publish workflows.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-27 19:30:18 +08:00

104 lines
4.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Scan published Marqdo CI images by digest.
#
# Records:
# - registry digest / platform manifests (buildx imagetools)
# - optional Trivy CVE report when `trivy` or `$TRIVY_IMAGE` is available
# - a fail-closed provenance check that consumers pin immutable tags
#
# Usage:
# ci/images/scan.sh [--out docs/evidence/ci-image-scan]
set -euo pipefail
root="$(cd "$(dirname "$0")/../.." && pwd)"
registry="${MARQDO_CI_REGISTRY:-git.cflmy.cn/cflmy}"
version="${MARQDO_CLI_VERSION:-3.0.0-rc.5}"
out="${1:-$root/docs/evidence/ci-image-scan-$version}"
if [[ "${1:-}" == "--out" ]]; then
out="${2:?}"
fi
mkdir -p "$out"
images=(
"marqdo-ci-shell:$version"
"marqdo-ci-rust:$version"
"marqdo-ci-web:$version"
)
echo "==> inspect manifests"
: >"$out/digests.txt"
for image in "${images[@]}"; do
ref="$registry/$image"
echo "--- $ref" | tee -a "$out/digests.txt"
if ! docker buildx imagetools inspect "$ref" >"$out/${image//[:\/]/_}.inspect.txt" 2>"$out/${image//[:\/]/_}.inspect.err"; then
echo "UNVERIFIED: cannot inspect $ref" | tee -a "$out/digests.txt"
continue
fi
digest=$(awk '/^Digest:/{print $2; exit}' "$out/${image//[:\/]/_}.inspect.txt")
platforms=$(awk '/Platform:/{print $2}' "$out/${image//[:\/]/_}.inspect.txt" | paste -sd, -)
echo "$ref digest=$digest platforms=$platforms" | tee -a "$out/digests.txt"
done
echo "==> optional Trivy scan"
trivy_bin="${TRIVY_BIN:-}"
if [[ -z "$trivy_bin" && -x "$root/.build/tools/trivy" ]]; then
trivy_bin="$root/.build/tools/trivy"
fi
if [[ -n "$trivy_bin" ]]; then
for image in "${images[@]}"; do
ref="$registry/$image"
"$trivy_bin" image --quiet --format json --output "$out/${image//[:\/]/_}.trivy.json" "$ref" || \
echo "trivy failed for $ref" >"$out/${image//[:\/]/_}.trivy.err"
done
elif [[ -n "${TRIVY_IMAGE:-}" ]]; then
for image in "${images[@]}"; do
ref="$registry/$image"
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
"$TRIVY_IMAGE" image --quiet --format json "$ref" \
>"$out/${image//[:\/]/_}.trivy.json" || \
echo "trivy container failed for $ref" >"$out/${image//[:\/]/_}.trivy.err"
done
else
echo "Trivy binary/image unavailable; CVE scan marked UNVERIFIED" | tee "$out/trivy-UNVERIFIED.txt"
fi
echo "==> provenance / pin check"
ROOT="$root" OUT="$out" VERSION="$version" python3 - <<'PY'
import os, pathlib, re, sys
root = pathlib.Path(os.environ["ROOT"])
out = pathlib.Path(os.environ["OUT"])
version = os.environ["VERSION"]
pattern = re.compile(r"git\.cflmy\.cn/cflmy/marqdo-ci-(shell|rust|web):([^\s\"']+)")
bad = []
skip = {".build", "node_modules", ".git", "cargo-home", ".cargo"}
for path in list(root.glob("**/.woodpecker/*.yml")) + list(root.glob("**/.woodpecker/*.yaml")):
if any(part in skip for part in path.parts):
continue
text = path.read_text(encoding="utf-8", errors="replace")
for match in pattern.finditer(text):
tag = match.group(2)
if tag in ("latest", "main", "master") or tag.endswith("-latest"):
bad.append(f"{path}: floating tag {tag}")
elif tag != version and not tag.startswith(version):
bad.append(f"{path}: unexpected tag {tag} (expected {version})")
report = out / "pin-check.txt"
if bad:
report.write_text("FAIL\n" + "\n".join(bad) + "\n", encoding="utf-8")
print("pin check failed; see", report, file=sys.stderr)
raise SystemExit(1)
report.write_text(f"PASS: workflows pin marqdo-ci-*:{version}\n", encoding="utf-8")
print(report.read_text().strip())
PY
cat >"$out/SUMMARY.md" <<EOF
# CI image scan ($version)
- Registry: \`$registry\`
- Digests: see \`digests.txt\`
- Pin check: see \`pin-check.txt\`
- CVE: Trivy output when available; otherwise \`trivy-UNVERIFIED.txt\`
- Platforms: current production consumers use \`linux/amd64\`. Multi-arch
builds are produced by \`ci/images/build.sh\` when \`MARQDO_CI_PLATFORMS\`
includes \`linux/arm64\`; arm64 CI execution remains UNVERIFIED until an
arm64 runner exists.
EOF
echo "scan complete: $out"