feat: enforce postgres tls and separate database roles
This commit is contained in:
+30
-24
@@ -63,24 +63,29 @@ services:
|
||||
postgres:
|
||||
image: postgres:17.2-alpine
|
||||
environment:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_USER: stand_operator
|
||||
POSTGRES_DB: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/pg_password
|
||||
POSTGRES_PASSWORD_FILE: /run/tls/operator_password
|
||||
command: ["postgres", "-c", "ssl=on", "-c", "ssl_cert_file=/run/tls/postgres.crt",
|
||||
"-c", "ssl_key_file=/run/tls/postgres.key", "-c", "ssl_min_protocol_version=TLSv1.2",
|
||||
"-c", "hba_file=/etc/postgresql/pg_hba.conf"]
|
||||
security_opt: [no-new-privileges:true]
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
- { type: volume, source: secrets, target: /run/secrets, read_only: true, volume: { subpath: postgres } }
|
||||
- ./infra/postgres/init.sh:/docker-entrypoint-initdb.d/roles.sh:ro
|
||||
- ./infra/postgres/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro
|
||||
- {type: volume, source: pki, target: /run/tls, read_only: true, volume: {subpath: postgres}}
|
||||
healthcheck:
|
||||
test: ["CMD", "pg_isready", "-d", "host=postgres dbname=messenger user=migrate sslmode=verify-full sslrootcert=/run/tls/ca.crt"]
|
||||
interval: 3s
|
||||
timeout: 3s
|
||||
retries: 15
|
||||
depends_on:
|
||||
bootstrap: {condition: service_completed_successfully}
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "1.0", memory: 512M }
|
||||
healthcheck:
|
||||
test: ["CMD", "pg_isready", "-U", "messenger", "-d", "messenger"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
depends_on:
|
||||
secrets-init:
|
||||
condition: service_completed_successfully
|
||||
restart: unless-stopped
|
||||
limits: {cpus: "1.0", memory: 512M}
|
||||
|
||||
redis:
|
||||
image: redis:7.4.1-alpine
|
||||
@@ -158,20 +163,18 @@ services:
|
||||
condition: service_healthy
|
||||
|
||||
migrate:
|
||||
<<: *lockdown
|
||||
build:
|
||||
context: .
|
||||
target: migrate
|
||||
image: mtusi-messenger-lab7-migrate:dev
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
volumes:
|
||||
- { type: volume, source: secrets, target: /run/secrets, read_only: true, volume: { subpath: migrate } }
|
||||
- {type: volume, source: pki, target: /run/tls, read_only: true, volume: {subpath: migrate}}
|
||||
depends_on:
|
||||
postgres: {condition: service_healthy}
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.5", memory: 512M }
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
limits: {cpus: "0.5", memory: 512M}
|
||||
|
||||
api:
|
||||
build:
|
||||
@@ -185,7 +188,7 @@ services:
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
||||
SHUTDOWN_DELAY_MS: 3000
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
DATABASE_URL_FILE: /run/tls/database_url
|
||||
CACHE_URL_FILE: /run/secrets/cache_url
|
||||
S3_ENDPOINT: http://s3:9000
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
@@ -223,7 +226,7 @@ services:
|
||||
image: mtusi-messenger-lab7-api:dev
|
||||
command: ["node", "dist/reconcile.js", "--apply", "--loop", "--grace-seconds=${RECONCILE_GRACE_SECONDS:-3600}", "--interval-seconds=${RECONCILE_INTERVAL_SECONDS:-300}"]
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
DATABASE_URL_FILE: /run/tls/database_url
|
||||
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
|
||||
S3_ENDPOINT: http://s3:9000
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
@@ -232,6 +235,7 @@ services:
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
||||
volumes:
|
||||
- { type: volume, source: secrets, target: /run/secrets, read_only: true, volume: { subpath: reconciler } }
|
||||
- { type: volume, source: pki, target: /run/tls, read_only: true, volume: { subpath: reconciler } }
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M }
|
||||
@@ -272,7 +276,7 @@ services:
|
||||
image: mtusi-messenger-lab7-api:dev
|
||||
command: ["node", "dist/relay.js"]
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
DATABASE_URL_FILE: /run/tls/database_url
|
||||
BROKER_URL_FILE: /run/secrets/broker_url
|
||||
JOB_STALE_SECONDS: ${JOB_STALE_SECONDS:-300}
|
||||
RELAY_FAULT: ${RELAY_FAULT:-}
|
||||
@@ -280,6 +284,7 @@ services:
|
||||
OTEL_SERVICE_NAME: messenger-relay
|
||||
volumes:
|
||||
- { type: volume, source: secrets, target: /run/secrets, read_only: true, volume: { subpath: relay } }
|
||||
- { type: volume, source: pki, target: /run/tls, read_only: true, volume: { subpath: relay } }
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M }
|
||||
@@ -300,7 +305,7 @@ services:
|
||||
image: mtusi-messenger-lab7-api:dev
|
||||
command: ["node", "dist/worker.js"]
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
DATABASE_URL_FILE: /run/tls/database_url
|
||||
BROKER_URL_FILE: /run/secrets/broker_url
|
||||
S3_ENDPOINT: http://s3:9000
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
@@ -317,6 +322,7 @@ services:
|
||||
OTEL_SERVICE_NAME: messenger-worker
|
||||
volumes:
|
||||
- { type: volume, source: secrets, target: /run/secrets, read_only: true, volume: { subpath: worker } }
|
||||
- { type: volume, source: pki, target: /run/tls, read_only: true, volume: { subpath: worker } }
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "1.0", memory: 768M }
|
||||
|
||||
Reference in New Issue
Block a user