Files
mtusi2026lab7/scripts/collect-evidence.sh
T
sendormeco d15f2a3631
Application stack (lab7) / stack (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
7 — Т2302 — ебедев — на 5
2026-11-22 23:26:17 +03:00

88 lines
7.0 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
# Полный прогон доказательств lab7 на Compose-стенде; вывод — evidence/ (без токенов, паролей, ключей).
# ВНИМАНИЕ: останавливает/перезапускает контейнеры, ротирует сертификаты и учётные данные, запечатывает OpenBao
# (затем распечатывает материалом оператора). Volumes не удаляются. Длительность ≈ 60–75 мин;
# SKIP_REGRESSION=1 — без регрессии lab2–lab6 (−30 мин); SKIP_RESEARCH=1 — без трека 1 и login DoS (−8 мин).
# Для dependency scan укажите GHSA_DB=/путь/к/advisory-database (см. scripts/dep_scan.py).
set -eu
cd "$(dirname "$0")/.."
. scripts/lib.sh
PY=${PYTHON:-python3}
B=${BASE_URL:-https://127.0.0.1:8443}
CA="$PWD/secrets/tls/trust/ca.crt"
export BASE_URL=$B CA_FILE=$CA TTL_BASE_URL=${TTL_BASE_URL:-https://127.0.0.1:8444} NO_PROXY=127.0.0.1,localhost no_proxy=127.0.0.1,localhost
mkdir -p evidence evidence/track1 evidence/scan
stamp() { echo "# $(now) commit=$(git rev-parse --short HEAD 2>/dev/null || echo n/a) host=$(uname -srm) cpus=$(getconf _NPROCESSORS_ONLN)"; }
run() { name=$1; shift; { stamp; echo "\$ $*"; "$@" 2>&1; echo "exit=$?"; } > "evidence/$name.txt" || true; tail -2 "evidence/$name.txt"; }
IN_WORKER="dc run --rm --no-deps -T -v $PWD/student-tests:/app/student-tests:ro --entrypoint python worker"
IN_API="dc run --rm --no-deps -T -v $PWD/student-tests:/app/student-tests:ro --entrypoint python api"
./scripts/init-secrets.sh
PROFILES="--profile ttl" ./scripts/up.sh
dc --profile tools up -d ops
{ stamp; docker version --format 'docker {{.Server.Version}}'; dc version; dc --profile ttl images; dc --profile ttl ps -a; state; } > evidence/stack.txt 2>&1
# ---------------------------------------------------------------- bootstrap (значения секретов не выводятся)
run pki-status dc --profile tools run --rm --no-deps -T pki status
run openbao-status sh -c "$PY scripts/bao_admin.py status; $PY scripts/bao_admin.py kv-keys api; $PY scripts/bao_admin.py kv-keys worker; $PY scripts/bao_admin.py tokens api"
run migrations sh -c "docker compose --env-file .env exec -T -u postgres postgres psql -d messenger -c 'SELECT version, left(checksum,12) AS checksum, applied_at FROM schema_migrations ORDER BY version' -c '\\du'; docker compose --env-file .env logs --no-log-prefix migrate"
run broker-bootstrap dc logs --no-log-prefix broker-init
run s3-bootstrap dc logs --no-log-prefix s3-init
run published-ports sh -c "docker compose --env-file .env ps --format '{{.Service}} {{.Ports}}' | sort -u"
run kdf-bench dc exec -T api python -m messenger kdf-bench
# ---------------------------------------------------------------- публичные проверки (HTTPS + CA)
run make-check make check
run smoke $PY tests/smoke.py --base-url "$B" --ca-file "$CA"
run test-security-public $PY tests/security.py --base-url "$B" --ca-file "$CA"
# ---------------------------------------------------------------- lab7: матрица доверия, внешняя граница, hardening
run internal-security dc --profile tests run --rm -T probe student-tests/internal_security.py
run test-security $PY student-tests/test_security.py
run test-hardening $PY student-tests/test_hardening.py --json evidence/hardening.json
if [ -d "${GHSA_DB:-/tmp/ghsa}/advisories" ]; then
run dep-scan $PY scripts/dep_scan.py --db "${GHSA_DB:-/tmp/ghsa}" --json evidence/scan/deps.json
fi
# ---------------------------------------------------------------- регрессия lab2–lab6 (поверх HTTPS/mTLS/OpenBao)
if [ "${SKIP_REGRESSION:-0}" != 1 ]; then
# Учебные хуки отказов lab5 (маркер в имени файла) по умолчанию ВЫКЛЮЧЕНЫ (это вектор DoS) — включаем только
# на время регрессии и выключаем обратно. export: тесты сами пересоздают worker и должны унаследовать значение.
export FAULT_HOOKS=lab
dc up -d --no-deps --force-recreate --wait api worker >/dev/null 2>&1
run test-api $PY student-tests/test_api.py
run test-idempotency $PY student-tests/test_idempotency.py
run test-attachments $PY student-tests/test_attachments.py
run test-expiry $PY student-tests/test_expiry.py
run test-cache-race $IN_API student-tests/test_cache_race.py
run test-pipeline $PY student-tests/test_pipeline.py
run test-imgproc $IN_WORKER student-tests/test_imgproc.py
run test-failures $PY student-tests/test_failures.py
run test-observability $PY student-tests/test_observability.py
run test-jobs-failures $PY student-tests/test_jobs_failures.py
run test-storage-failures $PY student-tests/test_storage_failures.py
run test-pipeline-idempotency $PY student-tests/test_pipeline_idempotency.py
run test-telemetry-persistence $PY student-tests/test_telemetry_persistence.py
unset FAULT_HOOKS
dc --profile fault stop api-fault >/dev/null 2>&1 || true
dc up -d --no-deps --force-recreate --wait api worker >/dev/null 2>&1
fi
# ---------------------------------------------------------------- отказ реплик и сохранность (публичные hooks)
: > evidence/failover-hook.txt
run failover-1 $PY tests/resilience.py --mode failover --action-script scripts/stop-one.sh --base-url "$B" --ca-file "$CA"
run restore-1 ./scripts/start-replicas.sh
run failover-2 $PY tests/resilience.py --mode failover --action-script scripts/stop-one.sh --base-url "$B" --ca-file "$CA"
run restore-2 ./scripts/start-replicas.sh
: > evidence/restart-hook.txt
run persistence $PY tests/resilience.py --mode persistence --action-script scripts/restart.sh --base-url "$B" --ca-file "$CA"
# ---------------------------------------------------------------- уровень 4: lifecycle под нагрузкой
run test-lifecycle $PY student-tests/test_lifecycle.py --json evidence/lifecycle.json
# ---------------------------------------------------------------- трек 5.1 и бюджет login DoS
if [ "${SKIP_RESEARCH:-0}" != 1 ]; then
run track1-worker-compromise $PY research/worker_compromise.py --out evidence/track1
run login-dos $PY research/login_dos.py --out evidence/login_dos.json
fi
# ---------------------------------------------------------------- итог: всё ещё работает после ротаций/инцидентов
run internal-security-final dc --profile tests run --rm -T probe student-tests/internal_security.py
run smoke-final $PY tests/smoke.py --base-url "$B" --ca-file "$CA"
run jobs-invariants dc --profile tools exec -T ops python -m messenger jobs invariants --settled --verify-bytes
run load $PY tests/load.py --base-url "$B" --ca-file "$CA" --duration 30 --concurrency 4 --output evidence/load.json
run secret-scan $PY scripts/secret_scan.py
echo "evidence collected in evidence/"