forked from mtusi2026/mtusi2026lab4
963 lines
54 KiB
Plaintext
963 lines
54 KiB
Plaintext
# Сводка сбора доказательств lab4 (2026-11-14T15:48:22Z)
|
||
|
||
03 собственные -> evidence/03-student-checks.txt: 123 PASS, 0 FAIL, 0 команд с ошибкой
|
||
05 failover -> evidence/05-failover.txt: 2 из 2 раундов PASS, upload-stop: 2 из 2
|
||
10 S3 недоступен -> evidence/10-s3-down.txt: PASS: все проверки режима 's3-outage'
|
||
|
||
=================== evidence/00-clean-start.txt
|
||
# 00 чистый старт (2026-11-14T10:58:41Z)
|
||
$ docker compose down -v
|
||
Container mtusi-lab4-lb-1 Stopping
|
||
Container mtusi-lab4-lb-1 Stopped
|
||
Container mtusi-lab4-lb-1 Removing
|
||
Container mtusi-lab4-lb-1 Removed
|
||
Container mtusi-lab4-api-1 Stopping
|
||
Container mtusi-lab4-api-2 Stopping
|
||
Container mtusi-lab4-api-1 Stopped
|
||
Container mtusi-lab4-api-1 Removing
|
||
Container mtusi-lab4-api-1 Removed
|
||
Container mtusi-lab4-api-2 Stopped
|
||
Container mtusi-lab4-api-2 Removing
|
||
Container mtusi-lab4-api-2 Removed
|
||
Container mtusi-lab4-s3-init-1 Stopping
|
||
Container mtusi-lab4-migrate-1 Stopping
|
||
Container mtusi-lab4-s3-init-1 Stopped
|
||
Container mtusi-lab4-s3-init-1 Removing
|
||
Container mtusi-lab4-migrate-1 Stopped
|
||
Container mtusi-lab4-migrate-1 Removing
|
||
Container mtusi-lab4-s3-init-1 Removed
|
||
Container mtusi-lab4-s3-1 Stopping
|
||
Container mtusi-lab4-migrate-1 Removed
|
||
Container mtusi-lab4-postgres-1 Stopping
|
||
Container mtusi-lab4-postgres-1 Stopped
|
||
Container mtusi-lab4-postgres-1 Removing
|
||
Container mtusi-lab4-postgres-1 Removed
|
||
Container mtusi-lab4-s3-1 Stopped
|
||
Container mtusi-lab4-s3-1 Removing
|
||
Container mtusi-lab4-s3-1 Removed
|
||
Volume mtusi-lab4_s3data Removing
|
||
Volume mtusi-lab4_pgdata Removing
|
||
Network mtusi-lab4_default Removing
|
||
Volume mtusi-lab4_pgdata Removed
|
||
Volume mtusi-lab4_s3data Removed
|
||
Network mtusi-lab4_default Removed
|
||
$ sh scripts/setup-secrets.sh
|
||
secrets: ok (значения не печатаются)
|
||
secrets: ok (значения не печатаются)
|
||
$ docker compose up -d --build
|
||
Compose can now delegate builds to bake for better performance.
|
||
To do so, set COMPOSE_BAKE=true.
|
||
#0 building with "desktop-linux" instance using docker driver
|
||
|
||
#1 [s3-init internal] load build definition from Dockerfile
|
||
#1 transferring dockerfile: 535B done
|
||
#1 DONE 0.0s
|
||
|
||
#2 [migrate internal] load build definition from Dockerfile
|
||
#2 transferring dockerfile: 535B 0.0s done
|
||
#2 DONE 0.0s
|
||
|
||
#3 [migrate internal] load metadata for docker.io/library/python:3.12.7-slim-bookworm
|
||
#3 DONE 1.4s
|
||
|
||
#4 [migrate internal] load .dockerignore
|
||
#4 transferring context: 216B done
|
||
#4 DONE 0.0s
|
||
|
||
#5 [s3-init internal] load .dockerignore
|
||
#5 transferring context: 216B done
|
||
#5 DONE 0.0s
|
||
|
||
#6 [migrate 1/6] FROM docker.io/library/python:3.12.7-slim-bookworm@sha256:60d9996b6a8a3689d36db740b49f4327be3be09a21122bd02fb8895abb38b50d
|
||
#6 resolve docker.io/library/python:3.12.7-slim-bookworm@sha256:60d9996b6a8a3689d36db740b49f4327be3be09a21122bd02fb8895abb38b50d 0.0s done
|
||
#6 DONE 0.0s
|
||
|
||
#7 [s3-init internal] load build context
|
||
#7 transferring context: 53.68kB done
|
||
#7 DONE 0.0s
|
||
|
||
#8 [migrate internal] load build context
|
||
#8 transferring context: 53.68kB done
|
||
#8 DONE 0.0s
|
||
|
||
#9 [s3-init 2/6] WORKDIR /app
|
||
#9 CACHED
|
||
|
||
#10 [s3-init 3/6] COPY src/requirements.txt .
|
||
#10 CACHED
|
||
|
||
#11 [migrate 4/6] RUN pip install --no-cache-dir -r requirements.txt
|
||
#11 CACHED
|
||
|
||
#12 [s3-init 5/6] COPY src/ .
|
||
#12 DONE 0.0s
|
||
|
||
#13 [s3-init 6/6] RUN useradd -r -u 10001 appuser
|
||
#13 0.340 useradd warning: appuser's uid 10001 is greater than SYS_UID_MAX 999
|
||
#13 DONE 0.4s
|
||
|
||
#14 [s3-init] exporting to image
|
||
#14 exporting layers 0.1s done
|
||
#14 exporting manifest sha256:4ae2a791bbba577bcb815375108ea737a327a44f3cb92b050371582871ca77a1 0.0s done
|
||
#14 exporting config sha256:fd2ebb00c346e3417687248874a92ffcf783d91a1cc83d788d70d5bfea6d0544 0.0s done
|
||
#14 exporting attestation manifest sha256:ae0da9de98954a73ad89771c32e4f4d1a8a061ce5fa1a3624287d97b91a368c4
|
||
#14 exporting attestation manifest sha256:ae0da9de98954a73ad89771c32e4f4d1a8a061ce5fa1a3624287d97b91a368c4 0.1s done
|
||
#14 exporting manifest list sha256:e51688c9cb5dc910f9520e2eb97fefa0d9e1d284df053199f4a2fa3b6a0a8cb0 0.0s done
|
||
#14 naming to docker.io/library/mtusi-lab4-api:1
|
||
#14 naming to docker.io/library/mtusi-lab4-api:1 0.0s done
|
||
#14 unpacking to docker.io/library/mtusi-lab4-api:1 0.1s done
|
||
#14 DONE 0.4s
|
||
|
||
#15 [migrate] exporting to image
|
||
#15 exporting layers 0.1s done
|
||
#15 exporting manifest sha256:d4b8df4de55e399aa1f89ec53b8fd34515066d4e32a3d2da4584d541275b3230 0.0s done
|
||
#15 exporting config sha256:e859f5e9831d26a74f7f454640182463334862757cbb876e878ebc60464ae04d 0.0s done
|
||
#15 exporting attestation manifest sha256:9bdce302a45c5a9ba9bc835944c8aa6fc46f18c25817a5d63aa987840ca12387 0.1s done
|
||
#15 exporting manifest list sha256:76901d91a4007adbe41c8041eeabb616dd078be07048f3dbdef5f0f5fee4ff57 0.0s done
|
||
#15 naming to docker.io/library/mtusi-lab4-api:1 done
|
||
#15 unpacking to docker.io/library/mtusi-lab4-api:1 0.1s done
|
||
#15 DONE 0.5s
|
||
|
||
#16 [s3-init] resolving provenance for metadata file
|
||
#16 DONE 0.0s
|
||
|
||
#17 [migrate] resolving provenance for metadata file
|
||
#17 DONE 0.0s
|
||
|
||
#18 [api internal] load build definition from Dockerfile
|
||
#18 transferring dockerfile: 535B done
|
||
#18 DONE 0.0s
|
||
|
||
#3 [api internal] load metadata for docker.io/library/python:3.12.7-slim-bookworm
|
||
#3 DONE 1.7s
|
||
|
||
#19 [api internal] load .dockerignore
|
||
#19 transferring context: 216B done
|
||
#19 DONE 0.0s
|
||
|
||
#6 [api 1/6] FROM docker.io/library/python:3.12.7-slim-bookworm@sha256:60d9996b6a8a3689d36db740b49f4327be3be09a21122bd02fb8895abb38b50d
|
||
#6 resolve docker.io/library/python:3.12.7-slim-bookworm@sha256:60d9996b6a8a3689d36db740b49f4327be3be09a21122bd02fb8895abb38b50d 0.0s done
|
||
#6 DONE 0.1s
|
||
|
||
#20 [api internal] load build context
|
||
#20 transferring context: 538B done
|
||
#20 DONE 0.0s
|
||
|
||
#21 [api 3/6] COPY src/requirements.txt .
|
||
#21 CACHED
|
||
|
||
#22 [api 4/6] RUN pip install --no-cache-dir -r requirements.txt
|
||
#22 CACHED
|
||
|
||
#23 [api 5/6] COPY src/ .
|
||
#23 CACHED
|
||
|
||
#9 [api 2/6] WORKDIR /app
|
||
#9 CACHED
|
||
|
||
#24 [api 6/6] RUN useradd -r -u 10001 appuser
|
||
#24 CACHED
|
||
|
||
#25 [api] exporting to image
|
||
#25 exporting layers done
|
||
#25 exporting manifest sha256:e340936d2ef95177fc4964b2ae581b17640ba56d9c391e5c1a919f762e75c1de 0.0s done
|
||
#25 exporting config sha256:962e9fd67f6859d238fcc659d62158046c2b41e06ac7728888f37c8d1cb2888c
|
||
#25 exporting config sha256:962e9fd67f6859d238fcc659d62158046c2b41e06ac7728888f37c8d1cb2888c 0.0s done
|
||
#25 exporting attestation manifest sha256:b791b5198f6c076c00999275b27ec867bf9dad754f65c4f53cbbe5e4ee3bf72c 0.0s done
|
||
#25 exporting manifest list sha256:2cc1a39bf9a24bc4274e218d769668dfff377fe32863850f110697231fbebbc3 0.0s done
|
||
#25 naming to docker.io/library/mtusi-lab4-api:1 done
|
||
#25 unpacking to docker.io/library/mtusi-lab4-api:1 0.0s done
|
||
#25 DONE 0.1s
|
||
|
||
#26 [api] resolving provenance for metadata file
|
||
#26 DONE 0.0s
|
||
api Built
|
||
migrate Built
|
||
s3-init Built
|
||
Network mtusi-lab4_default Creating
|
||
Network mtusi-lab4_default Created
|
||
Volume "mtusi-lab4_pgdata" Creating
|
||
Volume "mtusi-lab4_pgdata" Created
|
||
Volume "mtusi-lab4_s3data" Creating
|
||
Volume "mtusi-lab4_s3data" Created
|
||
Container mtusi-lab4-postgres-1 Creating
|
||
Container mtusi-lab4-s3-1 Creating
|
||
Container mtusi-lab4-s3-1 Created
|
||
Container mtusi-lab4-s3-init-1 Creating
|
||
Container mtusi-lab4-postgres-1 Created
|
||
Container mtusi-lab4-migrate-1 Creating
|
||
Container mtusi-lab4-s3-init-1 Created
|
||
Container mtusi-lab4-migrate-1 Created
|
||
Container mtusi-lab4-api-2 Creating
|
||
Container mtusi-lab4-api-1 Creating
|
||
Container mtusi-lab4-api-2 Created
|
||
Container mtusi-lab4-api-1 Created
|
||
Container mtusi-lab4-lb-1 Creating
|
||
Container mtusi-lab4-lb-1 Created
|
||
Container mtusi-lab4-s3-1 Starting
|
||
Container mtusi-lab4-postgres-1 Starting
|
||
Container mtusi-lab4-postgres-1 Started
|
||
Container mtusi-lab4-postgres-1 Waiting
|
||
Container mtusi-lab4-s3-1 Started
|
||
Container mtusi-lab4-s3-1 Waiting
|
||
Container mtusi-lab4-postgres-1 Healthy
|
||
Container mtusi-lab4-migrate-1 Starting
|
||
Container mtusi-lab4-migrate-1 Started
|
||
Container mtusi-lab4-s3-1 Healthy
|
||
Container mtusi-lab4-s3-init-1 Starting
|
||
Container mtusi-lab4-s3-init-1 Started
|
||
Container mtusi-lab4-s3-init-1 Waiting
|
||
Container mtusi-lab4-postgres-1 Waiting
|
||
Container mtusi-lab4-migrate-1 Waiting
|
||
Container mtusi-lab4-migrate-1 Exited
|
||
Container mtusi-lab4-postgres-1 Healthy
|
||
Container mtusi-lab4-s3-init-1 Exited
|
||
Container mtusi-lab4-api-1 Starting
|
||
Container mtusi-lab4-api-1 Started
|
||
Container mtusi-lab4-api-2 Starting
|
||
Container mtusi-lab4-api-2 Started
|
||
Container mtusi-lab4-api-1 Waiting
|
||
Container mtusi-lab4-api-2 Waiting
|
||
Container mtusi-lab4-api-1 Healthy
|
||
Container mtusi-lab4-api-2 Healthy
|
||
Container mtusi-lab4-lb-1 Starting
|
||
Container mtusi-lab4-lb-1 Started
|
||
ready через 19 с после запуска up
|
||
|
||
=================== evidence/01-env.txt
|
||
# 01 окружение (2026-11-14T10:59:26Z)
|
||
commit: ec540a1a725862a8619fcb758daec4ad197f0dd5
|
||
git status:
|
||
M REPORT.md
|
||
A scripts/collect-evidence.sh
|
||
A scripts/restart.sh
|
||
A scripts/setup-secrets.sh
|
||
A scripts/stop-one.sh
|
||
?? .gitattributes
|
||
?? Dockerfile
|
||
?? compose.yaml
|
||
?? evidence/00-clean-start.txt
|
||
?? evidence/01-env.txt
|
||
?? evidence/02-smoke.txt
|
||
?? evidence/03-student-checks.txt
|
||
?? evidence/04-load-balancing.txt
|
||
?? evidence/05-failover.txt
|
||
?? evidence/06-persistence.txt
|
||
?? evidence/07-db-migrations.txt
|
||
?? evidence/08-s3-storage.txt
|
||
?? evidence/09-db-down.txt
|
||
?? evidence/10-s3-down.txt
|
||
?? evidence/11-lb-config.txt
|
||
$ docker version
|
||
client=28.0.4 server=28.0.4 os=linux/amd64
|
||
$ docker compose version
|
||
Docker Compose version v2.34.0-desktop.1
|
||
python: Python 3.11.5
|
||
$ docker compose config --quiet
|
||
compose config: OK
|
||
$ docker compose images
|
||
CONTAINER REPOSITORY TAG IMAGE ID SIZE
|
||
mtusi-lab4-api-1 mtusi-lab4-api 1 2cc1a39bf9a2 66.9MB
|
||
mtusi-lab4-api-2 mtusi-lab4-api 1 2cc1a39bf9a2 66.9MB
|
||
mtusi-lab4-lb-1 haproxy 2.8.10-alpine 54af6e4943e4 12.2MB
|
||
mtusi-lab4-migrate-1 mtusi-lab4-api 1 2cc1a39bf9a2 66.9MB
|
||
mtusi-lab4-postgres-1 postgres 16.4-alpine 5660c2cbfea5 99.2MB
|
||
mtusi-lab4-s3-1 chrislusf/seaweedfs 4.42 f7cbc8bdbbf6 106MB
|
||
mtusi-lab4-s3-init-1 mtusi-lab4-api 1 2cc1a39bf9a2 66.9MB
|
||
$ docker compose ps -a
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab4-api-1 mtusi-lab4-api:1 "uvicorn app.main:ap…" api 17 seconds ago Up 9 seconds (healthy) 8080/tcp
|
||
mtusi-lab4-api-2 mtusi-lab4-api:1 "uvicorn app.main:ap…" api 17 seconds ago Up 8 seconds (healthy) 8080/tcp
|
||
mtusi-lab4-lb-1 haproxy:2.8.10-alpine "docker-entrypoint.s…" lb 17 seconds ago Up 3 seconds (health: starting) 127.0.0.1:8080->8080/tcp
|
||
mtusi-lab4-migrate-1 mtusi-lab4-api:1 "python -m app.migra…" migrate 18 seconds ago Exited (0) 12 seconds ago
|
||
mtusi-lab4-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres 18 seconds ago Up 17 seconds (healthy) 5432/tcp
|
||
mtusi-lab4-s3-1 chrislusf/seaweedfs:4.42 "weed server -dir=/d…" s3 18 seconds ago Up 17 seconds (healthy) 7333/tcp, 8080/tcp, 8333/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp
|
||
mtusi-lab4-s3-init-1 mtusi-lab4-api:1 "python -m app.s3init" s3-init 18 seconds ago Exited (0) 9 seconds ago
|
||
$ docker volume ls (pgdata)
|
||
local mtusi2026lab2_pgdata
|
||
local mtusi-lab3_pgdata
|
||
local mtusi-lab4_pgdata
|
||
$ docker stats --no-stream
|
||
NAME CPU % MEM USAGE / LIMIT
|
||
mtusi-lab4-api-1 0.55% 39.4MiB / 7.694GiB
|
||
mtusi-lab4-api-2 0.43% 39.11MiB / 7.694GiB
|
||
mtusi-lab4-lb-1 0.57% 12.05MiB / 7.694GiB
|
||
mtusi-lab4-postgres-1 0.45% 46.62MiB / 7.694GiB
|
||
mtusi-lab4-s3-1 0.19% 46.34MiB / 7.694GiB
|
||
$ docker info (лимиты хоста)
|
||
CPUs=16 Mem=8261029888
|
||
|
||
=================== evidence/02-smoke.txt
|
||
# 02 публичные проверки через LB (2026-11-14T10:59:31Z)
|
||
$ python scripts/check_contract.py
|
||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||
exit code: 0
|
||
$ python tests/smoke.py --base-url http://localhost:8080
|
||
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
|
||
exit code: 0
|
||
|
||
=================== evidence/03-student-checks.txt
|
||
# 03 собственные проверки (2026-11-14T15:45:54Z)
|
||
$ python student-tests/lab3_checks.py --base-url http://localhost:8080
|
||
PASS: повторный username -> 409
|
||
PASS: пароль короче 12 -> 400
|
||
PASS: лишнее поле -> 400
|
||
PASS: User не содержит пароль/hash/токен
|
||
PASS: гонка одинакового username: ровно один 201, остальные 409
|
||
PASS: неверный пароль и неизвестный пользователь неразличимы (401, тот же code/message/заголовок)
|
||
PASS: вход JSON-телом без Basic -> 401
|
||
PASS: Bearer на POST /auth/sessions -> 401
|
||
PASS: токен >=256 бит, token_type Bearer
|
||
PASS: Basic на бизнес-endpoint -> 401 + WWW-Authenticate: Bearer
|
||
PASS: один X-User-Id доступа не даёт
|
||
PASS: X-User-Id игнорируется: владелец определяется токеном
|
||
PASS: неизвестный токен -> 401
|
||
PASS: X-Request-Id совпадает с request_id в теле ошибки
|
||
PASS: чат с неизвестным участником -> 400
|
||
PASS: после отказа новый чат не появился (нет частичной записи)
|
||
PASS: чат создан с обоими участниками
|
||
PASS: создатель обязан быть среди member_ids -> 400
|
||
PASS: посторонний: GET /chat -> 404
|
||
PASS: посторонний: GET /messages -> 404
|
||
PASS: посторонний не может писать -> 404
|
||
PASS: неверный UUID /chats/not-a-uuid -> 400
|
||
PASS: неверный UUID /chats/not-a-uuid/messages -> 400
|
||
PASS: sender_id в запросе не принимается -> 400
|
||
PASS: пробельный текст -> 400
|
||
PASS: отправитель берётся из токена
|
||
PASS: пагинация limit=2: без повторов, все 6 сообщений
|
||
PASS: cursor от другого чата -> 400
|
||
PASS: ?limit=0 -> 400
|
||
PASS: ?limit=101 -> 400
|
||
PASS: ?limit=abc -> 400
|
||
PASS: ?limit=%2B5 -> 400
|
||
PASS: ?limit=2&limit=3 -> 400
|
||
PASS: тело >1 MiB -> 413
|
||
PASS: не JSON Content-Type -> 415
|
||
PASS: битый JSON -> 400
|
||
PASS: logout -> 204
|
||
PASS: повторный logout с отозванным токеном -> 401
|
||
PASS: отозванный токен -> 401 + WWW-Authenticate: Bearer
|
||
PASS: logout одного пользователя не затрагивает чужие сессии
|
||
PASS: все проверки режима 'main'
|
||
exit code: 0
|
||
$ python student-tests/lab3_checks.py --base-url http://localhost:8080 --mode idem --min-instances 2
|
||
PASS: через LB отвечают >= 2 реплик с одним токеном (X-Instance-Id: 2)
|
||
PASS: повтор с тем же ключом: тот же 201 и то же сообщение
|
||
PASS: повтор не создал дубль
|
||
PASS: тот же ключ с другим телом -> 409
|
||
PASS: тот же ключ и то же тело (другое форматирование JSON) -> тот же результат
|
||
PASS: тот же ключ в другом чате независим
|
||
PASS: тот же ключ у другого пользователя независим
|
||
PASS: нет Idempotency-Key -> 400
|
||
PASS: неверный ключ 'bad key!' -> 400
|
||
PASS: неверный ключ 'a/b' -> 400
|
||
PASS: неверный ключ 'aaaaaaaaaaaa' -> 400
|
||
PASS: неверный ключ '' -> 400
|
||
PASS: посторонний с тем же ключом -> 404 (доступ проверяется при повторе)
|
||
PASS: без токена -> 401
|
||
PASS: 30 параллельных запросов с одним ключом: все 201 и одно и то же сообщение
|
||
PASS: в истории ровно одно такое сообщение
|
||
INFO: параллельные повторы обслужили реплики: ['2c12200fa922', '45517da31576']
|
||
PASS: параллельно один ключ и два разных тела: победитель один, остальным другого тела -> 409
|
||
PASS: создано ровно одно сообщение из конкурирующих
|
||
PASS: повтор с отозванным токеном -> 401
|
||
PASS: все проверки режима 'idem'
|
||
exit code: 0
|
||
$ python student-tests/lab4_checks.py --base-url http://localhost:8080 (вложения: форматы, лимиты, права, сообщения)
|
||
PASS: загрузка PNG -> 201, status ready, ожидаемые поля
|
||
PASS: в ответе есть X-Instance-Id и X-Request-Id
|
||
PASS: загрузка JPEG -> 201 и верный sha256
|
||
PASS: созданный PNG другого размера -> 201
|
||
PASS: метаданные доступны другому участнику чата
|
||
PASS: скачивание: байты совпадают, Content-Type верный, nosniff
|
||
PASS: Content-Length равен размеру
|
||
PASS: метаданные постороннему -> 404
|
||
PASS: содержимое постороннему -> 404
|
||
PASS: без токена -> 401
|
||
PASS: неверный UUID -> 400
|
||
PASS: неизвестный UUID -> 404
|
||
PASS: загрузка в чужой чат -> 404
|
||
PASS: загрузка без токена -> 401
|
||
PASS: загрузка в неверный UUID чата -> 400
|
||
PASS: ?variant=thumbnail (вариантов нет) -> 404
|
||
PASS: ?variant=bogus -> 400
|
||
PASS: ?variant=original -> 200
|
||
PASS: filename: слэш -> 400
|
||
PASS: filename: обратный слэш -> 400
|
||
PASS: filename: NUL -> 400
|
||
PASS: filename: перевод строки -> 400
|
||
PASS: filename: пустое -> 400
|
||
PASS: filename: пробелы -> 400
|
||
PASS: filename: 256 символов -> 400
|
||
PASS: filename не указан -> 400
|
||
PASS: filename из 255 символов -> 201
|
||
PASS: имя «../..» без разделителей принимается и не влияет на ключ объекта
|
||
PASS: Content-Type text/plain -> 415
|
||
PASS: Content-Type image/gif -> 415
|
||
PASS: PNG под видом image/jpeg -> 415
|
||
PASS: текст под видом image/png -> 415
|
||
PASS: пустое тело -> 415
|
||
PASS: PNG с повреждённым блоком (CRC) -> 415
|
||
PASS: усечённый PNG -> 415
|
||
PASS: PNG с мусором в конце -> 415
|
||
PASS: усечённый JPEG -> 415
|
||
PASS: JPEG под видом image/png -> 415
|
||
PASS: ровно 40 000 000 пикселей (8000x5000) -> 201
|
||
PASS: 40 005 000 пикселей (8001x5000) -> 413
|
||
PASS: «бомба» 20000x20000 малого размера -> 413
|
||
PASS: тело 10 MiB + 1 байт -> 413
|
||
PASS: сообщение только с вложением (text='') -> 201 с attachment_ids
|
||
PASS: attachment_ids=[] даёт обычное сообщение с пустым массивом
|
||
PASS: без attachment_ids в ответе всё равно attachment_ids=[]
|
||
PASS: пустой текст без вложений -> 400
|
||
PASS: пробельный текст без вложений -> 400
|
||
PASS: пробельный текст с вложением допустим -> 201
|
||
PASS: неизвестное вложение -> 404
|
||
PASS: attachment_ids не массив -> 400
|
||
PASS: attachment_ids с неверным UUID -> 400
|
||
PASS: повтор одного id в attachment_ids -> 400
|
||
PASS: 11 вложений в сообщении -> 400
|
||
PASS: 10 вложений -> 201 с сохранением порядка
|
||
PASS: вложение другого чата в сообщении -> 404
|
||
PASS: участник может сослаться на вложение другого участника
|
||
PASS: повтор с вложением и тем же ключом: тот же результат
|
||
PASS: тот же ключ с другим набором вложений -> 409
|
||
PASS: тот же ключ без вложений (иное тело) -> 409
|
||
PASS: в истории одно такое сообщение, attachment_ids присутствует у каждого сообщения
|
||
PASS: вложение из истории скачивается вторым участником
|
||
PASS: все проверки режима 'attach'
|
||
exit code: 0
|
||
|
||
=================== evidence/04-load-balancing.txt
|
||
# 04 балансировка: одна сессия, разные реплики (2026-11-14T10:59:37Z)
|
||
$ docker compose ps api (реплики одного сервиса, без container_name)
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab4-api-1 mtusi-lab4-api:1 "uvicorn app.main:ap…" api 27 seconds ago Up 19 seconds (healthy) 8080/tcp
|
||
mtusi-lab4-api-2 mtusi-lab4-api:1 "uvicorn app.main:ap…" api 27 seconds ago Up 18 seconds (healthy) 8080/tcp
|
||
--- ID работающих API-контейнеров (X-Instance-Id = hostname = короткий ID контейнера)
|
||
2c12200fa922
|
||
45517da31576
|
||
--- порты API-контейнеров наружу (должно быть пусто: вход только через LB)
|
||
container 2c12200fa922:
|
||
container 45517da31576:
|
||
--- порты LB
|
||
127.0.0.1:8080
|
||
--- 40 запросов с ОДНИМ токеном к GET /users/me через LB: число ответов на каждую реплику
|
||
20 X-Instance-Id=2c12200fa922
|
||
20 X-Instance-Id=45517da31576
|
||
реплик увидено: 2 | токен не печатается, повторный вход не выполнялся
|
||
|
||
=================== evidence/05-failover.txt
|
||
# 05 отказ API-реплики: последовательно каждая из двух (2026-11-14T15:46:00Z)
|
||
hook: scripts/stop-one.cmd
|
||
|
||
=== раунд 1 ===
|
||
--- до
|
||
2c12200fa922 mtusi-lab4-api-1 Up 5 hours (healthy)
|
||
45517da31576 mtusi-lab4-api-2 Up 5 hours (healthy)
|
||
$ python tests/resilience.py --mode failover --action-script scripts/stop-one.cmd
|
||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||
{"observed_instances_before": 2, "successful_writes": 118, "failed_attempts": 1, "first_recovery_seconds": 1.75}
|
||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||
exit code: 0
|
||
--- после (ровно одна реплика должна быть Exited; остальные Up)
|
||
2c12200fa922 mtusi-lab4-api-1 Up 5 hours (healthy)
|
||
45517da31576 mtusi-lab4-api-2 Exited (0) 14 seconds ago
|
||
--- LB сейчас: ответы по репликам (остановленной быть не должно)
|
||
20 x-instance-id: 2c12200fa922
|
||
--- восстановление: docker compose start api
|
||
Container mtusi-lab4-postgres-1 Waiting
|
||
Container mtusi-lab4-s3-1 Waiting
|
||
Container mtusi-lab4-postgres-1 Healthy
|
||
Container mtusi-lab4-migrate-1 Starting
|
||
Container mtusi-lab4-s3-1 Healthy
|
||
Container mtusi-lab4-s3-init-1 Starting
|
||
Container mtusi-lab4-migrate-1 Started
|
||
Container mtusi-lab4-s3-init-1 Started
|
||
Container mtusi-lab4-postgres-1 Waiting
|
||
Container mtusi-lab4-migrate-1 Waiting
|
||
Container mtusi-lab4-s3-init-1 Waiting
|
||
Container mtusi-lab4-postgres-1 Healthy
|
||
Container mtusi-lab4-migrate-1 Exited
|
||
Container mtusi-lab4-s3-init-1 Exited
|
||
Container mtusi-lab4-api-2 Starting
|
||
Container mtusi-lab4-api-2 Started
|
||
обе реплики снова видны через LB через 5 с
|
||
2c12200fa922 mtusi-lab4-api-1 Up 5 hours (healthy)
|
||
45517da31576 mtusi-lab4-api-2 Up 5 seconds (health: starting)
|
||
|
||
=== раунд 2 ===
|
||
--- до
|
||
2c12200fa922 mtusi-lab4-api-1 Up 5 hours (healthy)
|
||
45517da31576 mtusi-lab4-api-2 Up 5 seconds (healthy)
|
||
$ python tests/resilience.py --mode failover --action-script scripts/stop-one.cmd
|
||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||
{"observed_instances_before": 2, "successful_writes": 112, "failed_attempts": 1, "first_recovery_seconds": 1.734}
|
||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||
exit code: 0
|
||
--- после (ровно одна реплика должна быть Exited; остальные Up)
|
||
2c12200fa922 mtusi-lab4-api-1 Up 5 hours (healthy)
|
||
45517da31576 mtusi-lab4-api-2 Exited (0) 14 seconds ago
|
||
--- LB сейчас: ответы по репликам (остановленной быть не должно)
|
||
20 x-instance-id: 2c12200fa922
|
||
--- восстановление: docker compose start api
|
||
Container mtusi-lab4-s3-1 Waiting
|
||
Container mtusi-lab4-postgres-1 Waiting
|
||
Container mtusi-lab4-s3-1 Healthy
|
||
Container mtusi-lab4-s3-init-1 Starting
|
||
Container mtusi-lab4-postgres-1 Healthy
|
||
Container mtusi-lab4-migrate-1 Starting
|
||
Container mtusi-lab4-s3-init-1 Started
|
||
Container mtusi-lab4-migrate-1 Started
|
||
Container mtusi-lab4-postgres-1 Waiting
|
||
Container mtusi-lab4-migrate-1 Waiting
|
||
Container mtusi-lab4-s3-init-1 Waiting
|
||
Container mtusi-lab4-postgres-1 Healthy
|
||
Container mtusi-lab4-migrate-1 Exited
|
||
Container mtusi-lab4-s3-init-1 Exited
|
||
Container mtusi-lab4-api-2 Starting
|
||
Container mtusi-lab4-api-2 Started
|
||
обе реплики снова видны через LB через 3 с
|
||
2c12200fa922 mtusi-lab4-api-1 Up 5 hours (healthy)
|
||
45517da31576 mtusi-lab4-api-2 Up 3 seconds (health: starting)
|
||
|
||
=== вложение + остановка принявшей реплики, раунд 1 (--target-index 0: останавливается другая реплика) ===
|
||
$ python student-tests/lab4_checks.py --mode upload-stop --stop-hook scripts/stop-one.cmd --target-index 0
|
||
PASS: через LB видны >= 2 реплик
|
||
PASS: файл принят выбранной репликой 2c12200fa922
|
||
PASS: hook остановил реплику 2c12200fa922 (код 0, 1.4 с)
|
||
PASS: после остановки реплики вложение скачивается через другую реплику (байты те же)
|
||
INFO: вложение снова доступно через 2.31 с после запуска hook (реплика ['45517da31576'])
|
||
PASS: подтверждённое сообщение с вложением доступно
|
||
PASS: остановленная реплика больше не отвечает
|
||
PASS: все проверки режима 'upload-stop'
|
||
exit code: 0
|
||
--- после
|
||
2c12200fa922 mtusi-lab4-api-1 Exited (0) 2 seconds ago
|
||
45517da31576 mtusi-lab4-api-2 Up 7 seconds (healthy)
|
||
--- восстановление: docker compose start api
|
||
Container mtusi-lab4-postgres-1 Waiting
|
||
Container mtusi-lab4-s3-1 Waiting
|
||
Container mtusi-lab4-postgres-1 Healthy
|
||
Container mtusi-lab4-migrate-1 Starting
|
||
Container mtusi-lab4-s3-1 Healthy
|
||
Container mtusi-lab4-s3-init-1 Starting
|
||
Container mtusi-lab4-migrate-1 Started
|
||
Container mtusi-lab4-s3-init-1 Started
|
||
Container mtusi-lab4-postgres-1 Waiting
|
||
Container mtusi-lab4-migrate-1 Waiting
|
||
Container mtusi-lab4-s3-init-1 Waiting
|
||
Container mtusi-lab4-postgres-1 Healthy
|
||
Container mtusi-lab4-migrate-1 Exited
|
||
Container mtusi-lab4-s3-init-1 Exited
|
||
Container mtusi-lab4-api-1 Starting
|
||
Container mtusi-lab4-api-1 Started
|
||
обе реплики снова видны через LB через 5 с
|
||
|
||
=== вложение + остановка принявшей реплики, раунд 2 (--target-index 1: останавливается другая реплика) ===
|
||
$ python student-tests/lab4_checks.py --mode upload-stop --stop-hook scripts/stop-one.cmd --target-index 1
|
||
PASS: через LB видны >= 2 реплик
|
||
PASS: файл принят выбранной репликой 45517da31576
|
||
PASS: hook остановил реплику 45517da31576 (код 0, 0.9 с)
|
||
PASS: после остановки реплики вложение скачивается через другую реплику (байты те же)
|
||
INFO: вложение снова доступно через 1.29 с после запуска hook (реплика ['2c12200fa922'])
|
||
PASS: подтверждённое сообщение с вложением доступно
|
||
PASS: остановленная реплика больше не отвечает
|
||
PASS: все проверки режима 'upload-stop'
|
||
exit code: 0
|
||
--- после
|
||
2c12200fa922 mtusi-lab4-api-1 Up 7 seconds (healthy)
|
||
45517da31576 mtusi-lab4-api-2 Exited (0) 1 second ago
|
||
--- восстановление: docker compose start api
|
||
Container mtusi-lab4-postgres-1 Waiting
|
||
Container mtusi-lab4-s3-1 Waiting
|
||
Container mtusi-lab4-s3-1 Healthy
|
||
Container mtusi-lab4-s3-init-1 Starting
|
||
Container mtusi-lab4-postgres-1 Healthy
|
||
Container mtusi-lab4-migrate-1 Starting
|
||
Container mtusi-lab4-migrate-1 Started
|
||
Container mtusi-lab4-s3-init-1 Started
|
||
Container mtusi-lab4-s3-init-1 Waiting
|
||
Container mtusi-lab4-postgres-1 Waiting
|
||
Container mtusi-lab4-migrate-1 Waiting
|
||
Container mtusi-lab4-postgres-1 Healthy
|
||
Container mtusi-lab4-migrate-1 Exited
|
||
Container mtusi-lab4-s3-init-1 Exited
|
||
Container mtusi-lab4-api-2 Starting
|
||
Container mtusi-lab4-api-2 Started
|
||
обе реплики снова видны через LB через 3 с
|
||
|
||
=================== evidence/06-persistence.txt
|
||
# 06 сохранность при рестарте всего стенда (PostgreSQL, S3, API, LB) (2026-11-14T11:00:44Z)
|
||
--- до
|
||
/mtusi-lab4-api-1 StartedAt=2026-11-14T11:00:41.418189002Z RestartCount=0
|
||
/mtusi-lab4-api-2 StartedAt=2026-11-14T10:59:18.845998391Z RestartCount=0
|
||
/mtusi-lab4-lb-1 StartedAt=2026-11-14T10:59:24.60449319Z RestartCount=0
|
||
/mtusi-lab4-postgres-1 StartedAt=2026-11-14T10:59:10.646170885Z RestartCount=0
|
||
/mtusi-lab4-s3-1 StartedAt=2026-11-14T10:59:10.657148631Z RestartCount=0
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab4-api-1 mtusi-lab4-api:1 "uvicorn app.main:ap…" api About a minute ago Up 4 seconds (health: starting) 8080/tcp
|
||
mtusi-lab4-api-2 mtusi-lab4-api:1 "uvicorn app.main:ap…" api About a minute ago Up About a minute (healthy) 8080/tcp
|
||
mtusi-lab4-lb-1 haproxy:2.8.10-alpine "docker-entrypoint.s…" lb About a minute ago Up About a minute (healthy) 127.0.0.1:8080->8080/tcp
|
||
mtusi-lab4-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres About a minute ago Up About a minute (healthy) 5432/tcp
|
||
mtusi-lab4-s3-1 chrislusf/seaweedfs:4.42 "weed server -dir=/d…" s3 About a minute ago Up About a minute (healthy) 7333/tcp, 8080/tcp, 8333/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp
|
||
объектов в S3 до рестарта: 5
|
||
$ python tests/resilience.py --mode persistence --action-script scripts/restart.cmd
|
||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||
exit code: 0
|
||
--- после (StartedAt должен измениться у postgres, api и lb)
|
||
/mtusi-lab4-api-1 StartedAt=2026-11-14T11:01:28.768539654Z RestartCount=0
|
||
/mtusi-lab4-api-2 StartedAt=2026-11-14T11:01:28.927527738Z RestartCount=0
|
||
/mtusi-lab4-lb-1 StartedAt=2026-11-14T11:01:29.197680185Z RestartCount=0
|
||
/mtusi-lab4-postgres-1 StartedAt=2026-11-14T11:00:49.753628396Z RestartCount=0
|
||
/mtusi-lab4-s3-1 StartedAt=2026-11-14T11:01:09.731773197Z RestartCount=0
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab4-api-1 mtusi-lab4-api:1 "uvicorn app.main:ap…" api 2 minutes ago Up 6 seconds (healthy) 8080/tcp
|
||
mtusi-lab4-api-2 mtusi-lab4-api:1 "uvicorn app.main:ap…" api 2 minutes ago Up 6 seconds (healthy) 8080/tcp
|
||
mtusi-lab4-lb-1 haproxy:2.8.10-alpine "docker-entrypoint.s…" lb 2 minutes ago Up 6 seconds (healthy) 127.0.0.1:8080->8080/tcp
|
||
mtusi-lab4-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres 2 minutes ago Up 45 seconds (healthy) 5432/tcp
|
||
mtusi-lab4-s3-1 chrislusf/seaweedfs:4.42 "weed server -dir=/d…" s3 2 minutes ago Up 25 seconds (healthy) 7333/tcp, 8080/tcp, 8333/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp
|
||
--- время восстановления одного рестарта (hook + ожидание /health/ready и 2 реплик)
|
||
Container mtusi-lab4-postgres-1 Restarting
|
||
Container mtusi-lab4-s3-1 Restarting
|
||
Container mtusi-lab4-postgres-1 Started
|
||
Container mtusi-lab4-s3-1 Started
|
||
Container mtusi-lab4-api-2 Restarting
|
||
Container mtusi-lab4-api-1 Restarting
|
||
Container mtusi-lab4-lb-1 Restarting
|
||
Container mtusi-lab4-api-2 Started
|
||
Container mtusi-lab4-lb-1 Started
|
||
Container mtusi-lab4-api-1 Started
|
||
Container mtusi-lab4-s3-1 Running
|
||
Container mtusi-lab4-postgres-1 Running
|
||
Container mtusi-lab4-s3-init-1 Created
|
||
Container mtusi-lab4-migrate-1 Created
|
||
Container mtusi-lab4-api-1 Running
|
||
Container mtusi-lab4-api-2 Running
|
||
Container mtusi-lab4-lb-1 Running
|
||
Container mtusi-lab4-s3-1 Waiting
|
||
Container mtusi-lab4-postgres-1 Waiting
|
||
Container mtusi-lab4-s3-1 Healthy
|
||
Container mtusi-lab4-s3-init-1 Starting
|
||
Container mtusi-lab4-postgres-1 Healthy
|
||
Container mtusi-lab4-migrate-1 Starting
|
||
Container mtusi-lab4-s3-init-1 Started
|
||
Container mtusi-lab4-migrate-1 Started
|
||
Container mtusi-lab4-postgres-1 Waiting
|
||
Container mtusi-lab4-migrate-1 Waiting
|
||
Container mtusi-lab4-s3-init-1 Waiting
|
||
Container mtusi-lab4-postgres-1 Healthy
|
||
Container mtusi-lab4-migrate-1 Exited
|
||
Container mtusi-lab4-s3-init-1 Exited
|
||
Container mtusi-lab4-api-1 Waiting
|
||
Container mtusi-lab4-api-2 Waiting
|
||
Container mtusi-lab4-api-1 Healthy
|
||
Container mtusi-lab4-api-2 Healthy
|
||
готов через 54 с
|
||
объектов в S3 после рестарта: 6
|
||
--- данные в БД после рестарта
|
||
users | chats | messages | sessions | idempotency_keys | attachments
|
||
-------+-------+----------+----------+------------------+-------------
|
||
26 | 12 | 247 | 26 | 247 | 6
|
||
(1 row)
|
||
|
||
|
||
=================== evidence/07-db-migrations.txt
|
||
# 07 схема БД и миграции (2026-11-14T11:02:32Z)
|
||
version | applied_at
|
||
---------------------+-------------------------------
|
||
001_init.sql | 2026-11-14 10:59:15.430991+00
|
||
002_idempotency.sql | 2026-11-14 10:59:15.491662+00
|
||
003_attachments.sql | 2026-11-14 10:59:15.505907+00
|
||
(3 rows)
|
||
|
||
List of relations
|
||
Schema | Name | Type | Owner
|
||
--------+---------------------+-------+-------
|
||
public | attachments | table | msg
|
||
public | chat_members | table | msg
|
||
public | chats | table | msg
|
||
public | idempotency_keys | table | msg
|
||
public | message_attachments | table | msg
|
||
public | messages | table | msg
|
||
public | schema_migrations | table | msg
|
||
public | sessions | table | msg
|
||
public | users | table | msg
|
||
(9 rows)
|
||
|
||
Table "public.attachments"
|
||
Column | Type | Collation | Nullable | Default
|
||
--------------+--------------------------+-----------+----------+-------------------
|
||
id | uuid | | not null |
|
||
chat_id | uuid | | not null |
|
||
owner_id | uuid | | not null |
|
||
filename | text | | not null |
|
||
content_type | text | | not null |
|
||
size_bytes | bigint | | not null |
|
||
sha256 | text | | not null |
|
||
width | integer | | not null |
|
||
height | integer | | not null |
|
||
object_key | text | | not null |
|
||
status | text | | not null | 'uploading'::text
|
||
created_at | timestamp with time zone | | not null | now()
|
||
updated_at | timestamp with time zone | | not null | now()
|
||
Indexes:
|
||
"attachments_pkey" PRIMARY KEY, btree (id)
|
||
"attachments_chat_idx" btree (chat_id, created_at)
|
||
"attachments_object_key_key" UNIQUE CONSTRAINT, btree (object_key)
|
||
"attachments_pending_idx" btree (created_at) WHERE status = 'uploading'::text
|
||
Check constraints:
|
||
"attachments_content_type_check" CHECK (content_type = ANY (ARRAY['image/png'::text, 'image/jpeg'::text]))
|
||
"attachments_filename_check" CHECK (char_length(filename) >= 1 AND char_length(filename) <= 255)
|
||
"attachments_height_check" CHECK (height > 0)
|
||
"attachments_sha256_check" CHECK (sha256 ~ '^[a-f0-9]{64}$'::text)
|
||
"attachments_size_bytes_check" CHECK (size_bytes >= 1 AND size_bytes <= 10485760)
|
||
"attachments_status_check" CHECK (status = ANY (ARRAY['uploading'::text, 'ready'::text]))
|
||
"attachments_width_check" CHECK (width > 0)
|
||
Foreign-key constraints:
|
||
"attachments_chat_id_fkey" FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE
|
||
"attachments_owner_id_fkey" FOREIGN KEY (owner_id) REFERENCES users(id)
|
||
Referenced by:
|
||
TABLE "message_attachments" CONSTRAINT "message_attachments_attachment_id_fkey" FOREIGN KEY (attachment_id) REFERENCES attachments(id)
|
||
|
||
Table "public.message_attachments"
|
||
Column | Type | Collation | Nullable | Default
|
||
---------------+---------+-----------+----------+---------
|
||
message_id | uuid | | not null |
|
||
attachment_id | uuid | | not null |
|
||
position | integer | | not null |
|
||
Indexes:
|
||
"message_attachments_pkey" PRIMARY KEY, btree (message_id, attachment_id)
|
||
"message_attachments_att_idx" btree (attachment_id)
|
||
Foreign-key constraints:
|
||
"message_attachments_attachment_id_fkey" FOREIGN KEY (attachment_id) REFERENCES attachments(id)
|
||
"message_attachments_message_id_fkey" FOREIGN KEY (message_id) REFERENCES messages(id) ON DELETE CASCADE
|
||
|
||
Table "public.idempotency_keys"
|
||
Column | Type | Collation | Nullable | Default
|
||
--------------+--------------------------+-----------+----------+---------
|
||
user_id | uuid | | not null |
|
||
method | text | | not null |
|
||
path | text | | not null |
|
||
key | text | | not null |
|
||
request_hash | bytea | | not null |
|
||
status_code | integer | | not null |
|
||
response | jsonb | | not null |
|
||
created_at | timestamp with time zone | | not null | now()
|
||
expires_at | timestamp with time zone | | not null |
|
||
Indexes:
|
||
"idempotency_keys_pkey" PRIMARY KEY, btree (user_id, method, path, key)
|
||
"idempotency_expires_idx" btree (expires_at)
|
||
Check constraints:
|
||
"idempotency_keys_key_check" CHECK (key ~ '^[A-Za-z0-9._:-]{1,128}$'::text)
|
||
Foreign-key constraints:
|
||
"idempotency_keys_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id)
|
||
|
||
Table "public.messages"
|
||
Column | Type | Collation | Nullable | Default
|
||
------------+--------------------------+-----------+----------+-------------------
|
||
id | uuid | | not null |
|
||
chat_id | uuid | | not null |
|
||
sender_id | uuid | | not null |
|
||
text | text | | not null |
|
||
created_at | timestamp with time zone | | not null | clock_timestamp()
|
||
Indexes:
|
||
"messages_pkey" PRIMARY KEY, btree (id)
|
||
"messages_history_idx" btree (chat_id, created_at, id)
|
||
Check constraints:
|
||
"messages_text_check" CHECK (char_length(text) <= 4000)
|
||
Foreign-key constraints:
|
||
"messages_chat_id_fkey" FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE
|
||
"messages_sender_id_fkey" FOREIGN KEY (sender_id) REFERENCES users(id)
|
||
Referenced by:
|
||
TABLE "message_attachments" CONSTRAINT "message_attachments_message_id_fkey" FOREIGN KEY (message_id) REFERENCES messages(id) ON DELETE CASCADE
|
||
|
||
--- статусы вложений в БД (после тестов не должно быть uploading)
|
||
status | count
|
||
--------+-------
|
||
ready | 6
|
||
(1 row)
|
||
|
||
--- пароли хранятся как Argon2id, в sessions только sha256 токена
|
||
hash_prefix | count
|
||
-------------+-------
|
||
$argon2id$ | 26
|
||
(1 row)
|
||
|
||
token_hash_bytes | count
|
||
------------------+-------
|
||
32 | 26
|
||
(1 row)
|
||
|
||
--- миграции выполняет отдельный one-shot сервис migrate (однократно, не репликами)
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab4-migrate-1 mtusi-lab4-api:1 "python -m app.migra…" migrate 3 minutes ago Exited (0) 10 seconds ago
|
||
migrations: ok, latest = 003_attachments.sql
|
||
migrations: ok, latest = 003_attachments.sql
|
||
migrations: ok, latest = 003_attachments.sql
|
||
--- API-реплики стартуют с RUN_MIGRATIONS=0
|
||
RUN_MIGRATIONS=0
|
||
IDEMPOTENCY_TTL_SECONDS=86400
|
||
SESSION_TTL_SECONDS=3600
|
||
--- повторный явный запуск миграции безопасен
|
||
migrations: ok, latest = 003_attachments.sql
|
||
version
|
||
---------------------
|
||
001_init.sql
|
||
002_idempotency.sql
|
||
003_attachments.sql
|
||
(3 rows)
|
||
|
||
|
||
=================== evidence/08-s3-storage.txt
|
||
# 08 приватное S3-хранилище вложений (2026-11-14T11:02:39Z)
|
||
$ docker compose ps -a s3 s3-init
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab4-s3-1 chrislusf/seaweedfs:4.42 "weed server -dir=/d…" s3 3 minutes ago Up 43 seconds (healthy) 7333/tcp, 8080/tcp, 8333/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp
|
||
mtusi-lab4-s3-init-1 mtusi-lab4-api:1 "python -m app.s3init" s3-init 3 minutes ago Exited (0) 14 seconds ago
|
||
--- порты S3 наружу (должно быть пусто: S3 доступен только внутри сети compose)
|
||
--- журнал s3-init (bucket создаётся идемпотентно)
|
||
PASS: ключ API не может удалить рабочий bucket -> AccessDenied
|
||
PASS: ключ API не может писать в чужой bucket -> AccessDenied
|
||
PASS: ключ API: delete_object -> 404
|
||
bucket messenger-attachments: уже существует
|
||
PASS: ключ API: put_object в bucket -> OK
|
||
PASS: ключ API: get_object из bucket -> OK
|
||
PASS: анонимный GET объекта без подписи (HTTP-статус) -> 403
|
||
PASS: анонимный GET списка bucket (HTTP-статус) -> 403
|
||
PASS: ключ API не может создать другой bucket -> AccessDenied
|
||
PASS: ключ API не может удалить рабочий bucket -> AccessDenied
|
||
PASS: ключ API не может писать в чужой bucket -> AccessDenied
|
||
PASS: ключ API: delete_object -> 404
|
||
--- повторный запуск s3-init и проверки приватности/прав (анонимный доступ, ограниченный ключ)
|
||
bucket messenger-attachments: уже существует
|
||
PASS: ключ API: put_object в bucket -> OK
|
||
PASS: ключ API: get_object из bucket -> OK
|
||
PASS: анонимный GET объекта без подписи (HTTP-статус) -> 403
|
||
PASS: анонимный GET списка bucket (HTTP-статус) -> 403
|
||
PASS: ключ API не может создать другой bucket -> AccessDenied
|
||
PASS: ключ API не может удалить рабочий bucket -> AccessDenied
|
||
PASS: ключ API не может писать в чужой bucket -> AccessDenied
|
||
PASS: ключ API: delete_object -> 404
|
||
exit code: 0
|
||
--- у API-реплик есть только ограниченный ключ (имена секретов; значения не печатаются)
|
||
/run/secrets/database_url
|
||
/run/secrets/s3_access_key_id
|
||
/run/secrets/s3_secret_access_key
|
||
--- у API-контейнеров нет локального хранилища вложений: изменения файловой системы после всех загрузок (должно быть пусто)
|
||
(записи /run/secrets относятся к смонтированным Docker secrets и не являются данными вложений)
|
||
container 2c12200fa922:
|
||
изменений файловой системы нет, кроме /run/secrets
|
||
container 45517da31576:
|
||
изменений файловой системы нет, кроме /run/secrets
|
||
--- сверка БД и S3: число готовых вложений и объектов в bucket
|
||
ready в БД: 6
|
||
uploading в БД: 0
|
||
объектов в S3: 6
|
||
--- volume с данными S3
|
||
volume mtusi-lab4_s3data -> /data
|
||
bind -> /run/secrets/s3_config
|
||
|
||
|
||
=================== evidence/09-db-down.txt
|
||
# 09 недоступность PostgreSQL (2026-11-14T11:02:48Z)
|
||
$ docker compose stop postgres
|
||
Container mtusi-lab4-postgres-1 Stopping
|
||
Container mtusi-lab4-postgres-1 Stopped
|
||
GET /health/ready (через LB) -> 503 (все backend не готовы, LB отвечает 503)
|
||
GET /api/v1/users/me -> 503
|
||
$ docker compose start postgres
|
||
Container mtusi-lab4-postgres-1 Starting
|
||
Container mtusi-lab4-postgres-1 Started
|
||
ready и 2 реплики снова через 4 с
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab4-api-1 mtusi-lab4-api:1 "uvicorn app.main:ap…" api 3 minutes ago Up 34 seconds (healthy) 8080/tcp
|
||
mtusi-lab4-api-2 mtusi-lab4-api:1 "uvicorn app.main:ap…" api 3 minutes ago Up 34 seconds (healthy) 8080/tcp
|
||
mtusi-lab4-lb-1 haproxy:2.8.10-alpine "docker-entrypoint.s…" lb 3 minutes ago Up 34 seconds (healthy) 127.0.0.1:8080->8080/tcp
|
||
mtusi-lab4-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres 3 minutes ago Up 3 seconds (healthy) 5432/tcp
|
||
mtusi-lab4-s3-1 chrislusf/seaweedfs:4.42 "weed server -dir=/d…" s3 3 minutes ago Up About a minute (healthy) 7333/tcp, 8080/tcp, 8333/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp
|
||
|
||
=================== evidence/10-s3-down.txt
|
||
# 10 недоступность S3 при живых API и PostgreSQL (2026-11-14T15:47:12Z)
|
||
$ python student-tests/lab4_checks.py --mode s3-outage (внутри: docker compose stop s3 ... docker compose start s3)
|
||
PASS: до сбоя: загрузка -> 201
|
||
PASS: S3 остановлен: загрузка -> 503 (code unavailable), 8.1 с
|
||
PASS: S3 остановлен: скачивание -> 503, а не 500/зависание
|
||
PASS: S3 остановлен: метаданные (только PostgreSQL) -> 200
|
||
PASS: S3 остановлен: обычное сообщение -> 201
|
||
PASS: S3 остановлен: сообщение со старым вложением -> 201 (только PostgreSQL)
|
||
PASS: S3 остановлен: /health/ready остаётся 200 (S3 некритичен для текстового API)
|
||
PASS: после старта S3 загрузка снова -> 201 (через 25 с)
|
||
PASS: после старта S3 старое вложение скачивается, байты те же (через 1.1 с, попыток: 2)
|
||
INFO: S3 был недоступен около 41 с
|
||
PASS: все проверки режима 's3-outage'
|
||
exit code: 0
|
||
S3 healthy
|
||
--- после сбоя в БД остаются строки uploading (если удаление объекта подтвердить не удалось)
|
||
status | count
|
||
-----------+-------
|
||
ready | 32
|
||
uploading | 15
|
||
(2 rows)
|
||
|
||
$ python -m app.sweep --grace 0 (очистка незавершённых загрузок)
|
||
sweep: найдено 15, удалено 15, не удалось 0 (grace=0 с)
|
||
status | count
|
||
--------+-------
|
||
ready | 32
|
||
(1 row)
|
||
|
||
объектов в S3: 32
|
||
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
|
||
mtusi-lab4-api-1 mtusi-lab4-api:1 "uvicorn app.main:ap…" api 5 hours ago Up About a minute (healthy) 8080/tcp
|
||
mtusi-lab4-api-2 mtusi-lab4-api:1 "uvicorn app.main:ap…" api 5 hours ago Up About a minute (healthy) 8080/tcp
|
||
mtusi-lab4-lb-1 haproxy:2.8.10-alpine "docker-entrypoint.s…" lb 5 hours ago Up 5 hours (healthy) 127.0.0.1:8080->8080/tcp
|
||
mtusi-lab4-postgres-1 postgres:16.4-alpine "docker-entrypoint.s…" postgres 5 hours ago Up 5 hours (healthy) 5432/tcp
|
||
mtusi-lab4-s3-1 chrislusf/seaweedfs:4.42 "weed server -dir=/d…" s3 5 hours ago Up 33 seconds (healthy) 7333/tcp, 8080/tcp, 8333/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp
|
||
|
||
=================== evidence/11-lb-config.txt
|
||
# 11 настройка LB: проверки и время обнаружения отказа (2026-11-14T11:04:02Z)
|
||
option redispatch 1 # при неудачном соединении последняя попытка уходит на другой backend
|
||
retries 3 # повторяем только установку соединения: запрос ещё не отправлен, это безопасно
|
||
timeout connect 1s
|
||
timeout client 30s
|
||
timeout server 30s
|
||
timeout http-request 10s
|
||
timeout check 1s
|
||
timeout resolve 1s
|
||
timeout retry 1s
|
||
hold valid 1s
|
||
option httpchk
|
||
http-check send meth GET uri /health/ready ver HTTP/1.1 hdr Host api
|
||
http-check expect status 200
|
||
default-server check inter 1s fall 2 rise 2 resolvers docker resolve-prefer ipv4 init-addr none on-marked-down shutdown-sessions
|
||
server-template api 6 api:8080
|
||
Максимальное время обнаружения отказа по конфигурации: inter 1s x fall 2 + timeout check 1s = около 3 с (порог задания: 10 с).
|
||
--- фактическое состояние backend в HAProxy (через stats нет; смотрим логи LB за последние строки)
|
||
172.25.0.1:44958 [14/Nov/2026:11:03:36.713] public api/api2 0/0/0/7/7 503 354 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:44984 [14/Nov/2026:11:03:37.747] public api/api1 0/0/0/21/21 503 354 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:44988 [14/Nov/2026:11:03:38.788] public api/api2 0/0/0/876/877 503 354 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:45008 [14/Nov/2026:11:03:40.669] public api/api1 0/0/0/14/14 503 354 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:57982 [14/Nov/2026:11:03:41.701] public api/api2 0/0/0/7/7 503 354 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:57988 [14/Nov/2026:11:03:42.726] public api/api1 0/0/1/1081/1082 503 354 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:58024 [14/Nov/2026:11:03:44.832] public api/api2 0/0/0/1304/1304 503 354 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:58034 [14/Nov/2026:11:03:47.163] public api/api1 0/0/0/7/7 503 354 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:58064 [14/Nov/2026:11:03:48.174] public api/api2 0/0/0/12/12 503 354 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:58076 [14/Nov/2026:11:03:49.213] public api/api1 0/0/1/1546/1547 503 354 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:39882 [14/Nov/2026:11:03:51.782] public api/api2 0/0/0/1222/1222 503 354 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:39904 [14/Nov/2026:11:03:54.023] public api/api1 0/0/1/6/7 503 354 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:39912 [14/Nov/2026:11:03:55.051] public api/api2 0/0/1/7/8 503 354 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:39920 [14/Nov/2026:11:03:56.081] public api/api1 0/0/1/27/29 201 620 - - ---- 1/1/0/0/0 0/0 "POST /api/v1/chats/51da9e1c-662c-4bb0-a8d4-b4c55e6e13a9/attachments?filename=a.png HTTP/1.1"
|
||
172.25.0.1:39926 [14/Nov/2026:11:03:56.127] public api/api2 0/0/1/2/3 503 354 - - ---- 1/1/0/0/0 0/0 "GET /api/v1/attachments/05bb3ffb-93bb-4e5c-ad31-fe99c47930ce/content HTTP/1.1"
|
||
|
||
=================== evidence/12-git-hygiene.txt
|
||
# 12 секреты и volumes вне Git (2026-11-14T11:04:03Z)
|
||
$ git check-ignore -v secrets/pg_password secrets/database_url .env
|
||
.gitignore:5:secrets/ secrets/pg_password
|
||
.gitignore:5:secrets/ secrets/database_url
|
||
.gitignore:2:.env .env
|
||
$ отслеживаемые файлы, похожие на секреты:
|
||
нет
|