Files
mtusi2026lab7/compose.yaml
T

683 lines
26 KiB
YAML
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: тот же мессенджер (lab2–6), но каждая связь — TLS, внутренние — mTLS с identity,
# секреты — из OpenBao, контейнеры — с минимальными привилегиями.
#
# клиент ──HTTPS 127.0.0.1:8443──▶ lb ──mTLS (CN lb ∈ allowlist API)──▶ api × 2
# api/worker ──TLS verify-full + сертификат (CN = роль БД) + пароль из OpenBao──▶ postgres
# api ──mTLS (CN api → ACL-пользователь api)──▶ redis (кэш сессий, общий rate limit)
# api/worker ──mTLS (CN → ACL producer/consumer)──▶ broker (Redis Streams + AOF)
# api/worker ──HTTPS + отдельный пользователь MinIO на роль (prefix-политики)──▶ s3
# api/worker/migrate ──mTLS cert auth──▶ openbao (KV своей роли, TTL токена 15 мин)
# api/worker ──mTLS (CN ∈ {api, worker})──▶ otel-gw ──loopback──▶ otel-collector
# otel-collector ──mTLS──▶ prometheus / loki / tempo ◀──mTLS── grafana (HTTPS 127.0.0.1:3000)
#
# Bootstrap (один раз, оператор): python scripts/lab7.py bootstrap
# CA и leaf-сертификаты (infra/pki) → init/unseal OpenBao (ключи — вне репозитория, у оператора)
# → политики и cert auth → роли БД, пользователи MinIO → запуск всего стенда.
# После рестарта OpenBao: python scripts/lab7.py unseal
#
# Сети (кроме edge — все internal: без выхода в интернет):
# edge — lb и grafana: только они публикуют порты (127.0.0.1);
# backend — lb ↔ api;
# data — api, worker, migrate ↔ postgres, redis, broker, s3;
# secrets — api, worker, migrate ↔ openbao;
# otel — api, worker ↔ otel-gw;
# tstore — otel-gw/otel-collector, prometheus, loki, tempo, grafana.
name: mtusi-lab7
x-hardening: &hardening
security_opt: ["no-new-privileges:true"]
cap_drop: ["ALL"]
x-app-env: &app-env
APP_PORT: "8443"
TLS_CERT_FILE: /tls/tls.crt
TLS_KEY_FILE: /tls/tls.key
TLS_CA_FILE: /tls/ca.crt
TLS_CRL_FILE: /tls/crl.pem
TLS_ALLOWED_CLIENTS: lb
BAO_ADDR: https://openbao:8200
SECRETS_REFRESH_SECONDS: ${SECRETS_REFRESH_SECONDS:-15}
DB_HOST: postgres
DB_PORT: "5432"
DB_NAME: messenger
DB_SSLMODE: verify-full
CACHE_URL: rediss://redis:6379/0
BROKER_URL: rediss://broker:6379/0
S3_ENDPOINT: https://s3:9000
S3_REGION: ${S3_REGION:-us-east-1}
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
SESSION_CACHE_TTL_SECONDS: ${SESSION_CACHE_TTL_SECONDS:-60}
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
# lab7: соединение к PostgreSQL теперь дорогое (TLS + клиентский сертификат + SCRAM), а пул
# растёт по одному соединению. При всплеске входов на 0,5 CPU рост не успевал за 3 c → 503.
# Держим соединения открытыми заранее.
DB_POOL_MIN: ${DB_POOL_MIN:-8}
DB_POOL_MAX: ${DB_POOL_MAX:-10}
DB_POOL_TIMEOUT: ${DB_POOL_TIMEOUT:-3}
DB_STATEMENT_TIMEOUT_MS: ${DB_STATEMENT_TIMEOUT_MS:-5000}
REDIS_TIMEOUT: ${REDIS_TIMEOUT:-0.5}
SHUTDOWN_TIMEOUT: ${SHUTDOWN_TIMEOUT:-10}
LOG_LEVEL: ${LOG_LEVEL:-info}
MIGRATE_ON_START: "false"
S3_CONNECT_TIMEOUT: ${S3_CONNECT_TIMEOUT:-2}
S3_READ_TIMEOUT: ${S3_READ_TIMEOUT:-10}
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
MAX_JSON_BODY_BYTES: ${MAX_JSON_BODY_BYTES:-65536}
UPLOAD_BODY_TIMEOUT_SECONDS: ${UPLOAD_BODY_TIMEOUT_SECONDS:-60}
UPLOAD_SPOOL_MEMORY_BYTES: ${UPLOAD_SPOOL_MEMORY_BYTES:-262144}
UPLOAD_MAX_CONCURRENT: ${UPLOAD_MAX_CONCURRENT:-16}
IMAGE_CHECK_CONCURRENCY: ${IMAGE_CHECK_CONCURRENCY:-2}
UPLOAD_GRACE_SECONDS: ${UPLOAD_GRACE_SECONDS:-900}
JANITOR_INTERVAL_SECONDS: ${JANITOR_INTERVAL_SECONDS:-60}
S3_BREAKER_SECONDS: ${S3_BREAKER_SECONDS:-5}
# lab7: Argon2id и защита входа (обоснование параметров — REPORT.md, замер на стенде)
ARGON2_MEMORY_KIB: ${ARGON2_MEMORY_KIB:-19456}
ARGON2_ITERATIONS: ${ARGON2_ITERATIONS:-2}
ARGON2_PARALLELISM: ${ARGON2_PARALLELISM:-1}
PASSWORD_HASH_CONCURRENCY: ${PASSWORD_HASH_CONCURRENCY:-2}
PASSWORD_HASH_QUEUE: ${PASSWORD_HASH_QUEUE:-8}
LOGIN_FAIL_LIMIT: ${LOGIN_FAIL_LIMIT:-5}
LOGIN_FAIL_WINDOW_SECONDS: ${LOGIN_FAIL_WINDOW_SECONDS:-300}
LOGIN_IP_LIMIT: ${LOGIN_IP_LIMIT:-120}
LOGIN_IP_WINDOW_SECONDS: ${LOGIN_IP_WINDOW_SECONDS:-60}
BROKER_TIMEOUT: ${BROKER_TIMEOUT:-2}
PIPELINE_VERSION: "1"
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-2}
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
JOB_LEASE_SECONDS: ${JOB_LEASE_SECONDS:-20}
JOB_BACKOFF_BASE_SECONDS: ${JOB_BACKOFF_BASE_SECONDS:-2}
JOB_BACKOFF_MAX_SECONDS: ${JOB_BACKOFF_MAX_SECONDS:-60}
CLAIM_IDLE_SECONDS: ${CLAIM_IDLE_SECONDS:-90}
IMAGE_MEMORY_MB: ${IMAGE_MEMORY_MB:-768}
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
# lab6/7: OTLP по mTLS через otel-gw; клиентский сертификат = identity роли.
APP_ENV: ${APP_ENV:-lab}
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-gw:4318
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
OTEL_EXPORTER_OTLP_CERTIFICATE: /tls/ca.crt
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: /tls/tls.crt
OTEL_EXPORTER_OTLP_CLIENT_KEY: /tls/tls.key
OTEL_RESOURCE_ATTRIBUTES: ${OTEL_RESOURCE_ATTRIBUTES:-deployment.environment.name=lab}
OTEL_METRIC_EXPORT_INTERVAL: ${OTEL_METRIC_EXPORT_INTERVAL:-10000}
OTEL_SDK_DISABLED: ${OTEL_SDK_DISABLED:-false}
x-api-env: &api-env
<<: *app-env
BAO_AUTH_ROLE: api
BAO_KV_PATH: kv/data/messenger/api
x-worker-env: &worker-env
<<: *app-env
BAO_AUTH_ROLE: worker
BAO_KV_PATH: kv/data/messenger/worker
x-dns-opt: &dns-opt ["timeout:1", "attempts:1"]
# Каталог identity из volume pki монтируется ТОЛЬКО в свой сервис, только для чтения.
x-tls-api: &tls-api {type: volume, source: pki, target: /tls, read_only: true, volume: {subpath: api}}
x-tls-worker: &tls-worker {type: volume, source: pki, target: /tls, read_only: true, volume: {subpath: worker}}
services:
# ======================================================================= секреты и PKI
# Операторский УЦ: запускается вручную (профиль ops), ключ CA — только в volume pki-ca.
pki:
image: mtusi-messenger:lab7
pull_policy: never
profiles: ["ops"]
user: "0:0"
entrypoint: ["python", "/infra/pki/pki.py"]
volumes:
- pki-ca:/ca
- pki:/pki
- ./secrets:/out
- ./infra/pki:/infra/pki:ro
network_mode: none
security_opt: ["no-new-privileges:true"]
cap_drop: ["ALL"]
cap_add: ["CHOWN", "FOWNER", "DAC_OVERRIDE"]
# OpenBao 2.6.4: НЕ dev-mode, Raft-хранилище на volume, TLS, ручной init/unseal.
openbao:
image: openbao/openbao:2.6.4
<<: *hardening
entrypoint: ["bao"]
command: ["server", "-config=/openbao/config/openbao.hcl"]
init: true
environment:
BAO_ADDR: https://127.0.0.1:8200 # для операторских команд через docker compose exec
BAO_CACERT: /openbao/tls/ca.crt
HOME: /tmp
volumes:
- ./infra/openbao/openbao.hcl:/openbao/config/openbao.hcl:ro
- ./infra/openbao/policies:/openbao/policies:ro
- {type: volume, source: pki, target: /openbao/tls, read_only: true, volume: {subpath: openbao}}
- baodata:/openbao/file
- baologs:/openbao/logs
read_only: true
tmpfs: ["/tmp:size=16m"]
networks: [secrets]
healthcheck:
# 0 — распечатан; 2 — sealed (до unseal оператором сервис «unhealthy»).
test: ["CMD", "bao", "status"]
interval: 5s
timeout: 3s
retries: 3
start_period: 5s
deploy:
resources:
limits: {cpus: "0.5", memory: 256M}
restart: unless-stopped
# ======================================================================= хранилища
postgres:
image: postgres:16.4-alpine
<<: *hardening
user: "70:70" # сразу postgres: entrypoint не нужен root и capabilities
command:
- postgres
- -c
- ssl=on
- -c
- ssl_cert_file=/tls/tls.crt
- -c
- ssl_key_file=/tls/tls.key
- -c
- ssl_ca_file=/tls/ca.crt
- -c
- ssl_crl_file=/tls/crl.pem
- -c
- ssl_min_protocol_version=TLSv1.2
- -c
- hba_file=/etc/postgresql/pg_hba.conf
- -c
- password_encryption=scram-sha-256
- -c
- log_connections=on
environment:
POSTGRES_DB: messenger
POSTGRES_USER: postgres
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
secrets: [postgres_password]
volumes:
- pgdata:/var/lib/postgresql/data
- ./infra/postgres/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro
- {type: volume, source: pki, target: /tls, read_only: true, volume: {subpath: postgres}}
read_only: true
tmpfs: ["/var/run/postgresql:mode=1777,size=1m", "/tmp:size=16m"]
networks: [data]
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d messenger"]
interval: 5s
timeout: 3s
retries: 20
deploy:
resources:
limits: {cpus: "1.0", memory: 512M}
restart: unless-stopped
# Кэш сессий и общий rate limit. Redis 8.6: TLS-only, клиент обязан предъявить сертификат,
# CN сертификата = ACL-пользователь (tls-auth-clients-user CN), паролей нет.
redis:
image: redis:8.6.8
<<: *hardening
user: "999:999"
command: ["redis-server", "/etc/redis/redis.conf"]
volumes:
- ./infra/redis/cache.conf:/etc/redis/redis.conf:ro
- ./infra/redis/cache.acl:/etc/redis/users.acl:ro
- ./infra/redis/rcli.sh:/usr/local/bin/rcli:ro
- {type: volume, source: pki, target: /tls, read_only: true, volume: {subpath: redis}}
read_only: true
tmpfs: ["/data:size=8m", "/tmp:size=8m"]
networks: [data]
healthcheck:
test: ["CMD", "sh", "/usr/local/bin/rcli", "ping"]
interval: 5s
timeout: 3s
retries: 20
deploy:
resources:
limits: {cpus: "0.25", memory: 96M}
restart: unless-stopped
# Брокер заданий (lab5): Redis Streams + AOF (appendfsync always) на volume.
broker:
image: redis:8.6.8
<<: *hardening
user: "999:999"
command: ["redis-server", "/etc/redis/redis.conf"]
volumes:
- brokerdata:/data
- ./infra/redis/broker.conf:/etc/redis/redis.conf:ro
- ./infra/redis/broker.acl:/etc/redis/users.acl:ro
- ./infra/redis/rcli.sh:/usr/local/bin/rcli:ro
- {type: volume, source: pki, target: /tls, read_only: true, volume: {subpath: broker}}
read_only: true
tmpfs: ["/tmp:size=8m"]
networks: [data]
healthcheck:
test: ["CMD", "sh", "/usr/local/bin/rcli", "ping"]
interval: 5s
timeout: 3s
retries: 20
deploy:
resources:
limits: {cpus: "0.5", memory: 256M}
restart: unless-stopped
# MinIO (сборка Pigsty): HTTPS (--certs-dir), root-credentials — docker secrets,
# у api и worker — отдельные пользователи с prefix-политиками (scripts/lab7.py bootstrap).
s3:
image: pgsty/minio:RELEASE.2026-08-04T00-00-00Z
<<: *hardening
command: ["server", "/data", "--certs-dir", "/certs"]
environment:
MINIO_ROOT_USER_FILE: /run/secrets/minio_root_user
MINIO_ROOT_PASSWORD_FILE: /run/secrets/minio_root_password
MINIO_BROWSER: "off"
SSL_CERT_FILE: /certs/ca.crt # mc внутри контейнера доверяет CA стенда
MC_CONFIG_DIR: /tmp/.mc
MC_HOST_health: https://127.0.0.1:9000
secrets: [minio_root_user, minio_root_password]
volumes:
- s3data:/data
- {type: volume, source: pki, target: /certs, read_only: true, volume: {subpath: s3}}
read_only: true
tmpfs: ["/tmp:size=32m"]
networks: [data]
healthcheck:
test: ["CMD", "mc", "ready", "health"]
interval: 5s
timeout: 5s
retries: 20
deploy:
resources:
limits: {cpus: "1.0", memory: 512M}
restart: unless-stopped
# ======================================================================= приложение
migrate:
build: .
image: mtusi-messenger:lab7
<<: *hardening
command: ["python", "-m", "app.migrate"]
environment:
<<: *app-env
BAO_AUTH_ROLE: migrate
BAO_KV_PATH: kv/data/messenger/migrate
volumes:
- {type: volume, source: pki, target: /tls, read_only: true, volume: {subpath: migrate}}
read_only: true
tmpfs: ["/tmp:size=16m"]
networks: [data, secrets]
depends_on:
postgres: {condition: service_healthy}
openbao: {condition: service_healthy}
deploy:
resources:
limits: {cpus: "0.5", memory: 256M}
restart: "no"
api:
build: .
image: mtusi-messenger:lab7
<<: *hardening
environment: *api-env
dns_opt: *dns-opt
expose: ["8443"] # только mTLS; портов на хосте нет
volumes: [*tls-api]
read_only: true
tmpfs: ["/tmp:size=64m"] # буфер загрузки (spool) и временные файлы
networks: [backend, data, secrets, otel]
deploy:
replicas: ${API_REPLICAS:-2}
resources:
limits: {cpus: "0.5", memory: 256M, pids: 128}
healthcheck:
# health-listener только на 127.0.0.1 контейнера (без TLS, только /health/*).
test: ["CMD", "python", "-c", "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8081/health/ready',timeout=2).status==200 else 1)"]
interval: 5s
timeout: 3s
retries: 3
start_period: 10s
stop_grace_period: 15s
depends_on:
migrate: {condition: service_completed_successfully}
postgres: {condition: service_healthy}
redis: {condition: service_healthy}
broker: {condition: service_healthy}
openbao: {condition: service_healthy}
restart: unless-stopped
# Worker: отдельный процесс, своя identity и свои права (БД, S3-prefix, ACL брокера).
worker:
image: mtusi-messenger:lab7
pull_policy: never
<<: *hardening
command: ["python", "-m", "app.worker"]
environment: *worker-env
dns_opt: *dns-opt
volumes: [*tls-worker]
read_only: true
tmpfs: ["/tmp:size=256m"] # файлы задач (оригинал + варианты), heartbeat
networks: [data, secrets, otel]
deploy:
replicas: ${WORKER_REPLICAS:-1}
resources:
limits: {cpus: "1.0", memory: 1G, pids: 256}
healthcheck:
test: ["CMD", "python", "-c", "import os,sys,time; sys.exit(0 if time.time()-os.path.getmtime('/tmp/worker-heartbeat')<30 else 1)"]
interval: 10s
timeout: 3s
retries: 3
start_period: 20s
stop_grace_period: 75s
depends_on:
migrate: {condition: service_completed_successfully}
postgres: {condition: service_healthy}
broker: {condition: service_healthy}
openbao: {condition: service_healthy}
api: {condition: service_started} # образ собирается сервисом api
restart: unless-stopped
lb:
image: haproxy:3.0.5-alpine
<<: *hardening
volumes:
- ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
- {type: volume, source: pki, target: /tls, read_only: true, volume: {subpath: lb}}
read_only: true
tmpfs: ["/tmp:size=8m"]
ports:
- "127.0.0.1:8443:8443"
- "127.0.0.1:8444:8444"
- "127.0.0.1:8445:8445"
networks: [edge, backend]
healthcheck:
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8404/healthz"]
interval: 5s
timeout: 3s
retries: 3
deploy:
resources:
limits: {cpus: "0.5", memory: 128M}
depends_on:
api: {condition: service_started}
restart: unless-stopped
# API с коротким сроком сессии — только для теста истечения (профиль ttl): https://localhost:8444
api-ttl:
image: mtusi-messenger:lab7
pull_policy: never
<<: *hardening
environment:
<<: *api-env
SESSION_TTL_SECONDS: "2"
JANITOR_ENABLED: "false"
dns_opt: *dns-opt
expose: ["8443"]
volumes: [*tls-api]
read_only: true
tmpfs: ["/tmp:size=64m"]
networks: [backend, data, secrets, otel]
deploy:
resources:
limits: {cpus: "0.25", memory: 192M}
depends_on:
postgres: {condition: service_healthy}
profiles: ["ttl"]
# Реплика с внедрением отказов (профиль fault): https://localhost:8445
api-fault:
image: mtusi-messenger:lab7
pull_policy: never
<<: *hardening
environment:
<<: *api-env
FAULT_INJECTION: "true"
JANITOR_ENABLED: "false"
dns_opt: *dns-opt
expose: ["8443"]
volumes: [*tls-api]
read_only: true
tmpfs: ["/tmp:size=64m"]
networks: [backend, data, secrets, otel]
deploy:
resources:
limits: {cpus: "0.5", memory: 256M}
depends_on:
postgres: {condition: service_healthy}
restart: unless-stopped
profiles: ["fault"]
worker-fault:
image: mtusi-messenger:lab7
pull_policy: never
<<: *hardening
command: ["python", "-m", "app.worker"]
environment:
<<: *worker-env
FAULT_INJECTION: "true"
JOB_BACKOFF_BASE_SECONDS: "1"
dns_opt: *dns-opt
volumes: [*tls-worker]
read_only: true
tmpfs: ["/tmp:size=256m"]
networks: [data, secrets, otel]
deploy:
resources:
limits: {cpus: "1.0", memory: 1G}
stop_grace_period: 75s
depends_on:
broker: {condition: service_healthy}
restart: unless-stopped
profiles: ["fault"]
# ======================================================================= наблюдаемость
# mTLS-шлюз Collector (HAProxy): владеет сетевым пространством, Collector подключается к нему.
otel-gw:
image: haproxy:3.0.5-alpine
<<: *hardening
volumes:
- ./infra/otelgw/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
- {type: volume, source: pki, target: /tls, read_only: true, volume: {subpath: otel-gw}}
read_only: true
tmpfs: ["/tmp:size=8m"]
networks: [otel, tstore]
healthcheck:
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8405/healthz"]
interval: 5s
timeout: 3s
retries: 3
deploy:
resources:
limits: {cpus: "0.25", memory: 64M}
restart: unless-stopped
otel-collector:
image: otel/opentelemetry-collector-contrib:0.111.0
<<: *hardening
command: ["--config=/etc/otelcol/config.yaml"]
network_mode: "service:otel-gw" # общий netns: OTLP-приёмник на 127.0.0.1 виден только шлюзу
volumes:
- ./infra/otel/collector.yaml:/etc/otelcol/config.yaml:ro
- {type: volume, source: pki, target: /tls, read_only: true, volume: {subpath: otel-collector}}
environment:
GOMEMLIMIT: 200MiB
read_only: true
depends_on:
otel-gw: {condition: service_started}
deploy:
resources:
limits: {cpus: "0.5", memory: 256M}
restart: unless-stopped
prometheus:
image: prom/prometheus:v2.55.1
<<: *hardening
command:
- --config.file=/etc/prometheus/prometheus.yml
- --web.config.file=/etc/prometheus/web.yml
- --storage.tsdb.path=/prometheus
- --storage.tsdb.retention.time=7d
- --web.enable-remote-write-receiver
volumes:
- ./infra/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- ./infra/prometheus/web.yml:/etc/prometheus/web.yml:ro
- ./infra/prometheus/client.yml:/etc/prometheus/client.yml:ro
- ./infra/prometheus/rules:/etc/prometheus/rules:ro
- {type: volume, source: pki, target: /tls, read_only: true, volume: {subpath: prometheus}}
- promdata:/prometheus
read_only: true
networks: [tstore]
healthcheck:
test: ["CMD", "promtool", "check", "ready", "--url=https://localhost:9090", "--http.config.file=/etc/prometheus/client.yml"]
interval: 10s
timeout: 5s
retries: 10
deploy:
resources:
limits: {cpus: "0.5", memory: 512M}
restart: unless-stopped
# Tempo/Loki работают от uid 10001, а новый named volume может принадлежать root.
telemetry-init:
image: grafana/tempo:2.6.1
user: root
entrypoint: ["chown", "-R", "10001:10001", "/var/tempo", "/loki"]
volumes:
- tempodata:/var/tempo
- lokidata:/loki
network_mode: none
security_opt: ["no-new-privileges:true"]
cap_drop: ["ALL"]
cap_add: ["CHOWN", "DAC_OVERRIDE", "FOWNER"] # повторный запуск: каталоги уже 10001:700
restart: "no"
loki:
image: grafana/loki:3.3.2
<<: *hardening
command: ["-config.file=/etc/loki/loki.yaml"]
volumes:
- ./infra/loki/loki.yaml:/etc/loki/loki.yaml:ro
- {type: volume, source: pki, target: /tls, read_only: true, volume: {subpath: loki}}
- lokidata:/loki
read_only: true
tmpfs: ["/tmp:size=32m"]
networks: [tstore]
depends_on:
telemetry-init: {condition: service_completed_successfully}
deploy:
resources:
limits: {cpus: "0.5", memory: 512M}
restart: unless-stopped
tempo:
image: grafana/tempo:2.6.1
<<: *hardening
command: ["-config.file=/etc/tempo/tempo.yaml"]
volumes:
- ./infra/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro
- {type: volume, source: pki, target: /tls, read_only: true, volume: {subpath: tempo}}
- tempodata:/var/tempo
read_only: true
tmpfs: ["/tmp:size=32m"]
networks: [tstore]
depends_on:
telemetry-init: {condition: service_completed_successfully}
deploy:
resources:
limits: {cpus: "0.5", memory: 512M}
restart: unless-stopped
# Grafana: HTTPS 127.0.0.1:3000, вход по паролю (docker secret). PEM для mTLS к хранилищам
# entrypoint читает из /tls в переменные окружения процесса (provisioning их подставляет).
grafana:
image: grafana/grafana:11.4.0
<<: *hardening
entrypoint: ["/bin/sh", "-c", "export GF_TLS_CA_PEM=\"$$(cat /tls/ca.crt)\" GF_TLS_CERT_PEM=\"$$(cat /tls/tls.crt)\" GF_TLS_KEY_PEM=\"$$(cat /tls/tls.key)\"; exec /run.sh"]
ports:
- "127.0.0.1:3000:3000"
environment:
GF_SERVER_PROTOCOL: https
GF_SERVER_CERT_FILE: /tls/tls.crt
GF_SERVER_CERT_KEY: /tls/tls.key
GF_SECURITY_ADMIN_USER: ${GRAFANA_ADMIN_USER:-admin}
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_admin_password
GF_SECURITY_COOKIE_SECURE: "true"
GF_AUTH_ANONYMOUS_ENABLED: "false"
GF_USERS_ALLOW_SIGN_UP: "false"
GF_ANALYTICS_REPORTING_ENABLED: "false"
GF_ANALYTICS_CHECK_FOR_UPDATES: "false"
GF_NEWS_NEWS_FEED_ENABLED: "false"
GF_PLUGINS_PREINSTALL_DISABLED: "true"
GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH: /var/lib/grafana/dashboards/messenger.json
GF_LOG_MODE: console # корневая ФС только для чтения — без файловых логов
secrets: [grafana_admin_password]
volumes:
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
- {type: volume, source: pki, target: /tls, read_only: true, volume: {subpath: grafana}}
- grafanadata:/var/lib/grafana
read_only: true
tmpfs: ["/tmp:size=32m", "/var/log/grafana:size=8m"]
networks: [edge, tstore]
depends_on:
prometheus: {condition: service_healthy}
loki: {condition: service_started}
tempo: {condition: service_started}
deploy:
resources:
limits: {cpus: "0.5", memory: 384M}
restart: unless-stopped
# ======================================================================= операторские тесты
# Отрицательные проверки внутренних связей (профиль ops): контейнер в каждой сети,
# с каталогом pki целиком (чужие/отозванные/«нарушительские» сертификаты).
sectest:
image: mtusi-messenger:lab7
pull_policy: never
profiles: ["ops"]
user: "0:0"
working_dir: /work
entrypoint: ["python"]
environment:
PYTHONDONTWRITEBYTECODE: "1"
PKI_DIR: /pki
volumes:
- {type: volume, source: pki, target: /pki, read_only: true}
- ./student-tests:/work/student-tests:ro
- ./infra:/work/infra:ro
networks: [edge, backend, data, secrets, otel, tstore]
security_opt: ["no-new-privileges:true"]
networks:
edge: {}
backend: {internal: true}
data: {internal: true}
secrets: {internal: true}
otel: {internal: true}
tstore: {internal: true}
secrets:
postgres_password: {file: ./secrets/postgres_password}
minio_root_user: {file: ./secrets/minio_root_user}
minio_root_password: {file: ./secrets/minio_root_password}
grafana_admin_password: {file: ./secrets/grafana_admin_password}
volumes:
pki-ca:
pki:
baodata:
baologs:
pgdata:
s3data:
brokerdata:
promdata:
lokidata:
tempodata:
grafanadata: