Закрыть внешний вход TLS и выдавать секреты через OpenBao.
LB ходит в API только с клиентским сертификатом нужной identity, остальные связи проверяют серверный сертификат, root token в приложение не попадает. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+465
-150
@@ -1,15 +1,225 @@
|
||||
# Client -> lb:8080 -> api x2 -> Postgres + Redis + private SeaweedFS S3 + RabbitMQ.
|
||||
# Worker is a separate process and is the only place that resizes images.
|
||||
# API and worker export OTLP to the collector. Prometheus, Loki, Tempo and Grafana
|
||||
# keep metrics, logs and traces. The collector is not required for the API to start.
|
||||
# API replicas do not publish host ports. MinIO console is not published.
|
||||
# API replicas do not publish host ports. Migrations run once in `migrate`.
|
||||
# Check period: HAProxy inter 1s, fall 2, rise 1. Worst detection of a dead
|
||||
# or not-ready replica is about 2s, plus the 1s DNS hold. API on SIGTERM
|
||||
# fails /health/ready immediately and exits after LB_DRAIN_SECONDS (default 2).
|
||||
# Client -TLS-> lb:8443 -mTLS-> api x2. API listens on 127.0.0.1 only.
|
||||
# Postgres, Redis, RabbitMQ (via local mTLS proxy), S3 (via local TLS proxy),
|
||||
# the collector and OpenBao are TLS. Secrets are read from OpenBao with AppRole.
|
||||
# Run scripts/bootstrap.ps1 before the first start: it creates certs, unseals
|
||||
# OpenBao and does not print secret values.
|
||||
|
||||
x-app-hardening: &app-hardening
|
||||
read_only: true
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
cap_drop:
|
||||
- ALL
|
||||
tmpfs:
|
||||
- /tmp:rw,nosuid,size=64m
|
||||
pids_limit: 128
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16.6-alpine
|
||||
environment:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/db_super_password
|
||||
POSTGRES_DB: messenger
|
||||
entrypoint: ["/bin/sh", "/entrypoint.sh"]
|
||||
volumes:
|
||||
- pg_data:/var/lib/postgresql/data
|
||||
- ./infra/postgres/entrypoint.sh:/entrypoint.sh:ro
|
||||
- ./infra/postgres/pg_hba.conf:/etc/postgres/pg_hba.conf:ro
|
||||
- ./infra/postgres/grant.sh:/etc/postgres/grant.sh:ro
|
||||
- ./certs/postgres.crt:/certs/postgres.crt:ro
|
||||
- ./certs/postgres.key:/certs/postgres.key:ro
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
secrets:
|
||||
- db_super_password
|
||||
- db_api_password
|
||||
- db_worker_password
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
||||
interval: 3s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
restart: unless-stopped
|
||||
mem_limit: ${POSTGRES_MEM:-512m}
|
||||
cpus: ${POSTGRES_CPUS:-1.0}
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
networks: [data]
|
||||
|
||||
redis:
|
||||
image: redis:7.4.2-alpine
|
||||
entrypoint: ["/bin/sh", "/entrypoint.sh"]
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
- ./infra/redis/entrypoint.sh:/entrypoint.sh:ro
|
||||
- ./certs/redis.crt:/certs/redis.crt:ro
|
||||
- ./certs/redis.key:/certs/redis.key:ro
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
secrets:
|
||||
- redis_password
|
||||
healthcheck:
|
||||
test:
|
||||
[
|
||||
"CMD-SHELL",
|
||||
"redis-cli --tls --cacert /tmp/ca.crt -p 6379 --user api --pass \"$$(cat /run/secrets/redis_password)\" ping | grep -q PONG",
|
||||
]
|
||||
interval: 3s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
restart: unless-stopped
|
||||
mem_limit: 128m
|
||||
cpus: "0.50"
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
networks: [data]
|
||||
|
||||
rabbitmq:
|
||||
image: rabbitmq:3.13.7-alpine
|
||||
hostname: rabbitmq
|
||||
entrypoint: ["/bin/sh", "/entrypoint.sh"]
|
||||
environment:
|
||||
RABBITMQ_DEFAULT_USER: messenger_api
|
||||
RABBITMQ_DEFAULT_PASS_FILE: /run/secrets/rabbit_api_password
|
||||
volumes:
|
||||
- rabbitmq_data:/var/lib/rabbitmq
|
||||
- ./infra/rabbitmq/entrypoint.sh:/entrypoint.sh:ro
|
||||
- ./certs/rabbitmq.crt:/certs/rabbitmq.crt:ro
|
||||
- ./certs/rabbitmq.key:/certs/rabbitmq.key:ro
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
secrets:
|
||||
- rabbit_api_password
|
||||
- rabbit_worker_password
|
||||
healthcheck:
|
||||
test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 20
|
||||
start_period: 20s
|
||||
restart: unless-stopped
|
||||
mem_limit: 256m
|
||||
cpus: "0.50"
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
networks: [data]
|
||||
|
||||
rabbit-mtls:
|
||||
image: haproxy:3.1.7-alpine
|
||||
network_mode: service:rabbitmq
|
||||
depends_on:
|
||||
rabbitmq:
|
||||
condition: service_started
|
||||
volumes:
|
||||
- ./infra/haproxy-rabbit.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
- ./certs/rabbitmq.pem:/certs/rabbitmq.pem:ro
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp:rw,nosuid,size=16m
|
||||
- /var/run:rw,nosuid,size=8m
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
restart: unless-stopped
|
||||
|
||||
s3:
|
||||
image: chrislusf/seaweedfs:3.85
|
||||
entrypoint: ["/bin/sh", "/seaweed-entrypoint.sh"]
|
||||
environment:
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
ports:
|
||||
- "127.0.0.1:9000:9000"
|
||||
volumes:
|
||||
- s3_data:/data
|
||||
- ./infra/s3/seaweed-entrypoint.sh:/seaweed-entrypoint.sh:ro
|
||||
secrets:
|
||||
- s3_admin_access
|
||||
- s3_admin_secret
|
||||
- s3_api_access
|
||||
- s3_api_secret
|
||||
- s3_worker_access
|
||||
- s3_worker_secret
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:9333/cluster/status || exit 1"]
|
||||
interval: 3s
|
||||
timeout: 5s
|
||||
retries: 20
|
||||
start_period: 8s
|
||||
restart: unless-stopped
|
||||
mem_limit: 256m
|
||||
cpus: "0.50"
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
networks: [data]
|
||||
|
||||
s3-tls:
|
||||
image: haproxy:3.1.7-alpine
|
||||
network_mode: service:s3
|
||||
depends_on:
|
||||
s3:
|
||||
condition: service_started
|
||||
volumes:
|
||||
- ./infra/haproxy-s3.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
- ./certs/s3.pem:/certs/s3.pem:ro
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp:rw,nosuid,size=16m
|
||||
- /var/run:rw,nosuid,size=8m
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
restart: unless-stopped
|
||||
|
||||
openbao:
|
||||
image: openbao/openbao:2.2.0
|
||||
entrypoint: ["bao"]
|
||||
command: ["server", "-config=/openbao/config/openbao.hcl"]
|
||||
volumes:
|
||||
- bao_data:/openbao/file
|
||||
- ./infra/openbao/openbao.hcl:/openbao/config/openbao.hcl:ro
|
||||
- ./certs/openbao.crt:/certs/openbao.crt:ro
|
||||
- ./certs/openbao.key:/certs/openbao.key:ro
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
healthcheck:
|
||||
test: ["CMD", "bao", "status", "-address=https://127.0.0.1:8200", "-ca-cert=/certs/ca.crt"]
|
||||
interval: 3s
|
||||
timeout: 3s
|
||||
retries: 40
|
||||
start_period: 5s
|
||||
restart: unless-stopped
|
||||
mem_limit: 256m
|
||||
cpus: "0.50"
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
networks: [data]
|
||||
|
||||
openbao-bootstrap:
|
||||
profiles: ["bootstrap"]
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: mtusi-messenger:lab7
|
||||
command: ["python", "-m", "app.tools.openbao_bootstrap"]
|
||||
environment:
|
||||
BAO_ADDR: https://openbao:8200
|
||||
TLS_CA_FILE: /certs/ca.crt
|
||||
BAO_INIT_FILE: /secrets/openbao-init.json
|
||||
volumes:
|
||||
- ./secrets:/secrets
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
- ./infra/openbao/policies:/policies:ro
|
||||
- ./evidence:/evidence
|
||||
networks: [data]
|
||||
depends_on:
|
||||
openbao:
|
||||
condition: service_started
|
||||
restart: "no"
|
||||
|
||||
migrate:
|
||||
<<: *app-hardening
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
@@ -18,31 +228,76 @@ services:
|
||||
environment:
|
||||
APP_ENV: lab
|
||||
LOG_LEVEL: info
|
||||
DATABASE_URL: postgresql://messenger:${POSTGRES_PASSWORD}@postgres:5432/messenger
|
||||
TLS_CA_FILE: /certs/ca.crt
|
||||
BAO_ADDR: https://openbao:8200
|
||||
BAO_CACERT: /certs/ca.crt
|
||||
BAO_ROLE_ID_FILE: /run/secrets/migrate_role_id
|
||||
BAO_SECRET_ID_FILE: /run/secrets/migrate_secret_id
|
||||
BAO_SECRET_PATH: secret/data/messenger/migrate
|
||||
DB_POOL_MIN: "1"
|
||||
DB_POOL_MAX: "2"
|
||||
MIGRATIONS_ON_START: "1"
|
||||
secrets:
|
||||
- source: migrate_role_id
|
||||
target: migrate_role_id
|
||||
- source: migrate_secret_id
|
||||
target: migrate_secret_id
|
||||
volumes:
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
openbao:
|
||||
condition: service_healthy
|
||||
restart: "no"
|
||||
mem_limit: 256m
|
||||
cpus: "0.50"
|
||||
networks: [data]
|
||||
|
||||
s3-init:
|
||||
<<: *app-hardening
|
||||
image: mtusi-messenger:lab7
|
||||
command: ["python", "-m", "app.s3bootstrap"]
|
||||
environment:
|
||||
S3_ENDPOINT: https://s3:9000
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
TLS_CA_FILE: /certs/ca.crt
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_admin_access
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_admin_secret
|
||||
secrets:
|
||||
- source: s3_admin_access
|
||||
target: s3_admin_access
|
||||
- source: s3_admin_secret
|
||||
target: s3_admin_secret
|
||||
volumes:
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
depends_on:
|
||||
s3:
|
||||
condition: service_healthy
|
||||
s3-tls:
|
||||
condition: service_started
|
||||
restart: "no"
|
||||
networks: [data]
|
||||
|
||||
api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
<<: *app-hardening
|
||||
image: mtusi-messenger:lab7
|
||||
environment:
|
||||
APP_HOST: 0.0.0.0
|
||||
command: ["sh", "/scripts/api-entrypoint.sh"]
|
||||
environment: &api-env
|
||||
APP_HOST: 127.0.0.1
|
||||
APP_PORT: "8080"
|
||||
MTLS_PORT: "8443"
|
||||
APP_ENV: lab
|
||||
LOG_LEVEL: info
|
||||
TELEMETRY_ENABLED: ${TELEMETRY_ENABLED:-1}
|
||||
TRACE_SAMPLE_RATIO: ${TRACE_SAMPLE_RATIO:-1}
|
||||
OTEL_SERVICE_NAME: messenger-api
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
||||
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
||||
OTEL_EXPORTER_OTLP_CERTIFICATE: /certs/ca.crt
|
||||
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: /certs/api-client.crt
|
||||
OTEL_EXPORTER_OTLP_CLIENT_KEY: /certs/api-client.key
|
||||
SERVICE_VERSION: lab7
|
||||
SHUTDOWN_GRACE_SECONDS: "3"
|
||||
LB_DRAIN_SECONDS: ${LB_DRAIN_SECONDS:-2}
|
||||
@@ -50,28 +305,52 @@ services:
|
||||
CACHE_TTL_SECONDS: ${CACHE_TTL_SECONDS:-60}
|
||||
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
||||
SESSION_STORE: redis
|
||||
DATABASE_URL: postgresql://messenger:${POSTGRES_PASSWORD}@postgres:5432/messenger
|
||||
REDIS_URL: redis://redis:6379/0
|
||||
S3_ENDPOINT: http://s3:9000
|
||||
S3_ENDPOINT: https://s3:9000
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID}
|
||||
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY}
|
||||
S3_PUBLIC_ENDPOINT: ${S3_PUBLIC_ENDPOINT:-https://127.0.0.1:9000}
|
||||
PRESIGN_TTL_SECONDS: ${PRESIGN_TTL_SECONDS:-60}
|
||||
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
|
||||
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
|
||||
ORPHAN_GRACE_SECONDS: ${ORPHAN_GRACE_SECONDS:-120}
|
||||
BROKER_URL: amqp://messenger:${RABBITMQ_PASSWORD}@rabbitmq:5672/
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
||||
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
|
||||
S3_SWEEP_INTERVAL_SECONDS: ${S3_SWEEP_INTERVAL_SECONDS:-30}
|
||||
S3_PUBLIC_ENDPOINT: ${S3_PUBLIC_ENDPOINT:-http://127.0.0.1:9000}
|
||||
PRESIGN_TTL_SECONDS: ${PRESIGN_TTL_SECONDS:-60}
|
||||
TLS_CA_FILE: /certs/ca.crt
|
||||
TLS_CERT_FILE: /certs/api-client.crt
|
||||
TLS_KEY_FILE: /certs/api-client.key
|
||||
TLS_SERVER_CERT_FILE: /certs/api.crt
|
||||
TLS_SERVER_KEY_FILE: /certs/api.key
|
||||
MTLS_ALLOW_FILE: /certs/allowed-lb.sha256
|
||||
BAO_ADDR: https://openbao:8200
|
||||
BAO_CACERT: /certs/ca.crt
|
||||
BAO_ROLE_ID_FILE: /run/secrets/api_role_id
|
||||
BAO_SECRET_ID_FILE: /run/secrets/api_secret_id
|
||||
BAO_SECRET_PATH: secret/data/messenger/api
|
||||
ARGON2_MEMORY_KIB: ${ARGON2_MEMORY_KIB:-19456}
|
||||
ARGON2_ITERATIONS: ${ARGON2_ITERATIONS:-2}
|
||||
ARGON2_PARALLELISM: ${ARGON2_PARALLELISM:-1}
|
||||
LOGIN_RATE_LIMIT: ${LOGIN_RATE_LIMIT:-8}
|
||||
LOGIN_RATE_WINDOW_SECONDS: ${LOGIN_RATE_WINDOW_SECONDS:-60}
|
||||
DB_POOL_MIN: "1"
|
||||
DB_POOL_MAX: ${DB_POOL_MAX:-4}
|
||||
DB_COMMAND_TIMEOUT: "5"
|
||||
DB_CONNECT_TIMEOUT: "5"
|
||||
MIGRATIONS_ON_START: "0"
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
||||
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
|
||||
secrets:
|
||||
- source: api_role_id
|
||||
target: api_role_id
|
||||
- source: api_secret_id
|
||||
target: api_secret_id
|
||||
volumes:
|
||||
- ./scripts/api-entrypoint.sh:/scripts/api-entrypoint.sh:ro
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
- ./certs/api.crt:/certs/api.crt:ro
|
||||
- ./certs/api.key:/certs/api.key:ro
|
||||
- ./certs/api-client.crt:/certs/api-client.crt:ro
|
||||
- ./certs/api-client.key:/certs/api-client.key:ro
|
||||
- ./certs/allowed-lb.sha256:/certs/allowed-lb.sha256:ro
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
@@ -83,10 +362,14 @@ services:
|
||||
condition: service_completed_successfully
|
||||
rabbitmq:
|
||||
condition: service_healthy
|
||||
rabbit-mtls:
|
||||
condition: service_started
|
||||
openbao:
|
||||
condition: service_healthy
|
||||
expose:
|
||||
- "8080"
|
||||
- "8443"
|
||||
restart: unless-stopped
|
||||
mem_limit: ${API_MEM:-256m}
|
||||
mem_limit: ${API_MEM:-384m}
|
||||
cpus: ${API_CPUS:-0.50}
|
||||
stop_grace_period: 8s
|
||||
healthcheck:
|
||||
@@ -99,105 +382,37 @@ services:
|
||||
]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 6
|
||||
start_period: 5s
|
||||
retries: 12
|
||||
start_period: 15s
|
||||
networks: [app, data, signals]
|
||||
|
||||
lb:
|
||||
image: haproxy:2.8.14-alpine
|
||||
image: haproxy:3.1.7-alpine
|
||||
volumes:
|
||||
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
- ./certs/lb.pem:/certs/lb.pem:ro
|
||||
- ./certs/lb-client.pem:/certs/lb-client.pem:ro
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
ports:
|
||||
- "127.0.0.1:8080:8080"
|
||||
- "127.0.0.1:8443:8443"
|
||||
depends_on:
|
||||
api:
|
||||
condition: service_started
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp:rw,nosuid,size=16m
|
||||
- /var/run:rw,nosuid,size=8m
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
restart: unless-stopped
|
||||
mem_limit: 128m
|
||||
cpus: "0.25"
|
||||
|
||||
postgres:
|
||||
image: postgres:16.6-alpine
|
||||
environment:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
POSTGRES_DB: messenger
|
||||
volumes:
|
||||
- pg_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
||||
interval: 3s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
restart: unless-stopped
|
||||
mem_limit: ${POSTGRES_MEM:-512m}
|
||||
cpus: ${POSTGRES_CPUS:-1.0}
|
||||
|
||||
s3:
|
||||
image: chrislusf/seaweedfs:3.85
|
||||
entrypoint: ["/bin/sh", "/seaweed-entrypoint.sh"]
|
||||
environment:
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID}
|
||||
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY}
|
||||
ports:
|
||||
- "127.0.0.1:9000:9000"
|
||||
volumes:
|
||||
- s3_data:/data
|
||||
- ./infra/s3/seaweed-entrypoint.sh:/seaweed-entrypoint.sh:ro
|
||||
healthcheck:
|
||||
test:
|
||||
[
|
||||
"CMD-SHELL",
|
||||
"wget -q -O /dev/null http://127.0.0.1:9333/cluster/status || exit 1; wget -q -O /dev/null http://127.0.0.1:9000/ || test $$? -ne 4",
|
||||
]
|
||||
interval: 3s
|
||||
timeout: 5s
|
||||
retries: 20
|
||||
start_period: 8s
|
||||
restart: unless-stopped
|
||||
mem_limit: 256m
|
||||
cpus: "0.50"
|
||||
|
||||
s3-init:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: mtusi-messenger:lab7
|
||||
command: ["python", "-m", "app.s3bootstrap"]
|
||||
environment:
|
||||
S3_ENDPOINT: http://s3:9000
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID}
|
||||
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY}
|
||||
depends_on:
|
||||
s3:
|
||||
condition: service_healthy
|
||||
restart: "no"
|
||||
|
||||
rabbitmq:
|
||||
image: rabbitmq:3.13.7-alpine
|
||||
hostname: rabbitmq
|
||||
environment:
|
||||
RABBITMQ_DEFAULT_USER: messenger
|
||||
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASSWORD}
|
||||
RABBITMQ_DEFAULT_VHOST: /
|
||||
volumes:
|
||||
- rabbitmq_data:/var/lib/rabbitmq
|
||||
healthcheck:
|
||||
test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 20
|
||||
start_period: 15s
|
||||
restart: unless-stopped
|
||||
mem_limit: 256m
|
||||
cpus: "0.50"
|
||||
networks: [app]
|
||||
|
||||
worker:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
<<: *app-hardening
|
||||
image: mtusi-messenger:lab7
|
||||
command: ["python", "-m", "app.worker"]
|
||||
environment:
|
||||
@@ -206,17 +421,25 @@ services:
|
||||
TELEMETRY_ENABLED: ${TELEMETRY_ENABLED:-1}
|
||||
TRACE_SAMPLE_RATIO: ${TRACE_SAMPLE_RATIO:-1}
|
||||
OTEL_SERVICE_NAME: messenger-worker
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
||||
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
||||
OTEL_EXPORTER_OTLP_CERTIFICATE: /certs/ca.crt
|
||||
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: /certs/worker-client.crt
|
||||
OTEL_EXPORTER_OTLP_CLIENT_KEY: /certs/worker-client.key
|
||||
SERVICE_VERSION: lab7
|
||||
DATABASE_URL: postgresql://messenger:${POSTGRES_PASSWORD}@postgres:5432/messenger
|
||||
S3_ENDPOINT: http://s3:9000
|
||||
S3_ENDPOINT: https://s3:9000
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID}
|
||||
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY}
|
||||
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
|
||||
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
|
||||
BROKER_URL: amqp://messenger:${RABBITMQ_PASSWORD}@rabbitmq:5672/
|
||||
TLS_CA_FILE: /certs/ca.crt
|
||||
TLS_CERT_FILE: /certs/worker-client.crt
|
||||
TLS_KEY_FILE: /certs/worker-client.key
|
||||
BAO_ADDR: https://openbao:8200
|
||||
BAO_CACERT: /certs/ca.crt
|
||||
BAO_ROLE_ID_FILE: /run/secrets/worker_role_id
|
||||
BAO_SECRET_ID_FILE: /run/secrets/worker_secret_id
|
||||
BAO_SECRET_PATH: secret/data/messenger/worker
|
||||
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-2}
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
||||
@@ -224,6 +447,15 @@ services:
|
||||
DB_POOL_MIN: "1"
|
||||
DB_POOL_MAX: "4"
|
||||
MIGRATIONS_ON_START: "0"
|
||||
secrets:
|
||||
- source: worker_role_id
|
||||
target: worker_role_id
|
||||
- source: worker_secret_id
|
||||
target: worker_secret_id
|
||||
volumes:
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
- ./certs/worker-client.crt:/certs/worker-client.crt:ro
|
||||
- ./certs/worker-client.key:/certs/worker-client.key:ro
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
@@ -231,97 +463,130 @@ services:
|
||||
condition: service_healthy
|
||||
rabbitmq:
|
||||
condition: service_healthy
|
||||
rabbit-mtls:
|
||||
condition: service_started
|
||||
s3-init:
|
||||
condition: service_completed_successfully
|
||||
openbao:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
mem_limit: 768m
|
||||
cpus: "1.0"
|
||||
stop_grace_period: 20s
|
||||
healthcheck:
|
||||
disable: true
|
||||
|
||||
redis:
|
||||
image: redis:7.4.2-alpine
|
||||
command:
|
||||
- redis-server
|
||||
- --appendonly
|
||||
- "yes"
|
||||
- --appendfsync
|
||||
- everysec
|
||||
- --save
|
||||
- "60"
|
||||
- "1"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 3s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
restart: unless-stopped
|
||||
mem_limit: 128m
|
||||
cpus: "0.50"
|
||||
networks: [data, signals]
|
||||
|
||||
otel-collector:
|
||||
image: otel/opentelemetry-collector-contrib:0.128.0
|
||||
command: ["--config=/etc/otel/collector.yaml"]
|
||||
volumes:
|
||||
- ./infra/otel/collector.yaml:/etc/otel/collector.yaml:ro
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
- ./certs/tempo.crt:/certs/tempo.crt:ro
|
||||
- ./certs/loki.crt:/certs/loki.crt:ro
|
||||
- ./certs/prometheus.crt:/certs/prometheus.crt:ro
|
||||
restart: unless-stopped
|
||||
mem_limit: 320m
|
||||
cpus: "0.50"
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
networks: [signals, telemetry]
|
||||
|
||||
otel-mtls:
|
||||
image: haproxy:3.1.7-alpine
|
||||
network_mode: service:otel-collector
|
||||
depends_on:
|
||||
otel-collector:
|
||||
condition: service_started
|
||||
volumes:
|
||||
- ./infra/haproxy-otel.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
- ./certs/otel.pem:/certs/otel.pem:ro
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp:rw,nosuid,size=16m
|
||||
- /var/run:rw,nosuid,size=8m
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
restart: unless-stopped
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:v2.55.1
|
||||
command:
|
||||
- --config.file=/etc/prometheus/prometheus.yml
|
||||
- --web.config.file=/etc/prometheus/web.yml
|
||||
- --web.enable-remote-write-receiver
|
||||
- --storage.tsdb.path=/prometheus
|
||||
- --storage.tsdb.retention.time=7d
|
||||
volumes:
|
||||
- ./infra/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||
- ./infra/prometheus/alerts.yml:/etc/prometheus/alerts.yml:ro
|
||||
- ./infra/prometheus/web.yml:/etc/prometheus/web.yml:ro
|
||||
- ./certs/prometheus.crt:/certs/prometheus.crt:ro
|
||||
- ./certs/prometheus.key:/certs/prometheus.key:ro
|
||||
- prometheus_data:/prometheus
|
||||
ports:
|
||||
- "127.0.0.1:9090:9090"
|
||||
restart: unless-stopped
|
||||
mem_limit: 512m
|
||||
cpus: "0.50"
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
networks: [telemetry]
|
||||
|
||||
loki:
|
||||
image: grafana/loki:3.3.2
|
||||
command: ["-config.file=/etc/loki/loki.yml"]
|
||||
volumes:
|
||||
- ./infra/loki/loki.yml:/etc/loki/loki.yml:ro
|
||||
- ./certs/loki.crt:/certs/loki.crt:ro
|
||||
- ./certs/loki.key:/certs/loki.key:ro
|
||||
- loki_data:/loki
|
||||
restart: unless-stopped
|
||||
mem_limit: 512m
|
||||
cpus: "0.50"
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
networks: [telemetry]
|
||||
|
||||
tempo:
|
||||
image: grafana/tempo:2.7.1
|
||||
command: ["-config.file=/etc/tempo/tempo.yml"]
|
||||
volumes:
|
||||
- ./infra/tempo/tempo.yml:/etc/tempo/tempo.yml:ro
|
||||
- ./certs/tempo.crt:/certs/tempo.crt:ro
|
||||
- ./certs/tempo.key:/certs/tempo.key:ro
|
||||
- tempo_data:/var/tempo
|
||||
restart: unless-stopped
|
||||
mem_limit: 512m
|
||||
cpus: "0.50"
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
networks: [telemetry]
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:11.4.0
|
||||
entrypoint: ["/bin/sh", "/entrypoint.sh"]
|
||||
environment:
|
||||
GF_SECURITY_ADMIN_USER: admin
|
||||
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:-lab-dev-only-change-me}
|
||||
GF_AUTH_ANONYMOUS_ENABLED: "true"
|
||||
GF_AUTH_ANONYMOUS_ORG_ROLE: Admin
|
||||
GF_AUTH_ANONYMOUS_ENABLED: "false"
|
||||
GF_USERS_DEFAULT_THEME: light
|
||||
GF_SERVER_PROTOCOL: https
|
||||
GF_SERVER_CERT_FILE: /certs/grafana.crt
|
||||
GF_SERVER_CERT_KEY: /certs/grafana.key
|
||||
SSL_CERT_FILE: /certs/ca.crt
|
||||
ports:
|
||||
- "127.0.0.1:3000:3000"
|
||||
volumes:
|
||||
- ./infra/grafana/entrypoint.sh:/entrypoint.sh:ro
|
||||
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
||||
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
||||
- ./certs/grafana.crt:/certs/grafana.crt:ro
|
||||
- ./certs/grafana.key:/certs/grafana.key:ro
|
||||
- ./certs/ca.crt:/certs/ca.crt:ro
|
||||
- grafana_data:/var/lib/grafana
|
||||
secrets:
|
||||
- source: grafana_password
|
||||
target: grafana_password
|
||||
depends_on:
|
||||
- prometheus
|
||||
- loki
|
||||
@@ -329,6 +594,55 @@ services:
|
||||
restart: unless-stopped
|
||||
mem_limit: 256m
|
||||
cpus: "0.50"
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
networks: [telemetry]
|
||||
|
||||
secrets:
|
||||
db_super_password:
|
||||
file: ./secrets/db_super_password
|
||||
db_api_password:
|
||||
file: ./secrets/db_api_password
|
||||
db_worker_password:
|
||||
file: ./secrets/db_worker_password
|
||||
redis_password:
|
||||
file: ./secrets/redis_password
|
||||
rabbit_api_password:
|
||||
file: ./secrets/rabbit_api_password
|
||||
rabbit_worker_password:
|
||||
file: ./secrets/rabbit_worker_password
|
||||
s3_admin_access:
|
||||
file: ./secrets/s3_admin_access
|
||||
s3_admin_secret:
|
||||
file: ./secrets/s3_admin_secret
|
||||
s3_api_access:
|
||||
file: ./secrets/s3_api_access
|
||||
s3_api_secret:
|
||||
file: ./secrets/s3_api_secret
|
||||
s3_worker_access:
|
||||
file: ./secrets/s3_worker_access
|
||||
s3_worker_secret:
|
||||
file: ./secrets/s3_worker_secret
|
||||
grafana_password:
|
||||
file: ./secrets/grafana_password
|
||||
api_role_id:
|
||||
file: ./secrets/api.role_id
|
||||
api_secret_id:
|
||||
file: ./secrets/api.secret_id
|
||||
worker_role_id:
|
||||
file: ./secrets/worker.role_id
|
||||
worker_secret_id:
|
||||
file: ./secrets/worker.secret_id
|
||||
migrate_role_id:
|
||||
file: ./secrets/migrate.role_id
|
||||
migrate_secret_id:
|
||||
file: ./secrets/migrate.secret_id
|
||||
|
||||
networks:
|
||||
app:
|
||||
data:
|
||||
signals:
|
||||
telemetry:
|
||||
|
||||
volumes:
|
||||
pg_data:
|
||||
@@ -339,3 +653,4 @@ volumes:
|
||||
loki_data:
|
||||
tempo_data:
|
||||
grafana_data:
|
||||
bao_data:
|
||||
|
||||
Reference in New Issue
Block a user