Check limits and isolation against a declared policy

scripts/limits.py states which secrets, volumes and networks each
service needs and that only lb publishes ports, on loopback. It
compares that policy with docker compose config (with the bench
profile, so k6 is covered) and with docker inspect of the running
containers: CPU and memory limits declared and applied, no
container_name, no published port on any API replica, a read-only
root filesystem for the API, and which networks are internal. It
prints both tables and every violation and exits non-zero on any.

The stack evidence script no longer reaches replicas through
docker compose exec or port, which assume container number 1 and
break after a rolling update renumbers the replicas.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Artyom
2026-10-28 19:52:09 +03:00
co-authored by Claude Opus 5.5
parent d5f8a7c25c
commit 5adb8719d4
2 changed files with 135 additions and 3 deletions
+3 -3
View File
@@ -12,8 +12,8 @@ header() { echo "date: $(date -u +%FT%TZ) commit: $(git rev-parse --short HEAD)
docker compose ps --format '{{.Service}} {{.Name}} {{.Status}} {{.Ports}}'
echo "\$ docker compose config | grep -c container_name"
docker compose config | grep -c container_name || true
echo "\$ docker compose port api 8080 # реплики не публикуют порт"
docker compose port api 8080 2>&1 || true
echo "\$ docker port <каждая реплика api> # реплики не публикуют порт"
for id in $(docker compose ps -q api); do echo "$(docker inspect -f '{{.Config.Hostname}}' "$id"): [$(docker port "$id")]"; done
echo "\$ docker inspect: hostname = X-Instance-Id, сети, лимиты CPU (nano) и памяти"
for id in $(docker compose ps -q); do
docker inspect -f '{{index .Config.Labels "com.docker.compose.service"}} {{.Config.Hostname}} {{.Name}} nets={{range $k, $v := .NetworkSettings.Networks}}{{$k}},{{end}} cpus={{.HostConfig.NanoCpus}} mem={{.HostConfig.Memory}} user={{.Config.User}} ro={{.HostConfig.ReadonlyRootfs}}' "$id"
@@ -33,7 +33,7 @@ for r in csv.DictReader(sys.stdin.read().lstrip("# ").splitlines()):
echo "compose: $(docker compose version --short)"
echo "images:"
grep -h -E 'image:|@sha256' compose.yaml Dockerfile | sed 's/^ */ /'
echo "python in image: $(docker compose exec -T api python -V)"
echo "python in image: $(docker exec "$(docker compose ps -q api | head -1)" python -V)"
echo "haproxy: $(docker compose exec -T lb haproxy -v | head -1)"
echo "packages (uv.lock):"
for name in fastapi uvicorn uvicorn-worker gunicorn asyncpg argon2-cffi pydantic pydantic-settings dishka structlog redis; do