feat: drop capabilities, run read-only and non-root in every container, mTLS for the S3 gRPC gateway
Every service of the stand gets the x-hardening anchor (cap_drop ALL, no-new-privileges, read-only root) with an empty exception table, tmpfs with size limits, pids limits by measurement and non-root users for PostgreSQL, Valkey, RabbitMQ and SeaweedFS. The S3 gateway gRPC accepts only mTLS with the stand CA. make hardening_check checks inspect data, processes and listeners against the compose model; a fast test keeps the override files from removing restrictions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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 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 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,48 @@ docker compose logs --no-log-prefix openbao | grep '"type":"response"'
|
||||
сигналу. Подготовки руками нет. `make failure_checks`, рабочие профили `bench/` и job CI — свой
|
||||
OpenBao прогона их оркестраторов (`secrets.md`, «OpenBao прогона»).
|
||||
|
||||
## Лаба 7: ограничения контейнеров
|
||||
|
||||
Change `container-hardening` (`docker.md`, «Ограничения контейнеров»). У каждого сервиса — якорь
|
||||
`x-hardening` (ни одной capability, `no-new-privileges`, корень только на чтение), tmpfs с
|
||||
`size=`, `pids`; PostgreSQL, Valkey, брокер — `user: "999:999"`, S3 — `"1000:1000"`; gRPC шлюза S3
|
||||
— только mTLS. Переход стенда — `make run_docker` (OpenBao пересоздаётся запечатанным: код 2) →
|
||||
`make bao_unseal` → `make run_docker`.
|
||||
|
||||
```bash
|
||||
make hardening_check # ~25 с: таблица «контейнер → проверка → ожидалось → получено»; 0 / 1 / 2
|
||||
make hardening_check REPORT=1 # те же сведения без вердикта (стенд до change)
|
||||
make s3_check # с change — ещё строки gRPC шлюза S3 (mTLS)
|
||||
```
|
||||
|
||||
- **`hardening-check`** — контейнеры проекта по метке `com.docker.compose.project`
|
||||
(`COMPOSE_PROJECT_NAME`, в том числе одноразовые и `docker compose run`; пробы этой команды — с
|
||||
меткой `mtusi.hardening-check=<tag>`, без метки проекта). Нет работающих — код 2 одной строкой.
|
||||
Модель — `docker compose config --format json` и `x-hardening-exceptions`. Описание: privileged,
|
||||
устройства, пространства (сеть `container:` — только контейнер стенда), `CapDrop` = ALL, `CapAdd`
|
||||
(или исключение), `no-new-privileges`, `seccomp` / `apparmor=unconfined`, `ReadonlyRootfs` (или
|
||||
исключение), пользователь контейнера (пустой — пользователь образа, у containerd поле `Image`
|
||||
может не находиться — тогда по `Config.Image`), `Tmpfs` с `size=` без `suid` / `dev`,
|
||||
монтирования (volumes модели, tmpfs, bind только на чтение из репозитория или файлов `secrets`
|
||||
модели, без `docker.sock`), `NanoCpus` / `Memory` / `PidsLimit` > 0, `PortBindings` = `HC_PUBLISHED`
|
||||
на `127.0.0.1`, «matches compose model» (`cap_drop`, `cap_add`, nnp, `read_only`, `pids`, tmpfs,
|
||||
user). Пробы (6 параллельно) на образе API `--read-only --cap-drop ALL --security-opt
|
||||
no-new-privileges --user 10001 --pids-limit 32 --memory 64m`: процессы — `--pid container:<id>
|
||||
--network none` (`/proc/*/status`: `Uid`, `CapEff`, `CapBnd`, `NoNewPrivs`, `Seccomp`), слушатели —
|
||||
`--network container:<id>` у владельцев сетевых пространств (`/proc/net/tcp*`, вне loopback =
|
||||
`HC_LISTENERS`); `docker exec … python` у `api`, `worker`, `relay`, `cleaner` — создать `/` и
|
||||
`/var/tmp` (`EROFS`; на стенде до change — `EACCES` и `written`); `docker compose run --rm
|
||||
--no-deps -T --label … --entrypoint python worker` — потоки (стек 256 KiB, не больше 4096) до
|
||||
отказа, пока держатся — `GET /health/ready` через LB. `--report` — без столбца ожиданий, код 0.
|
||||
Уборка — по метке, три круга, в `finally` и по SIGINT / SIGTERM (очередь проб отменяется).
|
||||
- **Новые строки `s3-check`** — `S3_GRPC_PY` на образе API из сети `<проект>_default`
|
||||
(stdlib `ssl`, преамбула HTTP/2 и пустой SETTINGS): без TLS — `no HTTP/2 answer`, без сертификата
|
||||
и с клиентским leaf постороннего CA — `refused`, с разовым клиентским leaf CA стенда
|
||||
`s3-grpc-probe` (1 день, `pki.sh issue` во временный каталог, удаляется) — `HTTP/2 answer
|
||||
(TLSv1.3)`. Разбор `weed shell` не считает объектом строку об истории команд.
|
||||
- **Журнал `s3`**: `W … propagating_store.go … failed to propagate change to s3 server
|
||||
127.0.0.1:18333` — ожидаемо (толчок filer без TLS отвергается, доставка — подпиской).
|
||||
|
||||
## Direct invocation (без HTTP)
|
||||
|
||||
Для правок в `src/core/` сервисы вызываются поверх единицы работы, сервер не
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user