531 lines
20 KiB
YAML
531 lines
20 KiB
YAML
# Lab 7: lab 6 stack + TLS/mTLS everywhere, OpenBao (non-dev), least privilege, hardened containers.
|
|
name: mtusi-lab7
|
|
|
|
x-hardened: &hardened # every container: no privilege escalation, all capabilities dropped (stateful exceptions are explicit below)
|
|
security_opt: ["no-new-privileges:true"]
|
|
cap_drop: ["ALL"]
|
|
pids_limit: 256
|
|
|
|
x-otel-env: &otel-env # SDK -> Collector over mTLS with the service's own identity (OTEL_* variables are read by the SDK itself)
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
|
OTEL_EXPORTER_OTLP_CERTIFICATE: /run/pki/ca.crt
|
|
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: /run/pki/tls.crt
|
|
OTEL_EXPORTER_OTLP_CLIENT_KEY: /run/pki/tls.key
|
|
OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=lab
|
|
SERVICE_VERSION: "1.7.0"
|
|
|
|
x-pg-env: &pg-env # libpq reads these: TLS verify-full against our CA; password is injected from OpenBao at start
|
|
PGHOST: postgres
|
|
PGPORT: "5432"
|
|
PGDATABASE: ${POSTGRES_DB:-messenger}
|
|
PGSSLMODE: verify-full
|
|
PGSSLROOTCERT: /run/pki/ca.crt
|
|
|
|
x-app-env: &app-env
|
|
TLS_CA_FILE: /run/pki/ca.crt
|
|
TLS_CERT_FILE: /run/pki/tls.crt
|
|
TLS_KEY_FILE: /run/pki/tls.key
|
|
BAO_ADDR: ${BAO_ADDR:-https://openbao:8200}
|
|
BAO_CACERT: /run/pki/ca.crt
|
|
S3_ENDPOINT: https://s3:9000
|
|
S3_REGION: ${S3_REGION:-us-east-1}
|
|
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
|
|
|
services:
|
|
init_perms: # one-shot: named volumes are root-owned on first use; give them to the unprivileged uid
|
|
image: alpine:3.20.3
|
|
user: "0:0"
|
|
command: ["sh", "-c", "chown -R 10001:10001 /v/redis /v/s3 /v/kafka /v/prom /v/loki /v/tempo /v/grafana /v/bao"]
|
|
volumes: [redis_data:/v/redis, s3_data:/v/s3, kafka_data:/v/kafka, prometheus_data:/v/prom, loki_data:/v/loki, tempo_data:/v/tempo, grafana_data:/v/grafana, bao_data:/v/bao]
|
|
security_opt: ["no-new-privileges:true"]
|
|
cap_drop: ["ALL"]
|
|
cap_add: ["CHOWN", "DAC_OVERRIDE", "FOWNER"]
|
|
network_mode: none
|
|
restart: "no"
|
|
|
|
openbao:
|
|
<<: *hardened
|
|
image: openbao/openbao:2.4.1
|
|
user: "10001:10001"
|
|
command: ["bao", "server", "-config=/openbao/config/openbao.hcl"] # NOT -dev: sealed at start, persistent file storage
|
|
volumes:
|
|
- ./infra/openbao/openbao.hcl:/openbao/config/openbao.hcl:ro
|
|
- ./secrets/pki/openbao:/run/pki:ro
|
|
- bao_data:/openbao/data
|
|
networks: [backend] # no published port: the operator uses `docker compose exec`
|
|
depends_on: {init_perms: {condition: service_completed_successfully}}
|
|
healthcheck: # healthy = process up and TLS works (sealed is fine: exit code 2)
|
|
test: ["CMD-SHELL", "bao status -address=https://127.0.0.1:8200 -ca-cert=/run/pki/ca.crt >/dev/null 2>&1; [ $$? -ne 1 ]"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 20
|
|
cpus: 0.5
|
|
mem_limit: 256m
|
|
restart: unless-stopped
|
|
|
|
postgres: # exception: starts as root to chown the key, then drops to postgres; minimal capabilities; writable data volume
|
|
image: postgres:17.6-alpine
|
|
entrypoint: ["/bin/sh", "/entrypoint.sh"]
|
|
environment:
|
|
POSTGRES_DB: ${POSTGRES_DB:-messenger}
|
|
POSTGRES_USER: ${POSTGRES_USER:-messenger}
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
- ./infra/postgres/entrypoint.sh:/entrypoint.sh:ro
|
|
- ./infra/postgres/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro
|
|
- ./secrets/pki/postgres:/pki:ro
|
|
- ./secrets/ops/postgres_password:/run/secrets/postgres_password:ro
|
|
tmpfs: ["/tls:mode=0700", "/run/postgresql", "/tmp"]
|
|
security_opt: ["no-new-privileges:true"]
|
|
cap_drop: ["ALL"]
|
|
cap_add: ["CHOWN", "SETUID", "SETGID", "DAC_OVERRIDE", "FOWNER"]
|
|
networks: [backend]
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
cpus: 1.0
|
|
mem_limit: 768m
|
|
restart: unless-stopped
|
|
|
|
redis:
|
|
<<: *hardened
|
|
image: redis:7.4.2-alpine
|
|
user: "10001:10001"
|
|
command: ["redis-server", "/etc/redis/redis.conf"]
|
|
read_only: true
|
|
tmpfs: ["/tmp"]
|
|
volumes:
|
|
- redis_data:/data
|
|
- ./infra/redis/redis.conf:/etc/redis/redis.conf:ro
|
|
- ./secrets/ops/redis_users.acl:/acl/users.acl:ro
|
|
- ./secrets/pki/redis:/pki:ro
|
|
- ./secrets/ops/redis_health_password:/run/secrets/redis_health_password:ro
|
|
networks: [backend]
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "REDISCLI_AUTH=\"$$(cat /run/secrets/redis_health_password)\" redis-cli --tls --cacert /pki/ca.crt --user health ping | grep -q PONG"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
cpus: 0.25
|
|
mem_limit: 256m
|
|
depends_on: {init_perms: {condition: service_completed_successfully}}
|
|
restart: unless-stopped
|
|
|
|
s3: # exception: stateful store with a writable data volume (rootfs not read-only)
|
|
<<: *hardened
|
|
image: pgsty/silo:RELEASE.2026-10-15T00-00-00Z
|
|
user: "10001:10001"
|
|
command: ["server", "/data", "--address", ":9000", "--certs-dir", "/certs"]
|
|
environment:
|
|
MINIO_ROOT_USER_FILE: /run/secrets/s3_root_user
|
|
MINIO_ROOT_PASSWORD_FILE: /run/secrets/s3_root_password
|
|
MINIO_BROWSER: "off"
|
|
volumes:
|
|
- s3_data:/data
|
|
- ./secrets/pki/s3/tls.crt:/certs/public.crt:ro
|
|
- ./secrets/pki/s3/tls.key:/certs/private.key:ro
|
|
- ./secrets/pki/s3/ca.crt:/certs/CAs/ca.crt:ro
|
|
- ./secrets/ops/s3_root_user:/run/secrets/s3_root_user:ro
|
|
- ./secrets/ops/s3_root_password:/run/secrets/s3_root_password:ro
|
|
networks: [backend]
|
|
depends_on: {init_perms: {condition: service_completed_successfully}}
|
|
cpus: 1.0
|
|
mem_limit: 512m
|
|
restart: unless-stopped
|
|
|
|
s3_init:
|
|
<<: *hardened
|
|
image: pgsty/silo:RELEASE.2026-10-15T00-00-00Z
|
|
user: "10001:10001"
|
|
entrypoint: ["/bin/sh", "/infra/s3-init.sh"]
|
|
environment:
|
|
S3_ENDPOINT: https://s3:9000
|
|
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
|
SSL_CERT_FILE: /pki/ca.crt # mc trusts only our CA
|
|
HOME: /tmp
|
|
tmpfs: ["/tmp"]
|
|
volumes:
|
|
- ./infra/s3-init.sh:/infra/s3-init.sh:ro
|
|
- ./secrets/pki/ca/ca.crt:/pki/ca.crt:ro
|
|
- ./secrets/ops/s3_root_user:/run/secrets/s3_root_user:ro
|
|
- ./secrets/ops/s3_root_password:/run/secrets/s3_root_password:ro
|
|
- ./secrets/ops/s3_api_secret:/run/secrets/s3_api_secret:ro
|
|
- ./secrets/ops/s3_worker_secret:/run/secrets/s3_worker_secret:ro
|
|
- ./secrets/ops/s3_sweeper_secret:/run/secrets/s3_sweeper_secret:ro
|
|
networks: [backend]
|
|
depends_on: {s3: {condition: service_started}}
|
|
restart: "no"
|
|
|
|
kafka: # exception: stateful broker (writable log dir and generated config)
|
|
security_opt: ["no-new-privileges:true"]
|
|
cap_drop: ["ALL"]
|
|
image: apache/kafka:3.9.0
|
|
user: "10001:10001"
|
|
environment:
|
|
KAFKA_NODE_ID: "1"
|
|
KAFKA_PROCESS_ROLES: broker,controller
|
|
KAFKA_LISTENERS: INTERNAL://:9092,CONTROLLER://:9093
|
|
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:9092
|
|
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
|
|
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:SSL,INTERNAL:SSL
|
|
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@kafka:9093
|
|
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
|
|
KAFKA_SSL_KEYSTORE_TYPE: PEM
|
|
KAFKA_SSL_KEYSTORE_LOCATION: /pki/keystore.pem
|
|
KAFKA_SSL_TRUSTSTORE_TYPE: PEM
|
|
KAFKA_SSL_TRUSTSTORE_LOCATION: /pki/ca.crt
|
|
|
|
KAFKA_SSL_CLIENT_AUTH: required # mTLS on every listener
|
|
KAFKA_SSL_PRINCIPAL_MAPPING_RULES: "RULE:^CN=([^,]+).*$$/$$1/,DEFAULT"
|
|
KAFKA_AUTHORIZER_CLASS_NAME: org.apache.kafka.metadata.authorizer.StandardAuthorizer
|
|
KAFKA_SUPER_USERS: User:kafka;User:kafka-admin
|
|
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "false"
|
|
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1"
|
|
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: "1"
|
|
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: "1"
|
|
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: "0"
|
|
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false"
|
|
KAFKA_LOG_DIRS: /var/lib/kafka/data
|
|
KAFKA_HEAP_OPTS: "-Xms256m -Xmx512m"
|
|
tmpfs: ["/opt/kafka/config:uid=10001,gid=10001", "/opt/kafka/logs:uid=10001,gid=10001"]
|
|
volumes:
|
|
- kafka_data:/var/lib/kafka/data
|
|
- ./secrets/pki/kafka:/pki:ro
|
|
- ./infra/kafka/client.properties:/client.properties:ro
|
|
networks: [backend]
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "KAFKA_HEAP_OPTS='-Xmx128m' /opt/kafka/bin/kafka-broker-api-versions.sh --bootstrap-server kafka:9092 --command-config /client.properties >/dev/null 2>&1"]
|
|
interval: 10s
|
|
timeout: 25s
|
|
retries: 40
|
|
start_period: 45s
|
|
cpus: 2.0
|
|
mem_limit: 2g
|
|
depends_on: {init_perms: {condition: service_completed_successfully}}
|
|
restart: unless-stopped
|
|
|
|
kafka_init:
|
|
<<: *hardened
|
|
image: apache/kafka:3.9.0
|
|
user: "10001:10001"
|
|
entrypoint: ["/bin/sh", "/init.sh"]
|
|
environment: {JOBS_TOPIC: "${JOBS_TOPIC:-attachment-jobs}"}
|
|
tmpfs: ["/opt/kafka/logs:uid=10001,gid=10001"]
|
|
volumes:
|
|
- ./infra/kafka/init.sh:/init.sh:ro
|
|
- ./infra/kafka/client.properties:/client.properties:ro
|
|
- ./secrets/pki/kafka-admin:/pki:ro
|
|
networks: [backend]
|
|
depends_on: {kafka: {condition: service_healthy}}
|
|
restart: "no"
|
|
|
|
migrate: # one-shot owner job: schema + least-privilege roles; the only container that knows the DB owner password
|
|
<<: *hardened
|
|
build: .
|
|
image: mtusi-lab7-app:1.0.0
|
|
user: "10001:10001"
|
|
command: ["sh", "-c", "PGPASSWORD=\"$$(cat /run/secrets/postgres_password)\" python scripts/migrate.py && PGPASSWORD=\"$$(cat /run/secrets/postgres_password)\" python scripts/db_roles.py $${DB_ROLES_ARGS}"]
|
|
environment:
|
|
<<: *pg-env
|
|
PGUSER: ${POSTGRES_USER:-messenger}
|
|
PGSSLROOTCERT: /pki/ca.crt
|
|
OPS_SECRETS_DIR: /run/secrets
|
|
DB_ROLES_ARGS: ${DB_ROLES_ARGS:-}
|
|
read_only: true
|
|
tmpfs: ["/tmp"]
|
|
volumes:
|
|
- ./secrets/pki/ca/ca.crt:/pki/ca.crt:ro
|
|
- ./secrets/ops/postgres_password:/run/secrets/postgres_password:ro
|
|
- ./secrets/ops/db_api_password:/run/secrets/db_api_password:ro
|
|
- ./secrets/ops/db_worker_password:/run/secrets/db_worker_password:ro
|
|
- ./secrets/ops/db_dispatcher_password:/run/secrets/db_dispatcher_password:ro
|
|
- ./secrets/ops/db_sweeper_password:/run/secrets/db_sweeper_password:ro
|
|
networks: [backend]
|
|
depends_on: {postgres: {condition: service_healthy}}
|
|
restart: "no"
|
|
cpus: 0.5
|
|
mem_limit: 384m
|
|
|
|
api:
|
|
<<: *hardened
|
|
build: .
|
|
image: mtusi-lab7-app:1.0.0
|
|
user: "10001:10001"
|
|
environment:
|
|
<<: [*pg-env, *app-env, *otel-env]
|
|
PGUSER: messenger_api
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: "8443"
|
|
ALLOWED_CLIENT_SANS: ${ALLOWED_CLIENT_SANS:-lb}
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
DB_POOL_MIN_SIZE: ${DB_POOL_MIN_SIZE:-1}
|
|
DB_POOL_MAX_SIZE: ${DB_POOL_MAX_SIZE:-10}
|
|
DB_POOL_TIMEOUT_SECONDS: ${DB_POOL_TIMEOUT_SECONDS:-5}
|
|
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
|
|
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
|
|
IMAGE_DECODE_CONCURRENCY: ${IMAGE_DECODE_CONCURRENCY:-1}
|
|
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
|
ARGON2_MEMORY_KIB: ${ARGON2_MEMORY_KIB:-19456}
|
|
ARGON2_ITERATIONS: ${ARGON2_ITERATIONS:-2}
|
|
ARGON2_PARALLELISM: ${ARGON2_PARALLELISM:-1}
|
|
ARGON2_CONCURRENCY: ${ARGON2_CONCURRENCY:-2}
|
|
LOGIN_IP_LIMIT: ${LOGIN_IP_LIMIT:-30}
|
|
LOGIN_USER_FAIL_LIMIT: ${LOGIN_USER_FAIL_LIMIT:-10}
|
|
RATE_WINDOW_SECONDS: ${RATE_WINDOW_SECONDS:-60}
|
|
deploy: {replicas: 2}
|
|
expose: ["8443"] # reachable only inside the backend network, and only with the LB client identity
|
|
read_only: true
|
|
tmpfs: ["/tmp:size=128m,mode=1777"]
|
|
volumes:
|
|
- ./secrets/pki/api:/run/pki:ro
|
|
- ./secrets/approle/api:/run/approle:ro
|
|
networks: [backend]
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
redis: {condition: service_healthy}
|
|
openbao: {condition: service_healthy}
|
|
s3_init: {condition: service_completed_successfully}
|
|
healthcheck: # TCP only: an HTTPS probe would be (correctly) refused by the identity allowlist
|
|
test: ["CMD", "python", "-c", "import socket; socket.create_connection(('127.0.0.1', 8443), 2)"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 10
|
|
start_period: 40s
|
|
stop_grace_period: 15s
|
|
cpus: 1.0
|
|
mem_limit: 512m
|
|
restart: unless-stopped
|
|
|
|
worker:
|
|
<<: *hardened
|
|
build: .
|
|
image: mtusi-lab7-app:1.0.0
|
|
user: "10001:10001"
|
|
command: ["python", "-m", "src.worker"]
|
|
environment:
|
|
<<: [*pg-env, *app-env, *otel-env]
|
|
PGUSER: messenger_worker
|
|
KAFKA_BOOTSTRAP_SERVERS: kafka:9092
|
|
JOBS_TOPIC: ${JOBS_TOPIC:-attachment-jobs}
|
|
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
|
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
|
LEASE_GRACE_SECONDS: ${LEASE_GRACE_SECONDS:-15}
|
|
JOB_BACKOFF_BASE_SECONDS: ${JOB_BACKOFF_BASE_SECONDS:-2}
|
|
JOB_BACKOFF_CAP_SECONDS: ${JOB_BACKOFF_CAP_SECONDS:-60}
|
|
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-2}
|
|
IMG_MEMORY_MB: ${IMG_MEMORY_MB:-1024}
|
|
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
|
|
FAULT_WORKER_EXIT_AFTER_S3: ${FAULT_WORKER_EXIT_AFTER_S3:-0}
|
|
read_only: true
|
|
tmpfs: ["/tmp:size=512m,mode=1777"]
|
|
volumes:
|
|
- ./secrets/pki/worker:/run/pki:ro
|
|
- ./secrets/approle/worker:/run/approle:ro
|
|
networks: [backend]
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
kafka_init: {condition: service_completed_successfully}
|
|
s3_init: {condition: service_completed_successfully}
|
|
openbao: {condition: service_healthy}
|
|
stop_grace_period: 30s
|
|
cpus: 1.0 # upload-worker budget: CPU, RAM (also RLIMIT_AS in the child) and JOB_TIMEOUT_SECONDS
|
|
mem_limit: 1g
|
|
restart: unless-stopped
|
|
|
|
dispatcher:
|
|
<<: *hardened
|
|
build: .
|
|
image: mtusi-lab7-app:1.0.0
|
|
user: "10001:10001"
|
|
command: ["python", "-m", "src.dispatcher"]
|
|
environment:
|
|
<<: [*pg-env, *app-env, *otel-env]
|
|
PGUSER: messenger_dispatcher
|
|
KAFKA_BOOTSTRAP_SERVERS: kafka:9092
|
|
JOBS_TOPIC: ${JOBS_TOPIC:-attachment-jobs}
|
|
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
|
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
|
LEASE_GRACE_SECONDS: ${LEASE_GRACE_SECONDS:-15}
|
|
JOB_BACKOFF_BASE_SECONDS: ${JOB_BACKOFF_BASE_SECONDS:-2}
|
|
JOB_BACKOFF_CAP_SECONDS: ${JOB_BACKOFF_CAP_SECONDS:-60}
|
|
FAULT_DISPATCHER_EXIT_BEFORE_PUBLISH: ${FAULT_DISPATCHER_EXIT_BEFORE_PUBLISH:-0}
|
|
read_only: true
|
|
tmpfs: ["/tmp"]
|
|
volumes:
|
|
- ./secrets/pki/dispatcher:/run/pki:ro
|
|
- ./secrets/approle/dispatcher:/run/approle:ro
|
|
networks: [backend]
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
kafka_init: {condition: service_completed_successfully}
|
|
openbao: {condition: service_healthy}
|
|
cpus: 0.25
|
|
mem_limit: 192m
|
|
restart: unless-stopped
|
|
|
|
s3_sweeper:
|
|
<<: *hardened
|
|
build: .
|
|
image: mtusi-lab7-app:1.0.0
|
|
user: "10001:10001"
|
|
command: ["python", "scripts/s3_sweep.py", "--loop", "--apply"]
|
|
environment:
|
|
<<: [*pg-env, *app-env]
|
|
PGUSER: messenger_sweeper
|
|
SWEEP_GRACE_SECONDS: ${SWEEP_GRACE_SECONDS:-3600}
|
|
SWEEP_INTERVAL_SECONDS: ${SWEEP_INTERVAL_SECONDS:-600}
|
|
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
|
|
read_only: true
|
|
tmpfs: ["/tmp"]
|
|
volumes:
|
|
- ./secrets/pki/sweeper:/run/pki:ro
|
|
- ./secrets/approle/sweeper:/run/approle:ro
|
|
networks: [backend]
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
s3_init: {condition: service_completed_successfully}
|
|
openbao: {condition: service_healthy}
|
|
cpus: 0.25
|
|
mem_limit: 128m
|
|
restart: unless-stopped
|
|
|
|
otel-collector:
|
|
<<: *hardened
|
|
image: otel/opentelemetry-collector-contrib:0.131.0
|
|
user: "10001:10001"
|
|
command: ["--config=/etc/otelcol/collector.yaml"]
|
|
read_only: true
|
|
volumes:
|
|
- ./infra/otel/collector.yaml:/etc/otelcol/collector.yaml:ro
|
|
- ./secrets/pki/otel-collector:/pki:ro
|
|
- ./secrets/pki/ca/workload-ca.crt:/ca/workload-ca.crt:ro
|
|
networks: [backend]
|
|
cpus: 0.5
|
|
mem_limit: 256m
|
|
restart: unless-stopped
|
|
|
|
prometheus: # exception: writable TSDB volume
|
|
<<: *hardened
|
|
image: prom/prometheus:v3.5.0
|
|
user: "10001:10001"
|
|
command:
|
|
- --config.file=/etc/prometheus/prometheus.yml
|
|
- --web.config.file=/etc/prometheus/web.yml
|
|
- --storage.tsdb.path=/prometheus
|
|
- --storage.tsdb.retention.time=30d
|
|
- --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/alerts.yml:/etc/prometheus/alerts.yml:ro
|
|
- ./secrets/pki/prometheus:/pki:ro
|
|
- prometheus_data:/prometheus
|
|
networks: [backend]
|
|
depends_on: {init_perms: {condition: service_completed_successfully}}
|
|
cpus: 0.5
|
|
mem_limit: 512m
|
|
restart: unless-stopped
|
|
|
|
loki: # exception: writable chunk store
|
|
<<: *hardened
|
|
image: grafana/loki:3.5.3
|
|
user: "10001:10001"
|
|
command: ["-config.file=/etc/loki/loki.yaml"]
|
|
volumes:
|
|
- ./infra/loki/loki.yaml:/etc/loki/loki.yaml:ro
|
|
- ./secrets/pki/loki:/pki:ro
|
|
- loki_data:/loki
|
|
networks: [backend]
|
|
depends_on: {init_perms: {condition: service_completed_successfully}}
|
|
cpus: 0.5
|
|
mem_limit: 512m
|
|
restart: unless-stopped
|
|
|
|
tempo: # exception: writable WAL/blocks; no longer runs as root (lab 6 used user 0)
|
|
<<: *hardened
|
|
image: grafana/tempo:2.8.2
|
|
user: "10001:10001"
|
|
command: ["-config.file=/etc/tempo/tempo.yaml"]
|
|
volumes:
|
|
- ./infra/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro
|
|
- ./secrets/pki/tempo:/pki:ro
|
|
- tempo_data:/var/tempo
|
|
networks: [backend]
|
|
depends_on: {init_perms: {condition: service_completed_successfully}}
|
|
cpus: 0.5
|
|
mem_limit: 512m
|
|
restart: unless-stopped
|
|
|
|
grafana: # exception: writable state volume; HTTPS, loopback-only port
|
|
<<: *hardened
|
|
image: grafana/grafana:12.1.1
|
|
user: "10001:10001"
|
|
environment:
|
|
GF_SECURITY_ADMIN_USER: ${GRAFANA_ADMIN_USER:-admin}
|
|
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_admin_password
|
|
GF_SERVER_PROTOCOL: https
|
|
GF_SERVER_CERT_FILE: /pki/tls.crt
|
|
GF_SERVER_CERT_KEY: /pki/tls.key
|
|
GF_USERS_ALLOW_SIGN_UP: "false"
|
|
GF_ANALYTICS_REPORTING_ENABLED: "false"
|
|
GF_ANALYTICS_CHECK_FOR_UPDATES: "false"
|
|
ports:
|
|
- "127.0.0.1:${GRAFANA_PORT:-3000}:3000"
|
|
volumes:
|
|
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
|
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
|
- ./secrets/pki/grafana:/pki:ro
|
|
- ./secrets/ops/grafana_admin_password:/run/secrets/grafana_admin_password:ro
|
|
- grafana_data:/var/lib/grafana
|
|
tmpfs: ["/tmp"]
|
|
networks: [frontend, backend]
|
|
depends_on: [prometheus, loki, tempo]
|
|
cpus: 0.5
|
|
mem_limit: 512m
|
|
restart: unless-stopped
|
|
|
|
load_balancer:
|
|
<<: *hardened
|
|
image: haproxy:3.2.5-alpine
|
|
user: "10001:10001"
|
|
ports:
|
|
- "127.0.0.1:${APP_PORT:-8443}:8443"
|
|
read_only: true
|
|
tmpfs: ["/tmp"]
|
|
volumes:
|
|
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
|
- ./secrets/pki/lb-public:/pki/lb-public:ro
|
|
- ./secrets/pki/lb:/pki/lb:ro
|
|
networks: [frontend, backend]
|
|
depends_on:
|
|
api: {condition: service_healthy}
|
|
healthcheck:
|
|
test: ["CMD", "haproxy", "-c", "-f", "/usr/local/etc/haproxy/haproxy.cfg"]
|
|
interval: 10s
|
|
timeout: 3s
|
|
retries: 3
|
|
cpus: 0.5
|
|
mem_limit: 128m
|
|
restart: unless-stopped
|
|
|
|
networks:
|
|
frontend: {driver: bridge}
|
|
backend:
|
|
driver: bridge
|
|
internal: true # no route to/from the host or the internet
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|
|
s3_data:
|
|
kafka_data:
|
|
bao_data:
|
|
prometheus_data:
|
|
loki_data:
|
|
tempo_data:
|
|
grafana_data:
|