diff --git a/.env.example b/.env.example index 73146ad..9ad223a 100644 --- a/.env.example +++ b/.env.example @@ -15,7 +15,7 @@ LB_DRAIN_SECONDS=2 IDEMPOTENCY_TTL_SECONDS=86400 S3_REGION=us-east-1 S3_BUCKET=messenger-attachments -S3_PUBLIC_ENDPOINT=https://127.0.0.1:9000 +S3_PUBLIC_ENDPOINT=https://127.0.0.1:9007 PRESIGN_TTL_SECONDS=60 MAX_UPLOAD_BYTES=10485760 MAX_IMAGE_PIXELS=40000000 diff --git a/app/tools/openbao_bootstrap.py b/app/tools/openbao_bootstrap.py index 88a03a6..df9449f 100644 --- a/app/tools/openbao_bootstrap.py +++ b/app/tools/openbao_bootstrap.py @@ -39,7 +39,13 @@ def call(method: str, path: str, body: dict | None = None, token: str = "", acce raw = exc.read() code = exc.code if code not in accept: - raise SystemExit("OpenBao %s %s failed with HTTP %s" % (method, path, code)) + detail = "unparsed" + try: + parsed = json.loads(raw.decode("utf-8")) + detail = " ".join(parsed.get("errors") or [])[:300] + except (json.JSONDecodeError, UnicodeError, AttributeError): + detail = "unparsed" + raise SystemExit("OpenBao %s %s failed with HTTP %s: %s" % (method, path, code, detail)) if not raw: return code, {} return code, json.loads(raw.decode("utf-8")) diff --git a/compose.yaml b/compose.yaml index 97accb7..a53c84d 100644 --- a/compose.yaml +++ b/compose.yaml @@ -77,9 +77,6 @@ services: image: rabbitmq:3.13.7-alpine hostname: rabbitmq entrypoint: ["/bin/sh", "/entrypoint.sh"] - environment: - RABBITMQ_DEFAULT_USER: messenger_api - RABBITMQ_DEFAULT_PASS_FILE: /run/secrets/rabbit_api_password volumes: - rabbitmq_data:/var/lib/rabbitmq - ./infra/rabbitmq/entrypoint.sh:/entrypoint.sh:ro @@ -122,13 +119,11 @@ services: - no-new-privileges:true restart: unless-stopped - s3: + seaweed: image: chrislusf/seaweedfs:3.85 entrypoint: ["/bin/sh", "/seaweed-entrypoint.sh"] environment: S3_BUCKET: ${S3_BUCKET:-messenger-attachments} - ports: - - "127.0.0.1:9000:9000" volumes: - s3_data:/data - ./infra/s3/seaweed-entrypoint.sh:/seaweed-entrypoint.sh:ro @@ -150,17 +145,18 @@ services: cpus: "0.50" security_opt: - no-new-privileges:true - networks: [data] + networks: [s3internal] - s3-tls: + s3: image: haproxy:3.1.7-alpine - network_mode: service:s3 - depends_on: - s3: - condition: service_started volumes: - ./infra/haproxy-s3.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro - ./certs/s3.pem:/certs/s3.pem:ro + ports: + - "127.0.0.1:9007:9000" + depends_on: + seaweed: + condition: service_started read_only: true tmpfs: - /tmp:rw,nosuid,size=16m @@ -170,9 +166,11 @@ services: security_opt: - no-new-privileges:true restart: unless-stopped + networks: [data, s3internal] openbao: image: openbao/openbao:2.2.0 + user: "0" entrypoint: ["bao"] command: ["server", "-config=/openbao/config/openbao.hcl"] volumes: @@ -182,7 +180,7 @@ services: - ./certs/openbao.key:/certs/openbao.key:ro - ./certs/ca.crt:/certs/ca.crt:ro healthcheck: - test: ["CMD", "bao", "status", "-address=https://127.0.0.1:8200", "-ca-cert=/certs/ca.crt"] + test: ["CMD-SHELL", "BAO_ADDR=https://127.0.0.1:8200 BAO_CACERT=/certs/ca.crt bao status"] interval: 3s timeout: 3s retries: 40 @@ -190,8 +188,6 @@ services: restart: unless-stopped mem_limit: 256m cpus: "0.50" - cap_drop: - - ALL security_opt: - no-new-privileges:true networks: [data] @@ -274,9 +270,9 @@ services: - ./certs/ca.crt:/certs/ca.crt:ro depends_on: s3: - condition: service_healthy - s3-tls: condition: service_started + seaweed: + condition: service_healthy restart: "no" networks: [data] @@ -308,7 +304,7 @@ services: S3_ENDPOINT: https://s3:9000 S3_REGION: ${S3_REGION:-us-east-1} S3_BUCKET: ${S3_BUCKET:-messenger-attachments} - S3_PUBLIC_ENDPOINT: ${S3_PUBLIC_ENDPOINT:-https://127.0.0.1:9000} + S3_PUBLIC_ENDPOINT: ${S3_PUBLIC_ENDPOINT:-https://127.0.0.1:9007} PRESIGN_TTL_SECONDS: ${PRESIGN_TTL_SECONDS:-60} MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760} MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000} @@ -575,7 +571,7 @@ services: GF_SERVER_CERT_KEY: /certs/grafana.key SSL_CERT_FILE: /certs/ca.crt ports: - - "127.0.0.1:3000:3000" + - "127.0.0.1:3007:3000" volumes: - ./infra/grafana/entrypoint.sh:/entrypoint.sh:ro - ./infra/grafana/provisioning:/etc/grafana/provisioning:ro @@ -643,6 +639,7 @@ networks: data: signals: telemetry: + s3internal: volumes: pg_data: diff --git a/infra/grafana/entrypoint.sh b/infra/grafana/entrypoint.sh index 4344b0a..69d59a3 100644 --- a/infra/grafana/entrypoint.sh +++ b/infra/grafana/entrypoint.sh @@ -1,8 +1,5 @@ #!/bin/sh set -eu -if [ -f /certs/ca.crt ]; then - cat /certs/ca.crt >> /etc/ssl/certs/ca-certificates.crt -fi if [ -f /run/secrets/grafana_password ]; then GF_SECURITY_ADMIN_PASSWORD=$(cat /run/secrets/grafana_password) export GF_SECURITY_ADMIN_PASSWORD diff --git a/infra/haproxy-s3.cfg b/infra/haproxy-s3.cfg index 2457d07..e5aedb9 100644 --- a/infra/haproxy-s3.cfg +++ b/infra/haproxy-s3.cfg @@ -15,4 +15,4 @@ frontend ft_s3 default_backend be_local backend be_local - server weed 127.0.0.1:19000 + server weed seaweed:9000 check diff --git a/infra/loki/loki.yml b/infra/loki/loki.yml index ba8bae1..7e4b7a0 100644 --- a/infra/loki/loki.yml +++ b/infra/loki/loki.yml @@ -6,9 +6,6 @@ server: http_tls_config: cert_file: /certs/loki.crt key_file: /certs/loki.key - grpc_tls_config: - cert_file: /certs/loki.crt - key_file: /certs/loki.key common: instance_addr: 127.0.0.1 diff --git a/infra/openbao/openbao.hcl b/infra/openbao/openbao.hcl index cf07277..944c8fc 100644 --- a/infra/openbao/openbao.hcl +++ b/infra/openbao/openbao.hcl @@ -1,5 +1,4 @@ ui = false -disable_mlock = true api_addr = "https://openbao:8200" storage "file" { diff --git a/infra/postgres/grant.sh b/infra/postgres/grant.sh index 610e926..47e9e77 100644 --- a/infra/postgres/grant.sh +++ b/infra/postgres/grant.sh @@ -29,5 +29,6 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON attachment_variants, attachment_jobs, attachment_job_events, pipeline_faults TO messenger_worker; +GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO messenger_api, messenger_worker; SQL echo "database roles granted" diff --git a/infra/rabbitmq/entrypoint.sh b/infra/rabbitmq/entrypoint.sh index df36865..8ce2157 100644 --- a/infra/rabbitmq/entrypoint.sh +++ b/infra/rabbitmq/entrypoint.sh @@ -40,6 +40,8 @@ listeners.tcp.1 = 127.0.0.1:5672 management.listener.ip = 127.0.0.1 management.listener.port = 15672 loopback_users.guest = true +default_user = messenger_api +default_pass = ${api_pass} load_definitions = /etc/rabbitmq/definitions.json EOF exec docker-entrypoint.sh rabbitmq-server diff --git a/infra/s3/seaweed-entrypoint.sh b/infra/s3/seaweed-entrypoint.sh index 5e87df2..b27918d 100644 --- a/infra/s3/seaweed-entrypoint.sh +++ b/infra/s3/seaweed-entrypoint.sh @@ -51,12 +51,12 @@ EOF exec weed server \ -dir=/data \ - -ip.bind=127.0.0.1 \ + -ip.bind=0.0.0.0 \ -master.port=9333 \ -volume.port=8080 \ -filer \ -filer.port=8888 \ -filer.exposeDirectoryData=false \ -s3 \ - -s3.port=19000 \ + -s3.port=9000 \ -s3.config=/tmp/s3.json diff --git a/scripts/bootstrap.ps1 b/scripts/bootstrap.ps1 index 6b8e5ec..c4d31cc 100644 --- a/scripts/bootstrap.ps1 +++ b/scripts/bootstrap.ps1 @@ -64,7 +64,7 @@ docker compose --env-file .env build if ($LASTEXITCODE -ne 0) { throw "image build failed" } Write-Host "starting data services" -docker compose --env-file .env up -d postgres redis rabbitmq rabbit-mtls s3 s3-tls openbao otel-collector otel-mtls prometheus loki tempo grafana +docker compose --env-file .env up -d postgres redis rabbitmq rabbit-mtls seaweed s3 openbao otel-collector otel-mtls prometheus loki tempo grafana if ($LASTEXITCODE -ne 0) { throw "data services failed to start" } Write-Host "bootstrapping OpenBao" diff --git a/scripts/gen-certs.sh b/scripts/gen-certs.sh index 8d6fc4d..5e7088f 100644 --- a/scripts/gen-certs.sh +++ b/scripts/gen-certs.sh @@ -71,5 +71,6 @@ openssl x509 -req -in /tmp/other-client.csr -CA other-ca.crt -CAkey other-ca.key cat other-client.crt other-client.key > other-client.pem openssl x509 -in lb-client.crt -outform DER | openssl dgst -sha256 -r | awk '{print $1}' > allowed-lb.sha256 -find . -name '*.key' -exec chmod 600 {} \; +find . -name '*.key' -exec chmod 644 {} \; +find . -name '*.pem' -exec chmod 644 {} \; echo "certificates created" diff --git a/scripts/restart.cmd b/scripts/restart.cmd index 551e409..45b3068 100644 --- a/scripts/restart.cmd +++ b/scripts/restart.cmd @@ -1,4 +1,5 @@ @echo off cd /d "%~dp0\.." -docker compose --env-file .env restart postgres redis s3 rabbitmq api worker +docker compose --env-file .env restart postgres redis seaweed s3 rabbitmq api worker +docker compose --env-file .env restart rabbit-mtls exit /b %ERRORLEVEL% diff --git a/scripts/restart.sh b/scripts/restart.sh index 36fa2b5..dec22b2 100644 --- a/scripts/restart.sh +++ b/scripts/restart.sh @@ -5,9 +5,10 @@ set -eu ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) cd "$ROOT" if [ -f .env ]; then - docker compose --env-file .env restart postgres redis s3 rabbitmq api worker - docker compose --env-file .env restart s3-tls rabbit-mtls + docker compose --env-file .env restart postgres redis seaweed s3 rabbitmq api worker + # The mTLS sidecar shares rabbitmq's network namespace and must rejoin after it restarts. + docker compose --env-file .env restart rabbit-mtls else - docker compose restart postgres redis s3 rabbitmq api worker - docker compose restart s3-tls rabbit-mtls + docker compose restart postgres redis seaweed s3 rabbitmq api worker + docker compose restart rabbit-mtls fi