lab7: TLS/mTLS по trust matrix, OpenBao (cert auth, KV, policies), роли БД, Argon2id+rehash, лимит входа, hardening, secprobe и тесты
This commit is contained in:
+652
@@ -0,0 +1,652 @@
|
||||
# Lab7 — защищённый мессенджер. Карта доверия: contracts/trust-matrix.md, угрозы: security/THREAT_MODEL.md.
|
||||
#
|
||||
# клиент ─TLS(:8443, CA стенда)→ lb ─mTLS(identity lb)→ api × 2
|
||||
# api / relay / worker / reconciler:
|
||||
# ─TLS verify-full + своя роль БД→ postgres ─TLS + ACL user→ redis (только api)
|
||||
# ─TLS + свой ключ/префиксы→ s3 (MinIO) ─mTLS, SASL EXTERNAL (CN)→ rabbitmq (relay, worker)
|
||||
# ─mTLS (CA телеметрии)→ otel-collector ─mTLS→ tempo / loki; prometheus ─mTLS→ collector
|
||||
# ─TLS + cert auth (тот же сертификат сервиса)→ openbao: роль/ключи БД, S3, Redis
|
||||
# grafana ─mTLS→ prometheus / loki / tempo; оператор → grafana (HTTPS, 127.0.0.1:3000)
|
||||
#
|
||||
# Секреты и ключи создаёт оператор (scripts/bootstrap.py → secrets/, вне Git); в образах их нет.
|
||||
# Запуск из чистого clone: python3 scripts/bootstrap.py all
|
||||
name: mtusi2026lab7
|
||||
|
||||
x-hardened: &hardened
|
||||
# Процессы приложения: non-root (uid 1001 образа), без capabilities, без повышения
|
||||
# привилегий, корневая ФС только чтение; запись — в ограниченный tmpfs /tmp.
|
||||
read_only: true
|
||||
cap_drop: [ALL]
|
||||
security_opt: [no-new-privileges:true]
|
||||
tmpfs:
|
||||
- /tmp:size=64m,mode=1777
|
||||
|
||||
x-app-env: &app-env
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: "8443"
|
||||
APP_ENV: ${APP_ENV:-lab}
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
SESSION_STORE: redis
|
||||
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
||||
DRAIN_DELAY: ${DRAIN_DELAY:-3s}
|
||||
SHUTDOWN_TIMEOUT: ${SHUTDOWN_TIMEOUT:-8s}
|
||||
DB_POOL_MAX: ${DB_POOL_MAX:-20}
|
||||
CACHE_INVALIDATION: ${CACHE_INVALIDATION:-version}
|
||||
S3_ENDPOINT: https://s3:9000
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
|
||||
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
|
||||
PIPELINE_VERSION: ${PIPELINE_VERSION:-1}
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
||||
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-2}
|
||||
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
|
||||
WEBP_QUALITY: ${WEBP_QUALITY:-80}
|
||||
WORKER_PIXEL_BUDGET: ${WORKER_PIXEL_BUDGET:-60000000}
|
||||
RETRY_BASE_DELAY: ${RETRY_BASE_DELAY:-2s}
|
||||
RETRY_MAX_DELAY: ${RETRY_MAX_DELAY:-60s}
|
||||
# TLS: CA стенда и сертификат сервиса (у каждого сервиса свой, под одинаковыми именами)
|
||||
TLS_CA_FILE: /run/secrets/ca.crt
|
||||
TLS_CERT_FILE: /run/secrets/service.crt
|
||||
TLS_KEY_FILE: /run/secrets/service.key
|
||||
# PostgreSQL: адрес; роль и пароль — из OpenBao (secret/messenger/<сервис>)
|
||||
DATABASE_HOST: postgres
|
||||
DATABASE_NAME: messenger
|
||||
REDIS_ADDR: redis:6379
|
||||
BROKER_URL: amqps://rabbitmq:5671/
|
||||
# OpenBao: cert auth тем же сертификатом сервиса, без статического токена
|
||||
BAO_ADDR: https://openbao:8200
|
||||
BAO_CACERT: /run/secrets/ca.crt
|
||||
SECRETS_REFRESH: ${SECRETS_REFRESH:-30s}
|
||||
# Argon2id (обоснование — REPORT.md, замер на стенде)
|
||||
ARGON2_MEMORY_KIB: ${ARGON2_MEMORY_KIB:-19456}
|
||||
ARGON2_ITERATIONS: ${ARGON2_ITERATIONS:-2}
|
||||
ARGON2_PARALLELISM: ${ARGON2_PARALLELISM:-1}
|
||||
ARGON2_MAX_CONCURRENT: ${ARGON2_MAX_CONCURRENT:-2}
|
||||
LOGIN_RATE_PER_USER: ${LOGIN_RATE_PER_USER:-10}
|
||||
LOGIN_RATE_PER_IP: ${LOGIN_RATE_PER_IP:-60}
|
||||
LOGIN_RATE_WINDOW_SECONDS: ${LOGIN_RATE_WINDOW_SECONDS:-60}
|
||||
# OpenTelemetry: HTTPS к Collector, клиентский сертификат CA телеметрии
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
||||
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
||||
OTEL_EXPORTER_OTLP_CERTIFICATE: /run/secrets/ca.crt
|
||||
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: /run/secrets/otel.crt
|
||||
OTEL_EXPORTER_OTLP_CLIENT_KEY: /run/secrets/otel.key
|
||||
OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=lab
|
||||
OTEL_TRACES_SAMPLER: ${OTEL_TRACES_SAMPLER:-parentbased_always_on}
|
||||
OTEL_TRACES_SAMPLER_ARG: ${OTEL_TRACES_SAMPLER_ARG:-1.0}
|
||||
|
||||
services:
|
||||
lb:
|
||||
image: haproxy:3.0.5-alpine
|
||||
<<: *hardened
|
||||
ports:
|
||||
- "127.0.0.1:${LB_PORT:-8443}:8443" # единственный публичный вход, только TLS
|
||||
environment:
|
||||
LB_BALANCE: ${LB_BALANCE:-roundrobin}
|
||||
volumes:
|
||||
- ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: lb_public_pem, target: lb-public.pem }
|
||||
- { source: lb_pem, target: lb.pem }
|
||||
depends_on:
|
||||
api:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
networks: [front]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 128M, pids: 256 }
|
||||
|
||||
api:
|
||||
build: .
|
||||
image: mtusi2026lab7-api:local
|
||||
<<: *hardened
|
||||
environment:
|
||||
<<: *app-env
|
||||
OTEL_SERVICE_NAME: messenger-api
|
||||
BAO_ROLE: api
|
||||
BAO_KV_PATH: messenger/api
|
||||
API_ALLOWED_CLIENTS: lb
|
||||
REVOKED_SERIALS_FILE: /run/secrets/revoked.txt
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: revoked_serials, target: revoked.txt }
|
||||
- { source: api_crt, target: service.crt }
|
||||
- { source: api_key, target: service.key }
|
||||
- { source: api_otel_crt, target: otel.crt }
|
||||
- { source: api_otel_key, target: otel.key }
|
||||
depends_on:
|
||||
postgres: { condition: service_healthy }
|
||||
redis: { condition: service_healthy }
|
||||
openbao: { condition: service_started }
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:8081/health/ready"]
|
||||
interval: 5s
|
||||
timeout: 2s
|
||||
retries: 3
|
||||
start_period: 20s
|
||||
stop_grace_period: 15s
|
||||
restart: unless-stopped
|
||||
networks: [front, back, telemetry]
|
||||
deploy:
|
||||
replicas: ${API_REPLICAS:-2}
|
||||
resources:
|
||||
limits: { cpus: "${API_CPUS:-0.50}", memory: "${API_MEMORY:-256M}", pids: 256 }
|
||||
|
||||
# Миграции — инструмент оператора: владелец схемы messenger, TLS verify-full.
|
||||
migrate:
|
||||
image: migrate/migrate:v4.17.0
|
||||
volumes:
|
||||
- ./migrations:/migrations:ro
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- database_url
|
||||
entrypoint: ["/bin/sh", "-c", "exec migrate -path /migrations -database \"$$(cat /run/secrets/database_url)\" up"]
|
||||
read_only: true
|
||||
cap_drop: [ALL]
|
||||
security_opt: [no-new-privileges:true]
|
||||
depends_on:
|
||||
postgres: { condition: service_healthy }
|
||||
restart: "no"
|
||||
profiles: [ops]
|
||||
networks: [back]
|
||||
|
||||
# PostgreSQL: TLS (ключ копируется в каталог postgres с правами 600 — требование PostgreSQL),
|
||||
# pg_hba: сетевой доступ только hostssl + scram. Stateful-исключение из read_only: entrypoint
|
||||
# образа делает chown/su-exec, поэтому оставлены нужные для этого capabilities.
|
||||
postgres:
|
||||
image: postgres:16.4-alpine
|
||||
entrypoint: ["sh", "-c"]
|
||||
command:
|
||||
- >-
|
||||
install -o postgres -g postgres -m 600 /run/secrets/postgres.key /var/lib/postgresql/server.key &&
|
||||
install -o postgres -g postgres -m 644 /run/secrets/postgres.crt /var/lib/postgresql/server.crt &&
|
||||
exec docker-entrypoint.sh postgres -c max_connections=100 -c ssl=on
|
||||
-c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key
|
||||
-c ssl_min_protocol_version=TLSv1.2 -c hba_file=/etc/postgresql/pg_hba.conf -c password_encryption=scram-sha-256
|
||||
environment:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
POSTGRES_DB: messenger
|
||||
secrets:
|
||||
- postgres_password
|
||||
- { source: postgres_crt, target: postgres.crt }
|
||||
- { source: postgres_key, target: postgres.key }
|
||||
volumes:
|
||||
- pg_data:/var/lib/postgresql/data
|
||||
- ./infra/postgres/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro
|
||||
cap_drop: [ALL]
|
||||
cap_add: [CHOWN, DAC_OVERRIDE, FOWNER, SETUID, SETGID]
|
||||
security_opt: [no-new-privileges:true]
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
restart: unless-stopped
|
||||
networks: [back]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "1.00", memory: 512M, pids: 512 }
|
||||
|
||||
# Redis: только TLS (plaintext-порт 0), ACL из файла оператора (пароли — SHA-256),
|
||||
# пользователь default выключен.
|
||||
redis:
|
||||
image: redis:7.4.1-alpine
|
||||
command:
|
||||
- redis-server
|
||||
- --port
|
||||
- "0"
|
||||
- --tls-port
|
||||
- "6379"
|
||||
- --tls-cert-file
|
||||
- /run/secrets/redis.crt
|
||||
- --tls-key-file
|
||||
- /run/secrets/redis.key
|
||||
- --tls-ca-cert-file
|
||||
- /run/secrets/ca.crt
|
||||
- --tls-auth-clients
|
||||
- "no"
|
||||
- --aclfile
|
||||
- /run/secrets/redis_users.acl
|
||||
- --appendonly
|
||||
- "yes"
|
||||
- --appendfsync
|
||||
- everysec
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: redis_crt, target: redis.crt }
|
||||
- { source: redis_key, target: redis.key }
|
||||
- redis_users.acl
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
cap_drop: [ALL]
|
||||
cap_add: [CHOWN, SETUID, SETGID, DAC_OVERRIDE]
|
||||
security_opt: [no-new-privileges:true]
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "--tls", "--cacert", "/run/secrets/ca.crt", "-h", "redis", "--user", "healthcheck", "--pass", "x", "--no-auth-warning", "ping"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
restart: unless-stopped
|
||||
networks: [back]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 256M, pids: 256 }
|
||||
|
||||
# MinIO RELEASE.2025-04-22 (Bitnami, по digest): только HTTPS, консоль выключена, порты не публикуются.
|
||||
s3:
|
||||
image: bitnamilegacy/minio:2025.4.22@sha256:50cec18ac4184af4671a78aedd5554942c8ae105d51a465fa82037949046da01
|
||||
entrypoint: ["/bin/bash", "-c"]
|
||||
command:
|
||||
- >-
|
||||
mkdir -p /tmp/certs/CAs && cp /run/secrets/s3.crt /tmp/certs/public.crt && cp /run/secrets/s3.key /tmp/certs/private.key &&
|
||||
cp /run/secrets/ca.crt /tmp/certs/CAs/ca.crt &&
|
||||
export MINIO_ROOT_USER="$$(cat /run/secrets/s3_root_user)" MINIO_ROOT_PASSWORD="$$(cat /run/secrets/s3_root_password)";
|
||||
exec /opt/bitnami/minio/bin/minio server /bitnami/minio/data --address :9000 --certs-dir /tmp/certs
|
||||
environment:
|
||||
MINIO_BROWSER: "off"
|
||||
secrets:
|
||||
- s3_root_user
|
||||
- s3_root_password
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: s3_crt, target: s3.crt }
|
||||
- { source: s3_key, target: s3.key }
|
||||
volumes:
|
||||
- s3_data:/bitnami/minio/data
|
||||
<<: *hardened
|
||||
healthcheck:
|
||||
test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/9000"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
restart: unless-stopped
|
||||
networks: [back]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 512M, pids: 256 }
|
||||
|
||||
# Bootstrap MinIO (запускает scripts/bootstrap.py): bucket, политики по префиксам, пользователи сервисов.
|
||||
s3-init:
|
||||
image: bitnamilegacy/minio-client:2025.4.16@sha256:8a86e441decf053093c5977d49290298295f850c7843652f93e970ab15871dd1
|
||||
entrypoint: ["/bin/sh", "/init/init.sh"]
|
||||
environment:
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
PATH: /opt/bitnami/minio-client/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
MC_CONFIG_DIR: /tmp/.mc
|
||||
secrets:
|
||||
- s3_root_user
|
||||
- s3_root_password
|
||||
- s3_users
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
volumes:
|
||||
- ./infra/s3:/init:ro
|
||||
<<: *hardened
|
||||
depends_on:
|
||||
s3: { condition: service_healthy }
|
||||
restart: "no"
|
||||
profiles: [ops]
|
||||
networks: [back]
|
||||
|
||||
reconciler:
|
||||
image: mtusi2026lab7-api:local
|
||||
<<: *hardened
|
||||
entrypoint: ["/app/reconcile", "--apply", "--interval", "${RECONCILE_INTERVAL:-10m}", "--grace", "${RECONCILE_GRACE:-1h}"]
|
||||
environment:
|
||||
<<: *app-env
|
||||
BAO_ROLE: reconciler
|
||||
BAO_KV_PATH: messenger/reconciler
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: reconciler_crt, target: service.crt }
|
||||
- { source: reconciler_key, target: service.key }
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pgrep -x reconcile >/dev/null || pidof reconcile >/dev/null"]
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 3
|
||||
start_period: 5s
|
||||
depends_on:
|
||||
postgres: { condition: service_healthy }
|
||||
openbao: { condition: service_started }
|
||||
restart: unless-stopped
|
||||
networks: [back]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M, pids: 128 }
|
||||
|
||||
# RabbitMQ: только AMQPS (5671) с обязательным клиентским сертификатом, SASL EXTERNAL.
|
||||
rabbitmq:
|
||||
image: rabbitmq:4.0.9-alpine
|
||||
hostname: rabbitmq
|
||||
volumes:
|
||||
- rabbitmq_data:/var/lib/rabbitmq
|
||||
- ./infra/rabbitmq/rabbitmq.conf:/etc/rabbitmq/conf.d/30-lab7.conf:ro
|
||||
- ./infra/rabbitmq/enabled_plugins:/etc/rabbitmq/enabled_plugins:ro
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: rabbitmq_crt, target: rabbitmq.crt }
|
||||
- { source: rabbitmq_key, target: rabbitmq.key }
|
||||
cap_drop: [ALL]
|
||||
cap_add: [CHOWN, DAC_OVERRIDE, FOWNER, SETUID, SETGID]
|
||||
security_opt: [no-new-privileges:true]
|
||||
healthcheck:
|
||||
test: ["CMD", "rabbitmq-diagnostics", "-q", "check_port_connectivity"]
|
||||
interval: 5s
|
||||
timeout: 10s
|
||||
retries: 30
|
||||
start_period: 15s
|
||||
restart: unless-stopped
|
||||
networks: [back, telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 512M, pids: 512 }
|
||||
|
||||
relay:
|
||||
image: mtusi2026lab7-api:local
|
||||
<<: *hardened
|
||||
entrypoint: ["/app/pipeline", "relay"]
|
||||
environment:
|
||||
<<: *app-env
|
||||
OTEL_SERVICE_NAME: messenger-relay
|
||||
BAO_ROLE: relay
|
||||
BAO_KV_PATH: messenger/relay
|
||||
BROKER_DECLARE: "true"
|
||||
FAULT_POINTS: ${RELAY_FAULT_POINTS:-}
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: relay_crt, target: service.crt }
|
||||
- { source: relay_key, target: service.key }
|
||||
- { source: relay_otel_crt, target: otel.crt }
|
||||
- { source: relay_otel_key, target: otel.key }
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pgrep -x pipeline >/dev/null || pidof pipeline >/dev/null"]
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 3
|
||||
start_period: 5s
|
||||
depends_on:
|
||||
postgres: { condition: service_healthy }
|
||||
rabbitmq: { condition: service_healthy }
|
||||
openbao: { condition: service_started }
|
||||
restart: unless-stopped
|
||||
networks: [back, telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M, pids: 128 }
|
||||
|
||||
# Worker: отдельная identity (CN worker-gN): своя роль БД, ключ S3 только s/ v/ o/,
|
||||
# в RabbitMQ — только чтение attachment.process. CPU/RAM/время ограничены.
|
||||
worker:
|
||||
image: mtusi2026lab7-api:local
|
||||
<<: *hardened
|
||||
tmpfs:
|
||||
- /tmp:size=256m,mode=1777 # cwebp: временный PNG/WebP одного изображения
|
||||
entrypoint: ["/app/pipeline", "worker"]
|
||||
environment:
|
||||
<<: *app-env
|
||||
OTEL_SERVICE_NAME: messenger-worker
|
||||
BAO_ROLE: worker
|
||||
BAO_KV_PATH: messenger/worker
|
||||
BROKER_DECLARE: "false"
|
||||
FAULT_POINTS: ${WORKER_FAULT_POINTS:-}
|
||||
GOMEMLIMIT: ${WORKER_GOMEMLIMIT:-560MiB}
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: worker_crt, target: service.crt }
|
||||
- { source: worker_key, target: service.key }
|
||||
- { source: worker_otel_crt, target: otel.crt }
|
||||
- { source: worker_otel_key, target: otel.key }
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pgrep -x pipeline >/dev/null || pidof pipeline >/dev/null"]
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 3
|
||||
start_period: 5s
|
||||
stop_grace_period: 70s
|
||||
depends_on:
|
||||
postgres: { condition: service_healthy }
|
||||
rabbitmq: { condition: service_healthy }
|
||||
openbao: { condition: service_started }
|
||||
restart: unless-stopped
|
||||
networks: [back, telemetry]
|
||||
deploy:
|
||||
replicas: ${WORKER_REPLICAS:-1}
|
||||
resources:
|
||||
limits: { cpus: "${WORKER_CPUS:-1.00}", memory: "${WORKER_MEMORY:-768M}", pids: 128 }
|
||||
|
||||
# OpenBao: не dev-mode, файловое хранилище на volume, TLS. Init/unseal — оператор
|
||||
# (scripts/bootstrap.py); после рестарта OpenBao запечатан до unseal, приложения
|
||||
# продолжают работать на полученных ранее секретах.
|
||||
openbao:
|
||||
image: openbao/openbao:2.1.0
|
||||
command: ["server", "-config=/openbao/config/config.hcl"]
|
||||
environment:
|
||||
SKIP_SETCAP: "true"
|
||||
volumes:
|
||||
- ./infra/openbao/config.hcl:/openbao/config/config.hcl:ro
|
||||
- ./infra/openbao/policies:/openbao/policies:ro
|
||||
- bao_data:/openbao/file
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: openbao_crt, target: openbao.crt }
|
||||
- { source: openbao_key, target: openbao.key }
|
||||
cap_drop: [ALL]
|
||||
cap_add: [CHOWN, DAC_OVERRIDE, FOWNER, SETUID, SETGID]
|
||||
security_opt: [no-new-privileges:true]
|
||||
ports:
|
||||
- "127.0.0.1:${BAO_PORT:-8200}:8200" # только оператору на хосте, TLS
|
||||
restart: unless-stopped
|
||||
networks: [back]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 256M, pids: 256 }
|
||||
|
||||
# ---------------- Наблюдаемость (lab6), всё по TLS/mTLS ----------------
|
||||
otel-collector:
|
||||
image: otel/opentelemetry-collector-contrib:0.116.1
|
||||
<<: *hardened
|
||||
command: ["--config=/etc/otelcol/${COLLECTOR_CONFIG:-collector.yaml}"]
|
||||
volumes:
|
||||
- ./infra/otel:/etc/otelcol:ro
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: tca_crt, target: tca.crt }
|
||||
- { source: otel_collector_crt, target: otel-collector.crt }
|
||||
- { source: otel_collector_key, target: otel-collector.key }
|
||||
restart: unless-stopped
|
||||
networks: [telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 256M, pids: 256 }
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:v3.1.0
|
||||
<<: *hardened
|
||||
command:
|
||||
- --config.file=/etc/prometheus/prometheus.yml
|
||||
- --web.config.file=/etc/prometheus/web.yml
|
||||
- --storage.tsdb.path=/prometheus
|
||||
- --storage.tsdb.retention.time=7d
|
||||
- --enable-feature=exemplar-storage
|
||||
volumes:
|
||||
- ./infra/prometheus:/etc/prometheus:ro
|
||||
- prometheus_data:/prometheus
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: prometheus_crt, target: prometheus.crt }
|
||||
- { source: prometheus_key, target: prometheus.key }
|
||||
restart: unless-stopped
|
||||
networks: [telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 512M, pids: 256 }
|
||||
|
||||
loki:
|
||||
image: grafana/loki:3.3.2
|
||||
<<: *hardened
|
||||
command: ["-config.file=/etc/loki/loki.yaml"]
|
||||
volumes:
|
||||
- ./infra/loki/loki.yaml:/etc/loki/loki.yaml:ro
|
||||
- loki_data:/loki
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: loki_crt, target: loki.crt }
|
||||
- { source: loki_key, target: loki.key }
|
||||
restart: unless-stopped
|
||||
networks: [telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 512M, pids: 256 }
|
||||
|
||||
tempo-init:
|
||||
image: &tempo-image grafana/tempo:2.6.1
|
||||
user: root
|
||||
entrypoint: ["chown", "10001:10001", "/var/tempo"]
|
||||
cap_drop: [ALL]
|
||||
cap_add: [CHOWN]
|
||||
volumes:
|
||||
- tempo_data:/var/tempo
|
||||
restart: "no"
|
||||
networks: [telemetry]
|
||||
tempo:
|
||||
image: *tempo-image
|
||||
<<: *hardened
|
||||
command: ["-config.file=/etc/tempo/tempo.yaml"]
|
||||
volumes:
|
||||
- ./infra/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro
|
||||
- tempo_data:/var/tempo
|
||||
secrets:
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: tempo_crt, target: tempo.crt }
|
||||
- { source: tempo_key, target: tempo.key }
|
||||
depends_on:
|
||||
tempo-init: { condition: service_completed_successfully }
|
||||
restart: unless-stopped
|
||||
networks: [telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 512M, pids: 256 }
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:11.4.0
|
||||
cap_drop: [ALL]
|
||||
security_opt: [no-new-privileges:true]
|
||||
environment:
|
||||
GF_SERVER_PROTOCOL: https
|
||||
GF_SERVER_CERT_FILE: /run/secrets/grafana.crt
|
||||
GF_SERVER_CERT_KEY: /run/secrets/grafana.key
|
||||
GF_SECURITY_ADMIN_USER: admin
|
||||
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_admin_password
|
||||
GF_USERS_ALLOW_SIGN_UP: "false"
|
||||
GF_ANALYTICS_REPORTING_ENABLED: "false"
|
||||
GF_ANALYTICS_CHECK_FOR_UPDATES: "false"
|
||||
GF_AUTH_ANONYMOUS_ENABLED: "false"
|
||||
secrets:
|
||||
- grafana_admin_password
|
||||
- { source: ca_crt, target: ca.crt }
|
||||
- { source: grafana_crt, target: grafana.crt }
|
||||
- { source: grafana_key, target: grafana.key }
|
||||
volumes:
|
||||
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
||||
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
||||
- grafana_data:/var/lib/grafana
|
||||
ports:
|
||||
- "127.0.0.1:${GRAFANA_PORT:-3000}:3000" # оператор, HTTPS
|
||||
depends_on:
|
||||
prometheus: { condition: service_started }
|
||||
loki: { condition: service_started }
|
||||
tempo: { condition: service_started }
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "--spider", "--no-check-certificate", "https://localhost:3000/api/health"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
restart: unless-stopped
|
||||
networks: [telemetry]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.50", memory: 256M, pids: 256 }
|
||||
|
||||
# Тестовый зонд отрицательных проверок (profile test): во всех сетях, сертификаты
|
||||
# стенда и тестовые (чужой CA, запрещённая identity) — только чтение.
|
||||
probe:
|
||||
build:
|
||||
context: .
|
||||
target: probe
|
||||
image: mtusi2026lab7-probe:local
|
||||
<<: *hardened
|
||||
user: "${PROBE_UID:-1001}" # каталог secrets/pki — 700 владельца стенда
|
||||
volumes:
|
||||
- ./secrets/pki:/pki:ro
|
||||
profiles: [test]
|
||||
networks: [front, back, telemetry]
|
||||
|
||||
networks:
|
||||
front:
|
||||
back:
|
||||
telemetry:
|
||||
|
||||
secrets:
|
||||
# оператор (scripts/init-secrets.sh, scripts/bootstrap.py) — значения вне Git
|
||||
postgres_password: { file: ./secrets/postgres_password }
|
||||
database_url: { file: ./secrets/database_url }
|
||||
s3_root_user: { file: ./secrets/s3_root_user }
|
||||
s3_root_password: { file: ./secrets/s3_root_password }
|
||||
grafana_admin_password: { file: ./secrets/grafana_admin_password }
|
||||
s3_users: { file: ./secrets/operator/s3_users.txt }
|
||||
redis_users.acl: { file: ./secrets/operator/redis_users.acl }
|
||||
# PKI (scripts/pki.sh): CA — только сертификаты; ключи CA в контейнеры не попадают
|
||||
ca_crt: { file: ./secrets/pki/ca.crt }
|
||||
tca_crt: { file: ./secrets/pki/tca.crt }
|
||||
revoked_serials: { file: ./secrets/pki/revoked.txt }
|
||||
lb_public_pem: { file: ./secrets/pki/lb-public.pem }
|
||||
lb_pem: { file: ./secrets/pki/lb.pem }
|
||||
api_crt: { file: ./secrets/pki/api.crt }
|
||||
api_key: { file: ./secrets/pki/api.key }
|
||||
api_otel_crt: { file: ./secrets/pki/api-otel.crt }
|
||||
api_otel_key: { file: ./secrets/pki/api-otel.key }
|
||||
worker_crt: { file: ./secrets/pki/worker.crt }
|
||||
worker_key: { file: ./secrets/pki/worker.key }
|
||||
worker_otel_crt: { file: ./secrets/pki/worker-otel.crt }
|
||||
worker_otel_key: { file: ./secrets/pki/worker-otel.key }
|
||||
relay_crt: { file: ./secrets/pki/relay.crt }
|
||||
relay_key: { file: ./secrets/pki/relay.key }
|
||||
relay_otel_crt: { file: ./secrets/pki/relay-otel.crt }
|
||||
relay_otel_key: { file: ./secrets/pki/relay-otel.key }
|
||||
reconciler_crt: { file: ./secrets/pki/reconciler.crt }
|
||||
reconciler_key: { file: ./secrets/pki/reconciler.key }
|
||||
postgres_crt: { file: ./secrets/pki/postgres.crt }
|
||||
postgres_key: { file: ./secrets/pki/postgres.key }
|
||||
redis_crt: { file: ./secrets/pki/redis.crt }
|
||||
redis_key: { file: ./secrets/pki/redis.key }
|
||||
s3_crt: { file: ./secrets/pki/s3.crt }
|
||||
s3_key: { file: ./secrets/pki/s3.key }
|
||||
rabbitmq_crt: { file: ./secrets/pki/rabbitmq.crt }
|
||||
rabbitmq_key: { file: ./secrets/pki/rabbitmq.key }
|
||||
openbao_crt: { file: ./secrets/pki/openbao.crt }
|
||||
openbao_key: { file: ./secrets/pki/openbao.key }
|
||||
otel_collector_crt: { file: ./secrets/pki/otel-collector.crt }
|
||||
otel_collector_key: { file: ./secrets/pki/otel-collector.key }
|
||||
prometheus_crt: { file: ./secrets/pki/prometheus.crt }
|
||||
prometheus_key: { file: ./secrets/pki/prometheus.key }
|
||||
loki_crt: { file: ./secrets/pki/loki.crt }
|
||||
loki_key: { file: ./secrets/pki/loki.key }
|
||||
tempo_crt: { file: ./secrets/pki/tempo.crt }
|
||||
tempo_key: { file: ./secrets/pki/tempo.key }
|
||||
grafana_crt: { file: ./secrets/pki/grafana.crt }
|
||||
grafana_key: { file: ./secrets/pki/grafana.key }
|
||||
|
||||
volumes:
|
||||
bao_data:
|
||||
prometheus_data:
|
||||
loki_data:
|
||||
tempo_data:
|
||||
grafana_data:
|
||||
rabbitmq_data:
|
||||
s3_data:
|
||||
pg_data:
|
||||
redis_data:
|
||||
Reference in New Issue
Block a user