lab7: HTTPS+mTLS, OpenBao AppRole, Argon2id, rate limits, hardening
This commit is contained in:
+312
@@ -0,0 +1,312 @@
|
||||
name: lab7
|
||||
|
||||
x-api-env: &api_env
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: "8080"
|
||||
APP_ENV: lab
|
||||
SERVICE_VERSION: "7.0.0"
|
||||
SESSION_TTL_SECONDS: "3600"
|
||||
PKI_DIR: /pki
|
||||
OPENBAO_ADDR: https://openbao:8200
|
||||
OPENBAO_CA: /pki/ca.crt
|
||||
OPENBAO_ROLE_ID_FILE: /run/secrets/openbao_role_id
|
||||
OPENBAO_SECRET_ID_FILE: /run/secrets/openbao_secret_id
|
||||
S3_ENDPOINT: https://s3:9000
|
||||
S3_REGION: us-east-1
|
||||
S3_BUCKET: messenger-attachments
|
||||
S3_CA: /pki/ca.crt
|
||||
BROKER_CA: /pki/ca.crt
|
||||
JOB_QUEUE: attachment_jobs
|
||||
STAGING_PREFIX: staging
|
||||
MAX_JOB_ATTEMPTS: "5"
|
||||
THUMBNAIL_SIZE: "256"
|
||||
MAX_UPLOAD_BYTES: "10485760"
|
||||
MAX_IMAGE_PIXELS: "40000000"
|
||||
LOGIN_RATE_LIMIT: "5"
|
||||
LOGIN_RATE_WINDOW_SECONDS: "60"
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4317
|
||||
OTEL_CA: /pki/ca.crt
|
||||
OTEL_METRIC_INTERVAL_MS: "10000"
|
||||
|
||||
x-hardening: &hardening
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
cap_drop:
|
||||
- ALL
|
||||
mem_limit: 512m
|
||||
cpus: 1.0
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16.4-alpine
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- >-
|
||||
install -m 0600 -o postgres /pki/postgres.key /tmp/postgres.key &&
|
||||
install -m 0644 /pki/postgres.crt /tmp/postgres.crt &&
|
||||
install -m 0644 /pki/ca.crt /tmp/ca.crt &&
|
||||
exec docker-entrypoint.sh postgres
|
||||
-c ssl=on
|
||||
-c ssl_cert_file=/tmp/postgres.crt
|
||||
-c ssl_key_file=/tmp/postgres.key
|
||||
-c ssl_ca_file=/tmp/ca.crt
|
||||
-c hba_file=/etc/postgresql/pg_hba.conf
|
||||
environment:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
POSTGRES_DB: messenger
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
- ./infra/postgres/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro
|
||||
- ./pki:/pki:ro
|
||||
secrets:
|
||||
- postgres_password
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
||||
interval: 3s
|
||||
timeout: 2s
|
||||
retries: 30
|
||||
|
||||
s3:
|
||||
image: milvusdb/minio:RELEASE.2024-12-18T13-15-44Z
|
||||
command: server /data --certs-dir /certs --console-address ":9001"
|
||||
environment:
|
||||
MINIO_ROOT_USER_FILE: /run/secrets/s3_root_user
|
||||
MINIO_ROOT_PASSWORD_FILE: /run/secrets/s3_root_password
|
||||
volumes:
|
||||
- s3data:/data
|
||||
- ./pki:/pki:ro
|
||||
- ./pki/minio.crt:/certs/public.crt:ro
|
||||
- ./pki/minio.key:/certs/private.key:ro
|
||||
secrets:
|
||||
- s3_root_user
|
||||
- s3_root_password
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "curl -fsS --cacert /pki/ca.crt https://localhost:9000/minio/health/live || exit 1"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
|
||||
broker:
|
||||
image: rabbitmq:3.13-alpine
|
||||
environment:
|
||||
RABBITMQ_DEFAULT_USER: ${BROKER_USER:?set BROKER_USER in .env}
|
||||
RABBITMQ_DEFAULT_PASS: ${BROKER_PASSWORD:?set BROKER_PASSWORD in .env}
|
||||
volumes:
|
||||
- rabbitdata:/var/lib/rabbitmq
|
||||
- ./infra/rabbitmq/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
|
||||
- ./pki:/pki:ro
|
||||
healthcheck:
|
||||
test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 30
|
||||
|
||||
openbao-perms:
|
||||
image: openbao/openbao:2.0.2
|
||||
user: "0:0"
|
||||
entrypoint: ["sh", "-c", "chown -R 100:1000 /openbao/data"]
|
||||
volumes:
|
||||
- openbaodata:/openbao/data
|
||||
|
||||
openbao:
|
||||
image: openbao/openbao:2.0.2
|
||||
command: ["server", "-config=/openbao/config.hcl"]
|
||||
environment:
|
||||
BAO_ADDR: https://openbao:8200
|
||||
BAO_CACERT: /pki/ca.crt
|
||||
cap_add:
|
||||
- IPC_LOCK
|
||||
ports:
|
||||
- "127.0.0.1:8200:8200"
|
||||
volumes:
|
||||
- openbaodata:/openbao/data
|
||||
- ./infra/openbao/config.hcl:/openbao/config.hcl:ro
|
||||
- ./pki:/pki:ro
|
||||
depends_on:
|
||||
openbao-perms:
|
||||
condition: service_completed_successfully
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "BAO_ADDR=https://openbao:8200 BAO_CACERT=/pki/ca.crt bao status >/dev/null 2>&1"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
|
||||
api1:
|
||||
build: .
|
||||
image: lab7-api:local
|
||||
<<: *hardening
|
||||
environment:
|
||||
<<: *api_env
|
||||
INSTANCE_ID: api-1
|
||||
secrets:
|
||||
- openbao_role_id
|
||||
- openbao_secret_id
|
||||
volumes:
|
||||
- ./pki:/pki:ro
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
s3:
|
||||
condition: service_healthy
|
||||
broker:
|
||||
condition: service_healthy
|
||||
openbao:
|
||||
condition: service_healthy
|
||||
|
||||
api2:
|
||||
image: lab7-api:local
|
||||
<<: *hardening
|
||||
environment:
|
||||
<<: *api_env
|
||||
INSTANCE_ID: api-2
|
||||
secrets:
|
||||
- openbao_role_id
|
||||
- openbao_secret_id
|
||||
volumes:
|
||||
- ./pki:/pki:ro
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
s3:
|
||||
condition: service_healthy
|
||||
broker:
|
||||
condition: service_healthy
|
||||
openbao:
|
||||
condition: service_healthy
|
||||
|
||||
worker:
|
||||
image: lab7-api:local
|
||||
<<: *hardening
|
||||
command: ["python", "-m", "src.worker"]
|
||||
environment:
|
||||
<<: *api_env
|
||||
INSTANCE_ID: worker
|
||||
secrets:
|
||||
- openbao_role_id
|
||||
- openbao_secret_id
|
||||
volumes:
|
||||
- ./pki:/pki:ro
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
s3:
|
||||
condition: service_healthy
|
||||
broker:
|
||||
condition: service_healthy
|
||||
openbao:
|
||||
condition: service_healthy
|
||||
|
||||
api-gw1:
|
||||
image: nginx:1.27.1-alpine
|
||||
environment:
|
||||
API_UPSTREAM: api1
|
||||
volumes:
|
||||
- ./infra/nginx/gateway.conf.template:/etc/nginx/templates/gateway.conf.template:ro
|
||||
- ./pki:/pki:ro
|
||||
ports:
|
||||
- "127.0.0.1:9443:8443"
|
||||
depends_on:
|
||||
- api1
|
||||
|
||||
api-gw2:
|
||||
image: nginx:1.27.1-alpine
|
||||
environment:
|
||||
API_UPSTREAM: api2
|
||||
volumes:
|
||||
- ./infra/nginx/gateway.conf.template:/etc/nginx/templates/gateway.conf.template:ro
|
||||
- ./pki:/pki:ro
|
||||
ports:
|
||||
- "127.0.0.1:9444:8443"
|
||||
depends_on:
|
||||
- api2
|
||||
|
||||
lb:
|
||||
image: nginx:1.27.1-alpine
|
||||
ports:
|
||||
- "8443:8443"
|
||||
volumes:
|
||||
- ./infra/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
|
||||
- ./pki:/pki:ro
|
||||
depends_on:
|
||||
- api-gw1
|
||||
- api-gw2
|
||||
|
||||
otel-collector:
|
||||
image: otel/opentelemetry-collector-contrib:0.115.1
|
||||
command: ["--config=/etc/otelcol/config.yaml"]
|
||||
volumes:
|
||||
- ./infra/otel/collector.yaml:/etc/otelcol/config.yaml:ro
|
||||
- ./pki:/pki:ro
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:v2.55.1
|
||||
command:
|
||||
- --config.file=/etc/prometheus/prometheus.yml
|
||||
- --storage.tsdb.path=/prometheus
|
||||
- --storage.tsdb.retention.time=15d
|
||||
volumes:
|
||||
- ./infra/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||
- promdata:/prometheus
|
||||
ports:
|
||||
- "127.0.0.1:9090:9090"
|
||||
depends_on:
|
||||
- otel-collector
|
||||
|
||||
loki:
|
||||
image: grafana/loki:3.2.1
|
||||
command: ["-config.file=/etc/loki/loki.yaml"]
|
||||
volumes:
|
||||
- ./infra/loki/loki.yaml:/etc/loki/loki.yaml:ro
|
||||
- lokidata:/loki
|
||||
|
||||
tempo:
|
||||
image: grafana/tempo:2.6.1
|
||||
command: ["-config.file=/etc/tempo/tempo.yaml"]
|
||||
volumes:
|
||||
- ./infra/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro
|
||||
- tempodata:/var/tempo
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:11.3.1
|
||||
environment:
|
||||
GF_AUTH_ANONYMOUS_ENABLED: "true"
|
||||
GF_AUTH_ANONYMOUS_ORG_ROLE: Admin
|
||||
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:-change-me}
|
||||
GF_USERS_DEFAULT_THEME: dark
|
||||
volumes:
|
||||
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
||||
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
||||
- grafanadata:/var/lib/grafana
|
||||
ports:
|
||||
- "127.0.0.1:3000:3000"
|
||||
depends_on:
|
||||
- prometheus
|
||||
- loki
|
||||
- tempo
|
||||
|
||||
volumes:
|
||||
pgdata: {}
|
||||
s3data: {}
|
||||
rabbitdata: {}
|
||||
openbaodata: {}
|
||||
promdata: {}
|
||||
lokidata: {}
|
||||
tempodata: {}
|
||||
grafanadata: {}
|
||||
|
||||
secrets:
|
||||
postgres_password:
|
||||
file: ./secrets/postgres_password.txt
|
||||
s3_root_user:
|
||||
file: ./secrets/s3_root_user.txt
|
||||
s3_root_password:
|
||||
file: ./secrets/s3_root_password.txt
|
||||
openbao_role_id:
|
||||
file: ./secrets/openbao_role_id.txt
|
||||
openbao_secret_id:
|
||||
file: ./secrets/openbao_secret_id.txt
|
||||
Reference in New Issue
Block a user