Files
mtusi2026lab7/contracts/trust-matrix.md
T
kaktuz20000 5a6fcff3ef
Skeleton contracts / contracts (pull_request) Canceled after 0s
выполение на 5
2026-11-04 19:22:35 +03:00

36 lines
7.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Матрица доверия — lab7
Для каждой связи указаны используемые endpoint, protocol, identity и фактический способ проверки. Состояние относится к реализации в `compose.yaml`.
| Связь | Фактический endpoint / protocol / identity | Проверка, срок действия | Доказательство / конфиг |
| --- | --- | --- | --- |
| Клиент → ingress/LB | `localhost:8443`, HTTPS; CA `secrets/pki/ca.crt`; ingress SAN `localhost`, `127.0.0.1`; внешний client certificate не требуется | Python HTTPS client проверяет CA и hostname; пользовательская идентичность — Bearer session; пять попыток на username и шестьдесят на source IP за минуту, затем 429/Retry-After | `haproxy.cfg`, `scripts/bootstrap-pki.py`, `tests/security.py`, `tests/login_rate_limit.py` |
| LB → API (все реплики) | `api:8080`, TLS 1.2+, mTLS; CA `ca.crt`; HAProxy cert URI SAN `spiffe://mtusi2026lab7/load-balancer`; API SAN `DNS:api` | HAProxy проверяет CA и DNS hostname; API проверяет клиентскую CA chain и точный URI SAN; leaf lifetime 397 дней | `haproxy.cfg`, `src/app.py`, `src/security.py`, `tests/internal_mtls.py`; `make test-internal-mtls` |
| API/worker → PostgreSQL | `postgres:5432`, PostgreSQL TLS over Compose network; CA verification (`sslmode=verify-full`); separate API and `messenger_worker` DB roles | Server certificate and hostname verified; worker role limited to attachment/outbox operations and columns | `compose.yaml`, `infra/postgres/pg_hba.conf`, `src/store.py`, `tests/worker_isolation.py` |
| API/worker/publisher/reconciler → S3 | `s3:8334`, HTTPS with mTLS; separate client certificates and access keys; CA verification | API reads originals/variants and lists originals as configured; worker reads/writes staging and writes originals/variants, but cannot list or read originals/variants; publisher/migrator have no object actions | `compose.yaml`, `scripts/prepare-secure-secrets.py`, `src/object_store.py`, `tests/worker_isolation.py` |
| Publisher/worker → broker | `rabbitmq:5671`, AMQPS with mTLS and CA/hostname verification; separate publisher and worker identities | Publisher can publish through the default exchange; worker consumes `attachments.process.v1` and is denied publishing; queue definitions are provisioned separately | `compose.yaml`, `src/jobs.py`, `scripts/prepare-secure-secrets.py`, `tests/worker_isolation.py` |
| API/worker/publisher → Collector | `otel-collector:4318`, OTLP/HTTP over HTTPS with mTLS; distinct client certificates and CA verification | Collector requires a client certificate from the lab CA; application uses TLS exporter settings | `compose.yaml`, `infra/otel/collector.yaml`, `src/telemetry.py` |
| Collector → telemetry backends | Prometheus scrape endpoint uses HTTPS/mTLS; Loki and Tempo use HTTPS with CA validation | Prometheus client certificate is checked by Collector; Collector validates backend CA | `infra/otel/collector.yaml`, `infra/otel/prometheus.yml`, `infra/otel/loki.yml`, `infra/otel/tempo.yml` |
| Grafana → data sources | Prometheus, Loki and Tempo HTTPS service endpoints | Grafana uses the local CA trust bundle; endpoints were queried from the Grafana container | `compose.yaml`, `infra/otel/grafana/provisioning/datasources/datasources.yml` |
| API/worker/agent → OpenBao | `https://openbao:8200`, CA verified; AppRole role_id + SecretID; KV v2 service-specific path | Per-service policy разрешает только `secret/data/messenger/<service>` read; SecretID TTL 24h, service token TTL 15m (max 1h) | `infra/openbao/config.hcl`, `scripts/bootstrap-openbao.py`, `src/config.py` |
| Оператор → OpenBao/Grafana/S3 admin | OpenBao опубликован только на `127.0.0.1:8200` по TLS; Grafana также на loopback; S3 admin используется bootstrap job внутри Compose network | OpenBao root token и unseal shares остаются у оператора; application services их не получают | `compose.yaml`, `infra/openbao/README.md`, `scripts/bootstrap-secrets.py` |
| API → Redis/Valkey, если используется | N/A: session source of truth — PostgreSQL; Redis/Valkey не выбран | Не применяется | `src/store.py`, `compose.yaml` |
| Replication/кластерные каналы, если добавлены | N/A: replicated database, broker cluster и multi-host transport не добавлены | Не применяется | `compose.yaml` |
| LB/API health checks | LB health request использует mTLS backend connection; API self-check использует loopback HTTPS и разрешённый LB certificate | API listener не опубликован на host; health endpoint не обходит mTLS | `haproxy.cfg`, `compose.yaml`, `src/app.py` |
## Отрицательные проверки
1. `make test-security BASE_URL=https://localhost:8443 CA_FILE=...` выполняет положительный TLS probe и проверку отказа пустого trust store. Hostname проверяется клиентским TLS context.
2. `make test-internal-mtls` проверяет API listener без client cert, с cert от foreign CA и с URI SAN другой службы; разрешённый LB cert должен пройти.
3. `make test-login-limit` проверяет 429 и положительный Retry-After после неудачных попыток.
4. `make test` проверяет ACL чат-участников, logout, сессии, сообщения и вложения; дополнительный `X-User-Id` не является источником identity после lab1.
5. `make test-openbao-acl` проверяет, что каждая AppRole читает только собственный KV path и получает 403 на остальные service paths.
6. `make test-worker-isolation` проверяет разрешённые и запрещённые операции worker в PostgreSQL, S3 и RabbitMQ.
7. `make test-worker-rotation ROOT_TOKEN_FILE=...` отзывает старый worker SecretID, проверяет отказ старой identity и завершает queued attachment с заменённой identity.
## Bootstrap и эксплуатация
В Git хранятся только конфигурация и скрипты. CA private key, leaf keys, root token, unseal shares и AppRole SecretIDs создаются локально и хранятся в исключённом каталоге `secrets/`. Оператор отвечает за CA/unseal; OpenBao использует persistent file storage, TLS listener и AppRole auth. Root token не монтируется приложению. После restart оператор unseal-ит OpenBao при необходимости; приложение повторно аутентифицируется AppRole при старте.
Redis и кластерные каналы не используются. После перезапуска OpenBao operator выполняет unseal; приложение не использует plaintext fallback при недоступном/sealed OpenBao.