forked from mtusi2026/mtusi2026lab7
351 lines
11 KiB
YAML
351 lines
11 KiB
YAML
name: mtusi2026lab7
|
|
|
|
x-hardening: &hardening
|
|
read_only: true
|
|
security_opt: [no-new-privileges:true]
|
|
cap_drop: [ALL]
|
|
tmpfs: ['/tmp:size=64m,mode=1777']
|
|
cpus: 0.75
|
|
mem_limit: 192m
|
|
|
|
x-app: &app
|
|
<<: *hardening
|
|
image: mtusi-messenger:lab7
|
|
build: .
|
|
mem_limit: 384m
|
|
restart: unless-stopped
|
|
stop_grace_period: 12s
|
|
|
|
x-app-env: &app-env
|
|
POSTGRES_HOST: postgres
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_MAX_CONNS: '8'
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
S3_ENDPOINT: minio:9000
|
|
S3_USE_SSL: 'true'
|
|
SSL_CERT_FILE: /trust/ca.crt
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: https://collector:44318
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
|
OTEL_TRACES_SAMPLER: parentbased_traceidratio
|
|
OTEL_TRACES_SAMPLER_ARG: '1.0'
|
|
GOMEMLIMIT: 224MiB
|
|
GOGC: '50'
|
|
|
|
x-proxy: &proxy
|
|
<<: *hardening
|
|
user: '10001:10001'
|
|
image: mtusi-messenger:lab7
|
|
entrypoint: [/usr/local/bin/tlsproxy]
|
|
restart: on-failure
|
|
cpus: 0.25
|
|
mem_limit: 48m
|
|
|
|
services:
|
|
postgres:
|
|
<<: *hardening
|
|
image: postgres:17-alpine@sha256:f9cf3e1f0066f0eb0c48707d864f0ac5941e9ff454a072077d97a4d278d07d73
|
|
user: postgres
|
|
entrypoint: [/bin/sh, /postgres-entrypoint.sh]
|
|
environment:
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_PASSWORD_FILE: /bootstrap/POSTGRES_PASSWORD
|
|
tmpfs: ['/tmp:size=16m,mode=1777', '/var/run/postgresql:size=8m,mode=1777']
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
- ./.runtime/identities/postgres:/identity:ro
|
|
- ./.runtime/bootstrap/admin:/bootstrap:ro
|
|
- ./infra/postgres-entrypoint.sh:/postgres-entrypoint.sh:ro
|
|
- ./infra/pg_hba.conf:/etc/pg_hba.conf:ro
|
|
- ./infra/pg_ident.conf:/etc/pg_ident.conf:ro
|
|
healthcheck:
|
|
test: [CMD-SHELL, 'pg_isready -h postgres -U messenger -d messenger']
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
networks: [data]
|
|
|
|
migrations:
|
|
<<: *hardening
|
|
image: mtusi-migrations:lab7
|
|
build: {context: ., target: migrations}
|
|
profiles: [operator]
|
|
environment:
|
|
GOOSE_DRIVER: postgres
|
|
GOOSE_DBSTRING: host=postgres user=messenger dbname=messenger sslmode=verify-full sslrootcert=/trust/ca.crt connect_timeout=5
|
|
POSTGRES_PASSWORD_FILE: /bootstrap/admin/POSTGRES_PASSWORD
|
|
volumes:
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/bootstrap/admin:/bootstrap/admin:ro
|
|
networks: [data]
|
|
|
|
db_grants:
|
|
<<: *hardening
|
|
image: postgres:17-alpine@sha256:f9cf3e1f0066f0eb0c48707d864f0ac5941e9ff454a072077d97a4d278d07d73
|
|
profiles: [operator]
|
|
user: postgres
|
|
entrypoint: [/bin/sh, /grant.sh]
|
|
environment: {PGSSLROOTCERT: /trust/ca.crt, PGSSLMODE: verify-full}
|
|
volumes:
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/bootstrap:/bootstrap:ro
|
|
- ./infra/db-grants.sql:/grants.sql:ro
|
|
- ./infra/rotate-worker.sql:/rotate-worker.sql:ro
|
|
- ./.runtime/retired:/retired:ro
|
|
- ./infra/db-grants.sh:/grant.sh:ro
|
|
- ./security/db-audit.sh:/db-audit.sh:ro
|
|
networks: [data]
|
|
|
|
redis:
|
|
<<: *hardening
|
|
image: redis:7.4-alpine@sha256:7f7d30b7fdd09467bac58198a1f166dd69789d348d4fe859cccb20e0cf287fbe
|
|
user: redis
|
|
command: [redis-server, /etc/redis.conf]
|
|
volumes:
|
|
- redis_data:/data
|
|
- ./infra/redis.conf:/etc/redis.conf:ro
|
|
- ./.runtime/redis:/acl:ro
|
|
networks: [data]
|
|
|
|
redis_tls:
|
|
<<: *proxy
|
|
network_mode: service:redis
|
|
environment: {TLS_ROUTES: '6380=6379=api;6381=6379=worker;6382=6379=operator'}
|
|
volumes:
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/identities/redis:/identity:ro
|
|
|
|
minio:
|
|
<<: *hardening
|
|
image: mtusi-lab7-minio:RELEASE.2025-09-07T16-13-09Z
|
|
build: {context: ., dockerfile: Dockerfile.storage, target: minio}
|
|
environment: {GOMEMLIMIT: 112MiB, GOGC: '50'}
|
|
mem_limit: 256m
|
|
stop_grace_period: 15s
|
|
volumes:
|
|
- s3_data:/data
|
|
- ./.runtime/bootstrap/admin:/bootstrap:ro
|
|
- ./.runtime/identities/minio:/identity:ro
|
|
networks: [data]
|
|
|
|
s3_bootstrap:
|
|
<<: *hardening
|
|
image: mtusi-lab7-mc:RELEASE.2025-08-13T08-35-41Z
|
|
build: {context: ., dockerfile: Dockerfile.storage, target: mc}
|
|
profiles: [operator]
|
|
entrypoint: [/bin/sh, /bootstrap.sh]
|
|
volumes:
|
|
- ./infra/s3-bootstrap.sh:/bootstrap.sh:ro
|
|
- ./.runtime/retired:/retired:ro
|
|
- ./security/s3-audit.sh:/s3-audit.sh:ro
|
|
- ./infra/s3-api.json:/policies/s3-api.json:ro
|
|
- ./infra/s3-worker.json:/policies/s3-worker.json:ro
|
|
- ./infra/s3-operator.json:/policies/s3-operator.json:ro
|
|
- ./.runtime/bootstrap:/bootstrap:ro
|
|
- ./.runtime/trust:/trust:ro
|
|
networks: [data]
|
|
|
|
openbao:
|
|
<<: *hardening
|
|
image: openbao/openbao:2.6.1@sha256:5b2486ab0fb90bbc788cc345b0a08616dfb375873ee8be5df3a2fd4d378a67e0
|
|
user: '100:1000'
|
|
entrypoint: [bao, server, -config=/etc/bao.hcl]
|
|
ports: ['127.0.0.1:18200:8200']
|
|
volumes:
|
|
- openbao_data:/openbao/file
|
|
- ./infra/openbao/bao.hcl:/etc/bao.hcl:ro
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/identities/openbao:/identity:ro
|
|
networks: [data]
|
|
|
|
api:
|
|
<<: *app
|
|
environment:
|
|
<<: *app-env
|
|
SERVICE_ROLE: api
|
|
POSTGRES_USER: messenger_api
|
|
REDIS_USER: api
|
|
REDIS_ADDR: redis:6380
|
|
volumes:
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/identities/api:/identity:ro
|
|
deploy: {replicas: 2}
|
|
networks: [ingress, data, telemetry]
|
|
|
|
worker:
|
|
<<: *app
|
|
entrypoint: [/usr/local/bin/worker]
|
|
environment:
|
|
<<: *app-env
|
|
SERVICE_ROLE: worker
|
|
POSTGRES_USER: messenger_worker
|
|
REDIS_USER: worker
|
|
REDIS_ADDR: redis:6381
|
|
WORKER_CONCURRENCY: '2'
|
|
WORKER_PREFETCH: '4'
|
|
WORKER_MAX_ATTEMPTS: '5'
|
|
WORKER_TIMEOUT_SECONDS: '25'
|
|
WORKER_LEASE_SECONDS: '40'
|
|
WORKER_PIXEL_BUDGET: '40000000'
|
|
volumes:
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/identities/worker:/identity:ro
|
|
networks: [data, telemetry]
|
|
|
|
operator:
|
|
<<: *app
|
|
profiles: [operator]
|
|
restart: 'no'
|
|
entrypoint: [/usr/local/bin/reconcile]
|
|
environment:
|
|
<<: *app-env
|
|
SERVICE_ROLE: operator
|
|
POSTGRES_USER: messenger_operator
|
|
REDIS_USER: operator
|
|
REDIS_ADDR: redis:6382
|
|
OTEL_SDK_DISABLED: 'true'
|
|
volumes:
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/identities/operator:/identity:ro
|
|
networks: [data]
|
|
|
|
gateway:
|
|
<<: *hardening
|
|
image: haproxy:3.2-alpine@sha256:7816a9801a6846b912bc37e48529808e2fa87c3c47992441940f68e393ebcfeb
|
|
user: '10001:10001'
|
|
ports: ['127.0.0.1:${PORT:-8443}:8443']
|
|
volumes:
|
|
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/identities/gateway:/identity:ro
|
|
depends_on: [api]
|
|
mem_limit: 64m
|
|
networks: [ingress]
|
|
|
|
collector:
|
|
<<: *hardening
|
|
image: otel/opentelemetry-collector-contrib:0.137.0
|
|
command: [--config=/etc/otelcol/config.yaml]
|
|
volumes:
|
|
- ./infra/otel/collector.yaml:/etc/otelcol/config.yaml:ro
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/identities/collector:/identity:ro
|
|
networks: [telemetry]
|
|
|
|
collector_tls:
|
|
<<: *proxy
|
|
network_mode: service:collector
|
|
environment: {TLS_ROUTES: '44318=4318=api worker=POST:/v1/;48888=8888=prometheus=GET:/metrics;48889=8889=prometheus=GET:/metrics'}
|
|
volumes:
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/identities/collector:/identity:ro
|
|
|
|
prometheus:
|
|
<<: *hardening
|
|
image: prom/prometheus:v3.6.0
|
|
command: [--config.file=/etc/prometheus/prometheus.yaml, --storage.tsdb.retention.time=7d, --storage.tsdb.retention.size=1GB, --web.listen-address=127.0.0.1:9090]
|
|
volumes:
|
|
- ./infra/prometheus:/etc/prometheus:ro
|
|
- prometheus_data:/prometheus
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/identities/prometheus:/identity:ro
|
|
networks: [telemetry]
|
|
|
|
prometheus_tls:
|
|
<<: *proxy
|
|
network_mode: service:prometheus
|
|
environment: {TLS_ROUTES: '49090=9090=grafana=GET:/api/v1/query,GET:/api/v1/query_range,GET:/api/v1/series,GET:/api/v1/labels,GET:/api/v1/label/,GET:/api/v1/status/buildinfo,POST:/api/v1/query,POST:/api/v1/query_range,POST:/api/v1/series,POST:/api/v1/labels'}
|
|
volumes:
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/identities/prometheus:/identity:ro
|
|
|
|
loki:
|
|
<<: *hardening
|
|
image: grafana/loki:3.5.5
|
|
command: [-config.file=/etc/loki/config.yaml]
|
|
volumes:
|
|
- ./infra/loki.yaml:/etc/loki/config.yaml:ro
|
|
- loki_data:/loki
|
|
networks: [telemetry]
|
|
|
|
loki_tls:
|
|
<<: *proxy
|
|
network_mode: service:loki
|
|
environment: {TLS_ROUTES: '43100=3100=collector=POST:/otlp/v1/logs;43101=3100=grafana=GET:/loki/api/v1/query,GET:/loki/api/v1/query_range,GET:/loki/api/v1/labels,GET:/loki/api/v1/label/,GET:/loki/api/v1/series,GET:/loki/api/v1/status/buildinfo;43102=3100=prometheus=GET:/metrics'}
|
|
volumes:
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/identities/loki:/identity:ro
|
|
|
|
tempo:
|
|
<<: *hardening
|
|
image: grafana/tempo:2.8.2
|
|
command: [-config.file=/etc/tempo/config.yaml]
|
|
volumes:
|
|
- ./infra/tempo.yaml:/etc/tempo/config.yaml:ro
|
|
- tempo_data:/var/tempo
|
|
environment: {GOMEMLIMIT: 300MiB, GOGC: '50'}
|
|
mem_limit: 512m
|
|
restart: unless-stopped
|
|
networks: [telemetry]
|
|
|
|
tempo_tls:
|
|
<<: *proxy
|
|
network_mode: service:tempo
|
|
environment: {TLS_ROUTES: '44318=4318=collector=POST:/v1/traces;43200=3200=grafana=GET:/api/;43201=3200=prometheus=GET:/metrics'}
|
|
volumes:
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/identities/tempo:/identity:ro
|
|
|
|
grafana:
|
|
<<: *hardening
|
|
image: grafana/grafana:12.2.0
|
|
ports: ['127.0.0.1:13000:3000']
|
|
environment:
|
|
GF_SERVER_PROTOCOL: https
|
|
GF_SERVER_CERT_FILE: /identity/tls.crt
|
|
GF_SERVER_CERT_KEY: /identity/tls.key
|
|
GF_SERVER_ROOT_URL: https://localhost:13000/
|
|
GF_PATHS_PROVISIONING: /provisioning
|
|
GF_SECURITY_ADMIN_PASSWORD__FILE: /bootstrap/GRAFANA_PASSWORD
|
|
GF_SECURITY_COOKIE_SECURE: 'true'
|
|
GF_PLUGINS_PREINSTALL_DISABLED: 'true'
|
|
GF_ANALYTICS_CHECK_FOR_UPDATES: 'false'
|
|
GF_ANALYTICS_REPORTING_ENABLED: 'false'
|
|
GF_USERS_ALLOW_SIGN_UP: 'false'
|
|
volumes:
|
|
- ./.runtime/grafana:/provisioning:ro
|
|
- ./.runtime/identities/grafana:/identity:ro
|
|
- ./.runtime/bootstrap/grafana:/bootstrap:ro
|
|
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
|
- grafana_data:/var/lib/grafana
|
|
networks: [telemetry]
|
|
|
|
audit:
|
|
<<: *hardening
|
|
image: python:3.13.9-alpine3.22
|
|
profiles: [operator]
|
|
user: '10001:10001'
|
|
entrypoint: [python, /audit.py]
|
|
volumes:
|
|
- ./security/audit.py:/audit.py:ro
|
|
- ./.runtime/trust:/trust:ro
|
|
- ./.runtime/identities:/identities:ro
|
|
- ./.runtime/bootstrap:/bootstrap:ro
|
|
- ./.runtime/retired:/retired:ro
|
|
networks: [ingress, data, telemetry]
|
|
|
|
networks:
|
|
ingress: {}
|
|
data: {}
|
|
telemetry: {}
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|
|
s3_data:
|
|
openbao_data:
|
|
prometheus_data:
|
|
loki_data:
|
|
tempo_data:
|
|
grafana_data:
|