#!/bin/sh # Output JSON reports. Exit nonzero on scanner findings or incomplete runs. set -eu cd "$(dirname "$0")/.." : "${SCAN_OUTPUT:?Set SCAN_OUTPUT to a report directory}" mkdir -p "$SCAN_OUTPUT" out=$(cd "$SCAN_OUTPUT" && pwd -P) mkdir -p "${SCAN_CACHE:-$out/cache}" cache=$(cd "${SCAN_CACHE:-$out/cache}" && pwd -P) audit=${PIP_AUDIT:-pip-audit} scanner=aquasec/trivy:0.66.0@sha256:086971aaf400beebd94e8300fd8ea623774419597169156cec56eec5b00dfb1e status=0 ./scripts/compose.sh --profile operator --profile bootstrap config --format json | python3 scripts/check-hardening.py > "$out/hardening.txt" || status=1 # Audit the exact installed dependency set, including transitive dependencies. app_image=$(./scripts/compose.sh config --format json | python3 -c 'import json,sys; print(json.load(sys.stdin)["services"]["migrate"]["image"])') docker run --rm --network none --entrypoint python "$app_image" \ -m pip freeze > "$out/runtime-pins.txt" "$audit" --no-deps --disable-pip -r "$out/runtime-pins.txt" -f json -o "$out/python.json" || status=1 "$audit" -r requirements-dev.txt -f json -o "$out/dev-python.json" || status=1 docker run --rm --mount "type=bind,src=$PWD,dst=/project,readonly" \ --mount "type=bind,src=$cache,dst=/cache" --mount "type=bind,src=$out,dst=/results" \ "$scanner" --cache-dir /cache \ config --skip-files /project/Dockerfile.example --misconfig-scanners dockerfile --exit-code 1 --format json \ --output /results/dockerfiles.json /project || status=1 ./scripts/compose.sh --profile operator --profile bootstrap config --images | sort -u > "$out/images.txt" while IFS= read -r image; do name=$(printf '%s' "$image" | tr '/:@' '___') archive=$(mktemp "$out/image.XXXXXX") if docker save -o "$archive" "$image"; then docker run --rm -e "TRIVY_SKIP_DB_UPDATE=${TRIVY_SKIP_DB_UPDATE:-false}" \ --mount "type=bind,src=$cache,dst=/cache" --mount "type=bind,src=$out,dst=/results" \ "$scanner" --cache-dir /cache \ image --input "/results/${archive##*/}" --scanners vuln --image-config-scanners misconfig \ --severity HIGH,CRITICAL --exit-code 1 --format json --output "/results/$name.json" || status=1 else status=1 fi if [ -f "$archive" ]; then unlink "$archive"; fi done < "$out/images.txt" exit "$status"