Files
mtusi2026lab7/scripts/collect-evidence.sh
T

121 lines
6.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
set -eu
# Проверки lab7 на запущенном стенде (bootstrap: python3 scripts/bootstrap.py all) → evidence/.
# Всё по HTTPS с проверкой сертификата (CA_FILE), секреты и токены не печатаются.
#
# sh scripts/collect-evidence.sh base # возможности lab3–lab5 через HTTPS: smoke, failover, persistence, нагрузка
# sh scripts/collect-evidence.sh security # trust matrix, mTLS, ACL, OpenBao, hardening, ротация, lifecycle, Argon2id, утечки
# sh scripts/collect-evidence.sh pipeline # lab5–6 регрессии: pipeline-сценарии, сигналы наблюдаемости
# sh scripts/collect-evidence.sh track1 # трек 1: компрометация worker
# sh scripts/collect-evidence.sh all
cd "$(dirname "$0")/.."
PY=${PYTHON:-python3}
STOP=${STOP:-scripts/stop-one.sh}
RESTART=${RESTART:-scripts/restart.sh}
BASE=${BASE_URL:-https://localhost:8443}
CA_FILE=${CA_FILE:-$(pwd)/secrets/pki/ca.crt}
export CA_FILE PYTHONUTF8=1 PYTHON="$PY"
WHAT=${1:-all}
mkdir -p evidence evidence/security evidence/pipeline evidence/track1
step() { echo "== $*"; }
base() {
step "состояние стенда и образы"
{ date -u +%Y-%m-%dT%H:%M:%SZ; docker compose version; docker compose ps; } > evidence/docker_ps.txt
for img in $(docker compose config --images | sort -u); do
printf '%s %s\n' "$img" "$(docker image inspect --format '{{index .RepoDigests 0}}' "$img" 2>/dev/null || echo local-build)"
done > evidence/images.txt
cat evidence/images.txt
step "X-Instance-Id через LB"
$PY - "$BASE" > evidence/instances.txt <<'EOF'
import os, ssl, sys, urllib.request, collections
seen = collections.Counter()
ctx = ssl.create_default_context(cafile=os.environ['CA_FILE'])
for _ in range(20):
with urllib.request.urlopen(sys.argv[1] + '/health/ready', context=ctx) as r:
seen[r.headers['X-Instance-Id']] += 1
for k, v in sorted(seen.items()):
print(k, v)
EOF
cat evidence/instances.txt
step "smoke по HTTPS (make test BASE_URL=https://localhost:8443 CA_FILE=...)"
$PY tests/smoke.py --base-url "$BASE" --ca-file "$CA_FILE" | tee evidence/smoke.txt
step "make test-security (внешний TLS)"
$PY tests/security.py --base-url "$BASE" --ca-file "$CA_FILE" | tee evidence/test_security.txt
step "конкурентная идемпотентность"
$PY student-tests/idempotency_concurrent.py --base-url "$BASE" --output evidence/idempotency_concurrent.json | tail -1
step "регрессии lab3"
$PY student-tests/regressions.py --base-url "$BASE" > evidence/regressions.txt 2>&1
cat evidence/regressions.txt
step "публичный failover (с вложением), 2 прогона"
for n in 1 2; do
{ $PY tests/resilience.py --mode failover --action-script "$STOP" --base-url "$BASE" --ca-file "$CA_FILE" || echo "FAILED"; \
echo "-- контейнеры api после stop-one:"; docker compose ps -a api --format '{{.Name}} {{.ID}} {{.Status}}'; } \
> evidence/failover_$n.txt 2>&1
cat evidence/failover_$n.txt
sh scripts/restore.sh >> evidence/failover_$n.txt
done
step "persistence (restart хранилищ, OpenBao (+unseal оператора), наблюдаемости; volumes сохранены)"
{ echo "-- до:"; docker compose ps --format '{{.Name}} {{.Status}}'; \
$PY tests/resilience.py --mode persistence --action-script "$RESTART" --base-url "$BASE" --ca-file "$CA_FILE" || echo "FAILED"; \
echo "-- после:"; docker compose ps --format '{{.Name}} {{.Status}}'; } > evidence/persistence.txt 2>&1
cat evidence/persistence.txt
step "серия отказов каждой реплики под нагрузкой"
$PY student-tests/failover_series.py --base-url "$BASE" --output evidence/failover_series.json | tail -1
step "rolling update под нагрузкой"
docker compose build -q api
{ echo "-- до:"; docker compose ps api --format '{{.Name}} {{.ID}} {{.Status}}'; } > evidence/rolling_update.txt
$PY tests/load.py --base-url "$BASE" --ca-file "$CA_FILE" --duration 90 --concurrency 4 --output evidence/rolling_update_load.json > /dev/null &
LOAD=$!
sleep 5
start=$(date +%s)
sh scripts/rolling-update.sh >> evidence/rolling_update.txt 2>&1
echo "-- замена заняла $(( $(date +%s) - start )) s (внутри 90 s нагрузки)" >> evidence/rolling_update.txt
wait $LOAD
tail -4 evidence/rolling_update.txt; cat evidence/rolling_update_load.json
}
security() {
for s in tls-external mtls acl openbao hardening rotation lifecycle leaks argon2; do
step "безопасность: $s"
$PY student-tests/security_ops.py "$s" --base-url "$BASE" --ca-file "$CA_FILE" --output "evidence/security/$s.json" > "evidence/security/$s.log" 2>&1 || echo "FAILED: $s"
tail -1 "evidence/security/$s.log"
done
}
pipeline() {
for s in demo crash-effect transient failed-replay; do
step "pipeline: $s"
$PY student-tests/pipeline_ops.py "$s" --base-url "$BASE" --ca-file "$CA_FILE" --output "evidence/pipeline/$s.json" > "evidence/pipeline/$s.log" 2>&1 || echo "FAILED: $s"
tail -1 "evidence/pipeline/$s.log"
done
step "наблюдаемость lab6 через TLS: сигналы, сквозная трасса"
$PY student-tests/observability_ops.py signals --base-url "$BASE" --ca-file "$CA_FILE" --output evidence/pipeline/obs_signals.json > evidence/pipeline/obs_signals.log 2>&1 || echo "FAILED: obs signals"
tail -1 evidence/pipeline/obs_signals.log
}
track1() {
step "трек 1: компрометация worker"
$PY student-tests/compromise.py --base-url "$BASE" --ca-file "$CA_FILE" --output evidence/track1/compromise.json > evidence/track1/compromise.log 2>&1 || echo "FAILED: compromise"
tail -3 evidence/track1/compromise.log
}
case "$WHAT" in
base) base ;;
security) security ;;
pipeline) pipeline ;;
track1) track1 ;;
all) base; security; pipeline; track1 ;;
*) echo "usage: $0 base|security|pipeline|track1|all" >&2; exit 2 ;;
esac
docker stats --no-stream --format '{{.Name}} {{.CPUPerc}} {{.MemUsage}}' > "evidence/docker_stats_$WHAT.txt"