Files
mtusi2026lab7/scripts/openbao_seal_test.sh
T
2026-11-27 16:42:18 +03:00

47 lines
2.1 KiB
Bash

#!/bin/sh
# Проверка поведения при sealed OpenBao: работающие реплики продолжают servить,
# новая реплика fail-closed не становится ready, после unseal восстанавливается.
set -eu
export MSYS_NO_PATHCONV=1
export MSYS2_ARG_CONV_EXCL="*"
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
cd "$ROOT"
CURL_OPTS=""
case "$(uname -s 2>/dev/null || true)" in
MINGW*|MSYS*|CYGWIN*) CURL_OPTS="--ssl-no-revoke" ;;
esac
mkdir -p evidence
ROOT_TOKEN=$(python -c "import json;print(json.load(open('secrets/openbao-init.json'))['root_token'])")
curl $CURL_OPTS --cacert certs/ca.crt -fsS -X PUT -H "X-Vault-Token: $ROOT_TOKEN" https://127.0.0.1:8200/v1/sys/seal >/dev/null
sleep 2
{
echo "# OpenBao sealed, $(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo -n "existing API readiness through LB: "
curl $CURL_OPTS --cacert certs/ca.crt -s -o /dev/null -w '%{http_code}\n' https://localhost:8443/health/ready || true
} > evidence/openbao-sealed.txt
docker stop lab7-api-2 >/dev/null
: > /tmp/api2-before-start.log
docker start lab7-api-2 >/dev/null
sleep 18
{
echo "new API container state: $(docker inspect -f '{{.State.Status}} restarts={{.RestartCount}} health={{if .State.Health}}{{.State.Health.Status}}{{end}}' lab7-api-2)"
echo -n "new API local /health/ready during seal: "
docker exec lab7-api-2 python -c "import urllib.request,urllib.error;
try:
print(urllib.request.urlopen('http://127.0.0.1:8080/health/ready',timeout=2).status)
except Exception as e:
print(type(e).__name__)" 2>&1 || true
echo "--- new API log lines since seal ---"
docker logs --since 20s lab7-api-2 2>&1 | tail -n 6
} >> evidence/openbao-sealed.txt
docker compose --env-file .env run --rm --no-deps openbao-bootstrap >/dev/null
sleep 12
{
echo "--- after unseal ---"
echo -n "readiness through LB: "
curl $CURL_OPTS --cacert certs/ca.crt -s -o /dev/null -w '%{http_code}\n' https://localhost:8443/health/ready || true
echo "api-2 state: $(docker inspect -f '{{.State.Status}} health={{if .State.Health}}{{.State.Health.Status}}{{end}}' lab7-api-2)"
} >> evidence/openbao-sealed.txt
cat evidence/openbao-sealed.txt