feat: rotate and revoke credentials on the running stand

Add operator commands for leaf and secret rotation, identity revocation
and CRL renewal without rebuilding images, and a drill under load.
A rejected PostgreSQL role password is now 503 instead of 500.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 06:46:55 +03:00
co-authored by Claude Opus 5.5
parent 21b8a08e46
commit c40fbef36a
40 changed files with 5804 additions and 127 deletions
+33 -1
View File
@@ -1,6 +1,6 @@
---
name: run-mtusi-messenger
description: Запустить, остановить, прогнать и подёргать API мессенджера MTUSI (FastAPI, PostgreSQL, Valkey; лаба 3 — HAProxy перед репликами API; лаба 4 — S3 на SeaweedFS; лаба 5 — RabbitMQ, relay и worker; лаба 6 — OTel Collector, Prometheus, Loki, Tempo и Grafana; лаба 7 — HTTPS на :8443, mTLS LB → API, локальный CA) — на хосте или в Docker. Use when asked to run / start / stop the server or the stand, check telemetry (find a request in Loki and Tempo, Grafana provisioning, Collector outage, stand from scratch), run the smoke test, `make test`, `make student_test`, `make test_isolated`, `make test-persistence` or `make test-failover`, `make s3_check`, `make mtls_check` (mTLS LB → API negative checks), `make storage_tls_check` (TLS to PostgreSQL, Valkey and S3 negative checks), `make broker_mtls_check` (mTLS to RabbitMQ, relay and worker rights negative checks), `make telemetry_tls_check` (mTLS to the OTel Collector gateway negative checks), `make hardening_check` (container capabilities, users, read-only roots, pids limits, ports), `make scan` (image and uv.lock vulnerability scan with triage), `make pki_stand` / `pki_status` (stand certificates), check that the S3 bucket is private, run the defense scenario or its failure windows, check the broker, the worker or the relay process, show the pipeline state, stop or restore an API replica, show X-Instance-Id distribution, check that an API change works on a live server, send a request to an endpoint, reproduce a bug over HTTP, check the containers, or call services directly without HTTP.
description: Запустить, остановить, прогнать и подёргать API мессенджера MTUSI (FastAPI, PostgreSQL, Valkey; лаба 3 — HAProxy перед репликами API; лаба 4 — S3 на SeaweedFS; лаба 5 — RabbitMQ, relay и worker; лаба 6 — OTel Collector, Prometheus, Loki, Tempo и Grafana; лаба 7 — HTTPS на :8443, mTLS LB → API, локальный CA) — на хосте или в Docker. Use when asked to run / start / stop the server or the stand, check telemetry (find a request in Loki and Tempo, Grafana provisioning, Collector outage, stand from scratch), run the smoke test, `make test`, `make student_test`, `make test_isolated`, `make test-persistence` or `make test-failover`, `make s3_check`, `make mtls_check` (mTLS LB → API negative checks), `make storage_tls_check` (TLS to PostgreSQL, Valkey and S3 negative checks), `make broker_mtls_check` (mTLS to RabbitMQ, relay and worker rights negative checks), `make telemetry_tls_check` (mTLS to the OTel Collector gateway negative checks), `make hardening_check` (container capabilities, users, read-only roots, pids limits, ports), `make scan` (image and uv.lock vulnerability scan with triage), `make rotation_check` / `rotate_leaf` / `revoke_identity` / `rotate_secret` / `pki_renew` (rotation and revocation on the running stand), `make pki_stand` / `pki_status` (stand certificates), check that the S3 bucket is private, run the defense scenario or its failure windows, check the broker, the worker or the relay process, show the pipeline state, stop or restore an API replica, show X-Instance-Id distribution, check that an API change works on a live server, send a request to an endpoint, reproduce a bug over HTTP, check the containers, or call services directly without HTTP.
---
REST API мессенджера (пользователи, чаты, сообщения) — сервер на
@@ -1045,6 +1045,38 @@ docker compose logs --no-log-prefix openbao | grep '"type":"response"'
сигналу. Подготовки руками нет. `make failure_checks`, рабочие профили `bench/` и job CI — свой
OpenBao прогона их оркестраторов (`secrets.md`, «OpenBao прогона»).
## Лаба 7: ротация и отзыв
Change `rotation-revocation` (правило `rotation.md`): команды оператора на работающем стенде без сборки
образов (`infra/rotation/rotation.py`). Коды скрипта 0 / 1 (фаза и команда, которая сводит) / 2
(предусловие, ничего не изменено), make — 0 или ненулевой. Ctrl+C после первого изменения откладывается
до конца команды.
```bash
make rotate_leaf IDENTITY=haproxy # новый leaf → владелец → отзыв прежних → CRL у проверяющих, 2–30 с
make revoke_identity IDENTITY=relay # CRL, закрытые соединения, отозванные токены, ~5 с; возврат — rotate_leaf
make pki_renew # CRL и истекающие leaf у всех сервисов, ~50 с; раз в две недели
make rotate_secret SECRET=postgres/api # .env → OpenBao и хранилище → процессы → прежнее отвергнуто, 6–25 с
make rolling_update BUILD=0 MIGRATE=0 # замена реплик на том же образе
make rotation_check # учения под нагрузкой, ~4 мин; меняет leaf и секреты рабочего стенда
make rotation_check CONTROL=skip-crl # контроль: отзыв только файлами — код 1 с именами проверяющих, ~1 мин
make pki_status # сроки и identity с действующими прежними leaf
```
- **`rotation-check`** — нагрузка `RotationLoad` (6 потоков отправки с ключом и повтором до 201, чтение,
загрузка раз в 2 с, скачивание раз в 1 с), клиент `RotationProbe` — контейнер образа API в сети стенда с
копиями пар (каталог 0700 во временном каталоге, удаляется): соединение AMQP, keep-alive OTLP, токен
и сессия TLS OpenBao «украденного» `relay`. Шаги: leaf `ingress` и `haproxy`; секреты `s3/api` и
`postgres/api`; запечатанный OpenBao — код 2; отзыв и возврат `relay`; истёкший leaf; сверка записей и
вложений, образы прежние, `make test`, `pki_status`. Строка — «что | expected | got»; в конце PASS / FAIL.
Уборка — в `finally` и по сигналу: контейнеры по метке, копии leaf, `rotate_leaf relay`, unseal.
Реплика обрывает рукопожатие без alert (asyncio) — ожидание `refused: tls`; причину называет быстрый
тест `test_api_tls.py`.
- Реплики после правки кода на образе, отличном от тега (`make test_isolated` пересобрал его из другого кода),
— код 2 «runs another build»: сначала `make run_docker` или `make rolling_update`.
- Правка `infra/rabbitmq/start.sh` на работающем стенде рвёт bind mount: `rotation.py` отвечает кодом 2 «the
broker runs without start.sh --install-crl» — `docker compose restart rabbitmq`.
## Лаба 7: ограничения контейнеров
Change `container-hardening` (`docker.md`, «Ограничения контейнеров»). У каждого сервиса — якорь
File diff suppressed because it is too large Load Diff