lab7: Argon2id из env (замер bench/argon2_bench.py), лимит неудачных входов в Valkey (429 + Retry-After), cap_drop ALL и no-new-privileges, X-Instance-Id = случайный alias

This commit is contained in:
Alexey Bodanyuk
2026-11-27 16:57:24 +03:00
parent 876f610847
commit 05df1695fe
16 changed files with 431 additions and 50 deletions
+8 -5
View File
@@ -1,14 +1,17 @@
#!/bin/sh
# Failover hook for `make test-failover ACTION_SCRIPT=scripts/stop-one.sh`.
# Stops exactly ONE API replica: the container whose X-Instance-Id (= container hostname,
# see src/messenger/config.py) is in TARGET_INSTANCE_ID. DB, Valkey, LB and volumes are
# not touched. The replica is LEFT STOPPED (`docker stop` = no restart by the policy);
# restore it explicitly afterwards: scripts/restore-api.sh.
# Stops exactly ONE API replica: the container whose X-Instance-Id is TARGET_INSTANCE_ID.
# Lab 7: X-Instance-Id is a random alias (no hostname/IP, src/messenger/config.py); each replica
# writes its alias to /tmp/instance_id inside its own container, which is how the operator maps
# alias -> container. DB, Valkey, LB, OpenBao and volumes are not touched. The replica is LEFT
# STOPPED (`docker stop` = no restart by the policy); restore it explicitly afterwards:
# scripts/restore-api.sh (make restore).
# STOP_MODE=stop (default) SIGTERM: readiness 503, 3 s drain, graceful exit (~4 s)
# STOP_MODE=kill SIGKILL at once (`docker stop -t 0`): crash of the process
# Returns within 10 s. The test hides the output; run by hand to see it (no secrets printed).
set -eu
cd "$(dirname "$0")/.."
export MSYS_NO_PATHCONV=1 # Git Bash: keep /tmp/instance_id a container path
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
case "$TARGET_INSTANCE_ID" in
*[!A-Za-z0-9._-]*) echo "stop-one: invalid TARGET_INSTANCE_ID" >&2; exit 2 ;;
@@ -18,7 +21,7 @@ mode="${STOP_MODE:-stop}"
target=""
# Only RUNNING containers of THIS compose project's service `api` are candidates.
for id in $(docker compose ps -q api); do
if [ "$(docker inspect -f '{{.Config.Hostname}}' "$id")" = "$TARGET_INSTANCE_ID" ]; then
if [ "$(docker exec "$id" cat /tmp/instance_id 2>/dev/null | tr -d '\r\n')" = "$TARGET_INSTANCE_ID" ]; then
target="$id"
fi
done