feat: add openbao and scoped service policies
This commit is contained in:
+124
-203
@@ -4,10 +4,28 @@ x-lockdown: &lockdown
|
||||
security_opt: [no-new-privileges:true]
|
||||
cap_drop: [ALL]
|
||||
|
||||
x-otel: &otel
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318}
|
||||
x-runtime: &runtime
|
||||
<<: *lockdown
|
||||
image: mtusi-messenger-lab7-api:dev
|
||||
build:
|
||||
context: .
|
||||
target: runtime
|
||||
init: true
|
||||
restart: unless-stopped
|
||||
|
||||
x-runtime-env: &runtime-env
|
||||
BAO_ADDR: https://openbao:8200
|
||||
NODE_EXTRA_CA_CERTS: /run/tls/ca.crt
|
||||
|
||||
x-s3-env: &s3-env
|
||||
S3_ENDPOINT: https://s3:9000
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_REGION: us-east-1
|
||||
|
||||
x-otel-env: &otel-env
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
|
||||
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
||||
OTEL_RESOURCE_ATTRIBUTES: ${OTEL_RESOURCE_ATTRIBUTES:-deployment.environment.name=lab}
|
||||
OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=lab
|
||||
|
||||
services:
|
||||
bootstrap:
|
||||
@@ -23,42 +41,38 @@ services:
|
||||
cap_add: [CHOWN, DAC_OVERRIDE, FOWNER]
|
||||
volumes:
|
||||
- ./infra/bootstrap.py:/work/bootstrap.py:ro
|
||||
- pki:/state
|
||||
- secrets:/state
|
||||
- baodata:/bao-data
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: "1.0", memory: 96M}
|
||||
|
||||
secrets-init:
|
||||
image: alpine:3.20.3
|
||||
openbao:
|
||||
<<: *lockdown
|
||||
image: openbao/openbao:2.4.4@sha256:595c83b42614a4d2b044608e4593c05b019c5db25bc9c185d8fff3ac96c03ddd
|
||||
user: "100:1000"
|
||||
entrypoint: [bao]
|
||||
command: ["server", "-config=/bao/config/server.hcl"]
|
||||
ports:
|
||||
- "127.0.0.1:${BAO_PORT:-8200}:8200"
|
||||
volumes:
|
||||
- secrets:/secrets
|
||||
command:
|
||||
- sh
|
||||
- -ec
|
||||
- |
|
||||
cd /secrets
|
||||
mkdir -p postgres redis api migrate s3 s3-init reconciler broker rabbitmq relay worker grafana
|
||||
for entry in pg_password:postgres:24 redis_password:redis:24 s3_root_user:s3:10 s3_root_password:s3:20 s3_access_key_id:api:10 s3_secret_access_key:api:20 broker_password:broker:24 admin_password:grafana:16; do
|
||||
file=$${entry%%:*}; rest=$${entry#*:}; dir=$${rest%%:*}; size=$${rest##*:}
|
||||
[ -s "$$dir/$$file" ] || head -c "$$size" /dev/urandom | od -An -tx1 | tr -d ' \n' > "$$dir/$$file"
|
||||
done
|
||||
rm -f s3-init/* rabbitmq/* relay/* worker/*
|
||||
cp s3/s3_root_user s3/s3_root_password api/s3_access_key_id api/s3_secret_access_key s3-init/
|
||||
db_url() { printf 'postgresql://messenger:%s@postgres:5432/messenger?connection_limit=%s&pool_timeout=5&connect_timeout=5&socket_timeout=10&application_name=%s&options=-c%%20statement_timeout%%3D5000' "$$(cat postgres/pg_password)" "$$1" "$$2"; }
|
||||
db_url 10 api > api/database_url
|
||||
db_url 5 worker > worker/database_url
|
||||
db_url 3 relay > relay/database_url
|
||||
printf 'redis://:%s@redis:6379/0' "$$(cat redis/redis_password)" > api/cache_url
|
||||
printf 'postgresql://messenger:%s@postgres:5432/messenger' "$$(cat postgres/pg_password)" > migrate/database_url
|
||||
printf 'amqp://messenger:%s@rabbitmq:5672/' "$$(cat broker/broker_password)" > worker/broker_url
|
||||
cp worker/broker_url relay/
|
||||
printf 'default_user = messenger\ndefault_pass = %s\nloopback_users = none\nlog.console = true\nlisteners.tcp.default = 5672\n' "$$(cat broker/broker_password)" > rabbitmq/10-messenger.conf
|
||||
cp api/database_url api/s3_access_key_id api/s3_secret_access_key reconciler/
|
||||
cp api/s3_access_key_id api/s3_secret_access_key worker/
|
||||
chmod 0444 postgres/* redis/* api/* migrate/* s3/* s3-init/* reconciler/* broker/* rabbitmq/* relay/* worker/* grafana/*
|
||||
- ./infra/openbao/server.hcl:/bao/config/server.hcl:ro
|
||||
- baodata:/bao/data
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: openbao}}
|
||||
environment:
|
||||
BAO_ADDR: https://openbao:8200
|
||||
BAO_CACERT: /run/tls/ca.crt
|
||||
healthcheck:
|
||||
test: ["CMD", "bao", "status"]
|
||||
interval: 3s
|
||||
timeout: 3s
|
||||
retries: 15
|
||||
depends_on:
|
||||
bootstrap: {condition: service_completed_successfully}
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.1", memory: 32M }
|
||||
limits: {cpus: "0.5", memory: 256M}
|
||||
|
||||
postgres:
|
||||
image: postgres:17.2-alpine
|
||||
@@ -74,7 +88,7 @@ services:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
- ./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}}
|
||||
- {type: volume, source: secrets, 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
|
||||
@@ -87,27 +101,19 @@ services:
|
||||
resources:
|
||||
limits: {cpus: "1.0", memory: 512M}
|
||||
|
||||
redis:
|
||||
image: redis:7.4.1-alpine
|
||||
user: redis
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- exec redis-server --save '' --appendonly no --maxmemory 64mb --maxmemory-policy allkeys-lru --requirepass "$$(cat /run/secrets/redis_password)"
|
||||
migrate:
|
||||
<<: *lockdown
|
||||
build:
|
||||
context: .
|
||||
target: migrate
|
||||
image: mtusi-messenger-lab7-migrate:dev
|
||||
volumes:
|
||||
- { type: volume, source: secrets, target: /run/secrets, read_only: true, volume: { subpath: redis } }
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: migrate}}
|
||||
depends_on:
|
||||
postgres: {condition: service_healthy}
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M }
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "redis-cli --no-auth-warning -a \"$$(cat /run/secrets/redis_password)\" ping | grep -q PONG"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
depends_on:
|
||||
secrets-init:
|
||||
condition: service_completed_successfully
|
||||
restart: unless-stopped
|
||||
limits: {cpus: "0.5", memory: 512M}
|
||||
|
||||
s3:
|
||||
<<: *lockdown
|
||||
@@ -119,7 +125,7 @@ services:
|
||||
MINIO_BROWSER: "off"
|
||||
volumes:
|
||||
- s3data:/data
|
||||
- {type: volume, source: pki, target: /run/tls, read_only: true, volume: {subpath: s3}}
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: s3}}
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-fsS", "--cacert", "/run/tls/ca.crt", "https://s3:9000/minio/health/live"]
|
||||
interval: 3s
|
||||
@@ -140,101 +146,13 @@ services:
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
volumes:
|
||||
- ./infra/s3/init.sh:/work/init.sh:ro
|
||||
- {type: volume, source: pki, target: /run/tls, read_only: true, volume: {subpath: s3-init}}
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: s3-init}}
|
||||
depends_on:
|
||||
s3: {condition: service_healthy}
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: "0.25", memory: 192M}
|
||||
|
||||
migrate:
|
||||
<<: *lockdown
|
||||
build:
|
||||
context: .
|
||||
target: migrate
|
||||
image: mtusi-messenger-lab7-migrate:dev
|
||||
volumes:
|
||||
- {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}
|
||||
|
||||
api:
|
||||
build:
|
||||
context: .
|
||||
target: runtime
|
||||
image: mtusi-messenger-lab7-api:dev
|
||||
environment:
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: 8080
|
||||
APP_ENV: ${APP_ENV:-lab}
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
||||
SHUTDOWN_DELAY_MS: 3000
|
||||
DATABASE_URL_FILE: /run/tls/database_url
|
||||
CACHE_URL_FILE: /run/secrets/cache_url
|
||||
NODE_EXTRA_CA_CERTS: /run/tls/ca.crt
|
||||
S3_ENDPOINT: https://s3:9000
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_ACCESS_KEY_ID_FILE: /run/tls/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/tls/s3_secret_access_key
|
||||
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
|
||||
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
<<: *otel
|
||||
OTEL_SERVICE_NAME: messenger-api
|
||||
volumes:
|
||||
- { type: volume, source: secrets, target: /run/secrets, read_only: true, volume: { subpath: api } }
|
||||
- { type: volume, source: pki, target: /run/tls, read_only: true, volume: { subpath: api } }
|
||||
deploy:
|
||||
replicas: ${API_REPLICAS:-2}
|
||||
resources:
|
||||
limits: { cpus: "0.5", memory: 256M }
|
||||
stop_grace_period: 10s
|
||||
depends_on:
|
||||
bootstrap:
|
||||
condition: service_completed_successfully
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
redis:
|
||||
condition: service_started
|
||||
s3-init:
|
||||
condition: service_completed_successfully
|
||||
restart: unless-stopped
|
||||
|
||||
reconciler:
|
||||
build:
|
||||
context: .
|
||||
target: runtime
|
||||
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/tls/database_url
|
||||
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
|
||||
NODE_EXTRA_CA_CERTS: /run/tls/ca.crt
|
||||
S3_ENDPOINT: https://s3:9000
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_ACCESS_KEY_ID_FILE: /run/tls/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/tls/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 }
|
||||
healthcheck:
|
||||
disable: true
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
s3-init:
|
||||
condition: service_completed_successfully
|
||||
restart: unless-stopped
|
||||
|
||||
rabbitmq:
|
||||
image: rabbitmq:4.0.5-alpine@sha256:e045b5166b9188a38eee5c99411709aa1f0ffa2ac75664053e64cb69411f7c32
|
||||
hostname: rabbitmq
|
||||
@@ -246,7 +164,7 @@ services:
|
||||
- rabbitmqdata:/var/lib/rabbitmq
|
||||
- ./infra/rabbitmq/10-messenger.conf:/etc/rabbitmq/conf.d/10-messenger.conf:ro
|
||||
- ./infra/rabbitmq/enabled_plugins:/etc/rabbitmq/enabled_plugins:ro
|
||||
- {type: volume, source: pki, target: /run/tls, read_only: true, volume: {subpath: rabbitmq}}
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: rabbitmq}}
|
||||
healthcheck:
|
||||
test: ["CMD", "rabbitmq-diagnostics", "-q", "check_port_connectivity"]
|
||||
interval: 5s
|
||||
@@ -261,78 +179,81 @@ services:
|
||||
resources:
|
||||
limits: {cpus: "0.5", memory: 512M}
|
||||
|
||||
relay:
|
||||
build:
|
||||
context: .
|
||||
target: runtime
|
||||
image: mtusi-messenger-lab7-api:dev
|
||||
command: ["node", "dist/relay.js"]
|
||||
api:
|
||||
<<: *runtime
|
||||
environment:
|
||||
NODE_EXTRA_CA_CERTS: /run/tls/ca.crt
|
||||
DATABASE_URL_FILE: /run/tls/database_url
|
||||
BROKER_URL_FILE: /run/tls/broker_url
|
||||
AMQP_TOPOLOGY_PREPROVISIONED: "true"
|
||||
JOB_STALE_SECONDS: ${JOB_STALE_SECONDS:-300}
|
||||
RELAY_FAULT: ${RELAY_FAULT:-}
|
||||
<<: *otel
|
||||
OTEL_SERVICE_NAME: messenger-relay
|
||||
<<: [*runtime-env, *s3-env, *otel-env]
|
||||
BAO_ROLE: api
|
||||
OTEL_SERVICE_NAME: messenger-api
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
|
||||
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
|
||||
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 } }
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: api}}
|
||||
depends_on:
|
||||
openbao: {condition: service_healthy}
|
||||
migrate: {condition: service_completed_successfully}
|
||||
s3-init: {condition: service_completed_successfully}
|
||||
deploy:
|
||||
replicas: ${API_REPLICAS:-2}
|
||||
resources:
|
||||
limits: {cpus: "0.5", memory: 384M}
|
||||
|
||||
relay:
|
||||
<<: *runtime
|
||||
environment:
|
||||
<<: [*runtime-env, *otel-env]
|
||||
BAO_ROLE: relay
|
||||
OTEL_SERVICE_NAME: messenger-relay
|
||||
AMQP_TOPOLOGY_PREPROVISIONED: "true"
|
||||
volumes:
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: relay}}
|
||||
depends_on:
|
||||
openbao: {condition: service_healthy}
|
||||
migrate: {condition: service_completed_successfully}
|
||||
rabbitmq: {condition: service_healthy}
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M }
|
||||
healthcheck:
|
||||
disable: true
|
||||
stop_grace_period: 10s
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
rabbitmq:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
limits: {cpus: "0.25", memory: 192M}
|
||||
|
||||
worker:
|
||||
build:
|
||||
context: .
|
||||
target: runtime
|
||||
image: mtusi-messenger-lab7-api:dev
|
||||
command: ["node", "dist/worker.js"]
|
||||
<<: *runtime
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/tls/database_url
|
||||
BROKER_URL_FILE: /run/tls/broker_url
|
||||
<<: [*runtime-env, *s3-env, *otel-env]
|
||||
BAO_ROLE: worker
|
||||
OTEL_SERVICE_NAME: messenger-worker
|
||||
AMQP_TOPOLOGY_PREPROVISIONED: "true"
|
||||
NODE_EXTRA_CA_CERTS: /run/tls/ca.crt
|
||||
S3_ENDPOINT: https://s3:9000
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_ACCESS_KEY_ID_FILE: /run/tls/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/tls/s3_secret_access_key
|
||||
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
|
||||
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
|
||||
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-2}
|
||||
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
||||
JOB_LEASE_SECONDS: ${JOB_LEASE_SECONDS:-90}
|
||||
WORKER_FAULT: ${WORKER_FAULT:-}
|
||||
<<: *otel
|
||||
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 } }
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: worker}}
|
||||
depends_on:
|
||||
openbao: {condition: service_healthy}
|
||||
migrate: {condition: service_completed_successfully}
|
||||
rabbitmq: {condition: service_healthy}
|
||||
s3-init: {condition: service_completed_successfully}
|
||||
stop_grace_period: 30s
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "1.0", memory: 768M }
|
||||
healthcheck:
|
||||
disable: true
|
||||
stop_grace_period: 30s
|
||||
limits: {cpus: "1.0", memory: 768M}
|
||||
|
||||
reconciler:
|
||||
<<: *runtime
|
||||
command: ["node", "dist/stand.js", "--apply", "--loop"]
|
||||
environment:
|
||||
<<: [*runtime-env, *s3-env]
|
||||
BAO_ROLE: reconciler
|
||||
volumes:
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: reconciler}}
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
rabbitmq:
|
||||
condition: service_healthy
|
||||
s3-init:
|
||||
condition: service_completed_successfully
|
||||
restart: unless-stopped
|
||||
openbao: {condition: service_healthy}
|
||||
migrate: {condition: service_completed_successfully}
|
||||
s3-init: {condition: service_completed_successfully}
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: "0.25", memory: 192M}
|
||||
|
||||
lb:
|
||||
<<: *lockdown
|
||||
@@ -342,7 +263,7 @@ services:
|
||||
- "127.0.0.1:${HTTPS_PORT:-8443}:8443"
|
||||
volumes:
|
||||
- ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
- {type: volume, source: pki, target: /run/tls, read_only: true, volume: {subpath: lb}}
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: lb}}
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8404/"]
|
||||
interval: 3s
|
||||
@@ -440,7 +361,7 @@ services:
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
depends_on:
|
||||
secrets-init:
|
||||
bootstrap:
|
||||
condition: service_completed_successfully
|
||||
prometheus:
|
||||
condition: service_healthy
|
||||
@@ -458,7 +379,7 @@ services:
|
||||
working_dir: /work
|
||||
volumes:
|
||||
- .:/work:ro
|
||||
- {type: volume, source: pki, target: /run/tls, read_only: true, volume: {subpath: checks}}
|
||||
- {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: checks}}
|
||||
depends_on:
|
||||
bootstrap: {condition: service_completed_successfully}
|
||||
deploy:
|
||||
@@ -466,6 +387,8 @@ services:
|
||||
limits: {cpus: "0.5", memory: 128M}
|
||||
|
||||
volumes:
|
||||
secrets:
|
||||
baodata:
|
||||
pgdata:
|
||||
s3data:
|
||||
rabbitmqdata:
|
||||
@@ -473,8 +396,6 @@ volumes:
|
||||
lokidata:
|
||||
tempodata:
|
||||
grafanadata:
|
||||
secrets:
|
||||
pki:
|
||||
|
||||
networks:
|
||||
telemetry:
|
||||
|
||||
Reference in New Issue
Block a user