Files
mtusi2026lab7/scripts/scan.sh
T
ALMiron 912a874f00
Skeleton contracts / contracts (pull_request) Blocked by required conditions
lab 7 openbao
2026-11-23 14:39:13 +03:00

48 lines
1.2 KiB
Bash

#!/bin/sh
# Dependency + image scan (results go to evidence/; triage by applicability is written in REPORT.md).
set -eu
cd "$(dirname "$0")/.."
mkdir -p evidence
# pip-audit: non-zero exit is expected when vulnerabilities are found.
docker run --rm \
-v "$PWD/requirements.txt:/r.txt:ro" \
python:3.12.11-slim-bookworm \
sh -c "pip install -q pip-audit && pip-audit -r /r.txt" \
> evidence/pip-audit.txt 2>&1 || true
# Trivy: preserve complete reports, including findings without fixes.
scan_failed=0
for img in \
mtusi-lab7-app:1.0.0 \
openbao/openbao:2.4.1 \
redis:7.4.2-alpine \
postgres:17.6-alpine \
haproxy:3.2.5-alpine
do
out="evidence/trivy-$(echo "$img" | tr '/:' '__').txt"
echo "Scanning $img ..."
if docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
aquasec/trivy:0.58.1 image \
--severity HIGH,CRITICAL \
"$img" > "$out" 2>&1
then
echo "PASS: $img; report saved to $out"
else
rc=$?
echo "ERROR: Trivy failed for $img (exit code $rc); see $out" >&2
scan_failed=1
fi
done
if [ "$scan_failed" -ne 0 ]; then
echo "Scan failed for one or more images" >&2
exit 1
fi
echo "scan finished: evidence/pip-audit.txt, evidence/trivy-*.txt"