forked from mtusi2026/mtusi2026lab7
lab7: TLS ко всем зависимостям и телеметрии; раздельные роли PostgreSQL (GRANT по коду), ACL Valkey, AMQPS, HTTPS S3, mTLS Collector/Prometheus/Loki/Tempo/Grafana
This commit is contained in:
+258
-114
@@ -1,26 +1,31 @@
|
||||
# Lab 6 stand = lab 5 + observability (docs/OBSERVABILITY.md):
|
||||
# api x2 / relay / worker --OTLP/HTTP--> otel-collector --> prometheus (metrics, + alert rules)
|
||||
# --> loki (logs) --> tempo (traces)
|
||||
# grafana (127.0.0.1:3000): provisioned datasources + dashboard + Prometheus alert view.
|
||||
# The application never waits for telemetry: no depends_on on it, bounded SDK queues.
|
||||
# Network `telemetry` (internal) joins only the apps and these five services.
|
||||
# Lab 7 stand = lab 6 + security on every trust boundary (contracts/trust-matrix.md):
|
||||
# client --HTTPS :8443 (public CA)--> lb (HAProxy) --mTLS (internal CA, SAN allowlist lb)--> api x2
|
||||
# api/relay/worker --TLS verify-full--> postgres (own role per service, GRANT only what it does)
|
||||
# api --TLS (rediss)--> valkey (ACL user api) api/worker --HTTPS--> s3 (own key pair each)
|
||||
# relay/worker --AMQPS 5671--> broker (publish-only / consume-only users)
|
||||
# api/relay/worker --OTLP/HTTPS + client cert--> otel-collector --mTLS--> prometheus/loki/tempo
|
||||
# grafana (https://localhost:3000, public CA) --mTLS--> the three datasources
|
||||
# Nothing speaks plaintext over a container network. Plaintext remains only on a container's own
|
||||
# loopback (healthchecks, the internal hops of SeaweedFS/Loki/Tempo): closed local hops.
|
||||
#
|
||||
# Lab 5 part: client -> HAProxy (lb) -> API x N (scalable service `api`)
|
||||
# -> PostgreSQL (metadata, jobs, outbox: source of truth) + Valkey (sessions)
|
||||
# + SeaweedFS S3 (staging bucket and final bucket, both private)
|
||||
# Lab 6 part: api x2 / relay / worker --OTLP--> otel-collector --> prometheus (metrics + alert rules)
|
||||
# --> loki (logs) --> tempo (traces); grafana: provisioned datasources + dashboard.
|
||||
# The application never waits for telemetry: no depends_on on it, bounded SDK queues.
|
||||
# Lab 5 part: PostgreSQL (metadata, jobs, outbox: source of truth) + Valkey (sessions)
|
||||
# + SeaweedFS S3 (staging bucket and final bucket, both private)
|
||||
# relay : outbox in PostgreSQL -> RabbitMQ (publisher confirms) [service `relay`]
|
||||
# broker : RabbitMQ 4.3, durable quorum queue + dead-letter queue [service `broker`]
|
||||
# worker : RabbitMQ -> variants -> final bucket + PostgreSQL, then ack [service `worker`]
|
||||
# From a clean clone (details and Windows notes: REPORT.md, docs/WINDOWS.md):
|
||||
# python scripts/init_secrets.py # once: random local credentials into ./secrets (git-ignored)
|
||||
# cp .env.example .env # optional overrides (API_REPLICAS, limits, ...)
|
||||
# docker compose --env-file .env up -d --build --wait
|
||||
# From a clean clone: docs/OPERATOR.md (Windows: docs/WINDOWS.md).
|
||||
# .venv/Scripts/python scripts/init_secrets.py # once: credentials + PKI into ./secrets (git-ignored)
|
||||
# docker compose up -d --build --wait
|
||||
# Order: postgres/valkey/s3/broker healthy -> migrate + s3-init (ONE run each, exit 0)
|
||||
# -> api healthy -> lb; relay and worker start after migrate/s3-init.
|
||||
# Images are pinned by version AND digest. Passwords/keys are passed only as secret files, and
|
||||
# every service gets only the secrets it needs. Only the LB publishes ports (loopback only).
|
||||
# every service gets only the secrets it needs. Only the LB (8443) and Grafana (3000) publish
|
||||
# ports, both HTTPS, both on loopback only.
|
||||
# Networks: `edge` (lb <-> api); internal (no route outside): `data` (postgres/valkey),
|
||||
# `storage` (s3), `queue` (broker). The API is NOT on `queue`: it never talks to the broker.
|
||||
# `storage` (s3), `queue` (broker), `telemetry`. The API is NOT on `queue`.
|
||||
name: ${COMPOSE_PROJECT_NAME:-mtusi-lab7}
|
||||
|
||||
x-api-env: &api-env
|
||||
@@ -42,7 +47,7 @@ x-api-env: &api-env
|
||||
DOCS_ENABLED: ${DOCS_ENABLED:-true}
|
||||
MESSAGE_WRITE_PATH: ${MESSAGE_WRITE_PATH:-function}
|
||||
# S3: the API's own key pair (Write staging + Read final, see infra/seaweedfs/start.sh).
|
||||
S3_ENDPOINT: ${S3_ENDPOINT:-http://s3:8333}
|
||||
S3_ENDPOINT: ${S3_ENDPOINT:-https://s3:8333}
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_STAGING_BUCKET: ${S3_STAGING_BUCKET:-messenger-staging}
|
||||
@@ -62,18 +67,23 @@ x-api-env: &api-env
|
||||
# Lab 5: pipeline version and attempt budget of the jobs created by uploads.
|
||||
PIPELINE_VERSION: ${PIPELINE_VERSION:-1}
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
# Failure experiments only (student-tests, bench/); empty = no injected failures.
|
||||
# Failure experiments only (student-tests); empty = no injected failures.
|
||||
FAULT_POINTS: ${API_FAULT_POINTS:-}
|
||||
# Lab 7: the CA every outgoing TLS connection (S3, Valkey) verifies the server with.
|
||||
TLS_CA_FILE: /run/secrets/internal-ca.crt
|
||||
|
||||
# Lab 6: OpenTelemetry SDK settings shared by api, relay and worker (src/messenger/telemetry.py).
|
||||
# OTEL_SDK_DISABLED=true = telemetry off (track 1 baseline). Sampler: head sampling in the SDK
|
||||
# (parentbased_always_on | parentbased_traceidratio + OTEL_TRACES_SAMPLER_ARG). Exporter timeout
|
||||
# 3 s and bounded batch queues (2048 spans / log records): a dead Collector costs dropped telemetry,
|
||||
# not memory or request latency.
|
||||
# Exporter timeout 3 s and bounded batch queues (2048 spans / log records): a dead Collector costs
|
||||
# dropped telemetry, not memory or request latency.
|
||||
# Lab 7: OTLP over HTTPS; the SDK verifies the Collector (internal CA, hostname otel-collector) and
|
||||
# presents the service's own certificate (/run/secrets/service.crt: SAN api / relay / worker).
|
||||
x-otel-env: &otel-env
|
||||
OTEL_SDK_DISABLED: ${OTEL_SDK_DISABLED:-false}
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318}
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
||||
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
||||
OTEL_EXPORTER_OTLP_CERTIFICATE: /run/secrets/internal-ca.crt
|
||||
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: /run/secrets/service.crt
|
||||
OTEL_EXPORTER_OTLP_CLIENT_KEY: /run/secrets/service.key
|
||||
OTEL_EXPORTER_OTLP_TIMEOUT: ${OTEL_EXPORTER_OTLP_TIMEOUT:-3}
|
||||
OTEL_RESOURCE_ATTRIBUTES: ${OTEL_RESOURCE_ATTRIBUTES:-deployment.environment.name=lab}
|
||||
OTEL_TRACES_SAMPLER: ${OTEL_TRACES_SAMPLER:-parentbased_always_on}
|
||||
@@ -92,7 +102,7 @@ x-pipeline-env: &pipeline-env
|
||||
BROKER_URL_FILE: /run/secrets/broker_url
|
||||
DB_POOL_MAX: ${PIPELINE_DB_POOL_MAX:-6}
|
||||
DB_TIMEOUT_SECONDS: ${DB_TIMEOUT_SECONDS:-3}
|
||||
S3_ENDPOINT: ${S3_ENDPOINT:-http://s3:8333}
|
||||
S3_ENDPOINT: ${S3_ENDPOINT:-https://s3:8333}
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_STAGING_BUCKET: ${S3_STAGING_BUCKET:-messenger-staging}
|
||||
@@ -105,21 +115,46 @@ x-pipeline-env: &pipeline-env
|
||||
JOB_RETRY_BASE_SECONDS: ${JOB_RETRY_BASE_SECONDS:-2}
|
||||
JOB_RETRY_MAX_SECONDS: ${JOB_RETRY_MAX_SECONDS:-60}
|
||||
QUEUED_REPUBLISH_SECONDS: ${QUEUED_REPUBLISH_SECONDS:-300}
|
||||
TLS_CA_FILE: /run/secrets/internal-ca.crt
|
||||
|
||||
services:
|
||||
# PostgreSQL 18. Lab 7: TLS (internal CA, SAN postgres), pg_hba accepts ONLY hostssl logins of the
|
||||
# service roles; the superuser `postgres` exists for initdb and the operator (local socket).
|
||||
# The server key must be 0600 and owned by postgres: it is copied from the secret into a tmpfs
|
||||
# at start (the bind-mounted secret cannot be chowned), then the image's entrypoint drops root.
|
||||
postgres:
|
||||
image: postgres:18.6-bookworm@sha256:afc7e2d441324c0388fa80c3d24f733b4194a4eb7f47dd8ee2b08eb1a24a647c
|
||||
environment:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_DB: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
# pg_stat_statements: per-statement counters for the experiments.
|
||||
command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", "-c", "max_connections=${PG_MAX_CONNECTIONS:-100}"]
|
||||
secrets: [postgres_password]
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- >-
|
||||
install -o postgres -g postgres -m 600 /run/secrets/postgres.key /run/pgtls/server.key &&
|
||||
exec docker-entrypoint.sh postgres
|
||||
-c ssl=on -c ssl_cert_file=/run/secrets/postgres.crt -c ssl_key_file=/run/pgtls/server.key
|
||||
-c ssl_min_protocol_version=TLSv1.2 -c hba_file=/etc/postgresql/pg_hba.conf
|
||||
-c password_encryption=scram-sha-256
|
||||
-c shared_preload_libraries=pg_stat_statements -c max_connections=${PG_MAX_CONNECTIONS:-100}
|
||||
secrets:
|
||||
- postgres_password
|
||||
- pg_migrate_password
|
||||
- pg_api_password
|
||||
- pg_relay_password
|
||||
- pg_worker_password
|
||||
- pg_jobctl_password
|
||||
- pg_auditor_password
|
||||
- {source: pki_postgres_crt, target: postgres.crt}
|
||||
- {source: pki_postgres_key, target: postgres.key}
|
||||
tmpfs:
|
||||
- /run/pgtls:size=1m,mode=0755
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql # PostgreSQL 18 image keeps PGDATA under this path
|
||||
- ./infra/postgres/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro
|
||||
- ./infra/postgres/initdb:/docker-entrypoint-initdb.d:ro
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger -q"]
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres -d messenger -q"]
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
@@ -131,24 +166,22 @@ services:
|
||||
resources:
|
||||
limits: {cpus: "${PG_CPUS:-2.0}", memory: "${PG_MEMORY:-1g}"}
|
||||
|
||||
# Valkey: sessions + login rate limit. Lab 7: TLS only (port 0, tls-port 6379), ACL user `api`
|
||||
# (infra/valkey/start.sh), `default` user off.
|
||||
valkey:
|
||||
image: valkey/valkey:8.1.3-bookworm@sha256:fea8b3e67b15729d4bb70589eb03367bab9ad1ee89c876f54327fc7c6e618571
|
||||
# The password goes into a config include readable only by the valkey user,
|
||||
# so it never appears in the process arguments. docker-entrypoint.sh drops root.
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- >-
|
||||
umask 077 &&
|
||||
printf 'requirepass %s\n' "$$(cat /run/secrets/valkey_password)" > /tmp/requirepass.conf &&
|
||||
chown valkey /tmp/requirepass.conf &&
|
||||
exec docker-entrypoint.sh valkey-server /etc/valkey/valkey.conf
|
||||
secrets: [valkey_password]
|
||||
entrypoint: ["/bin/sh", "/etc/valkey/start.sh"]
|
||||
secrets:
|
||||
- valkey_api_password
|
||||
- {source: pki_valkey_crt, target: valkey.crt}
|
||||
- {source: pki_valkey_key, target: valkey.key}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
volumes:
|
||||
- ./infra/valkey/valkey.conf:/etc/valkey/valkey.conf:ro
|
||||
- ./infra/valkey/start.sh:/etc/valkey/start.sh:ro
|
||||
- valkeydata:/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "REDISCLI_AUTH=\"$$(cat /run/secrets/valkey_password)\" valkey-cli ping | grep -q PONG"]
|
||||
test: ["CMD-SHELL", "REDISCLI_AUTH=\"$$(cat /run/secrets/valkey_api_password)\" valkey-cli --tls --cacert /run/secrets/internal-ca.crt -h localhost --user api ping | grep -q PONG"]
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
@@ -160,8 +193,8 @@ services:
|
||||
limits: {cpus: "${VALKEY_CPUS:-0.5}", memory: 256m}
|
||||
|
||||
# S3-compatible object storage (SeaweedFS: master + volume + filer + S3 gateway in one process).
|
||||
# Bytes live ONLY here, on the named volume s3data: staging bucket (originals accepted before
|
||||
# 202) and final bucket (published originals and variants). Identities: infra/seaweedfs/start.sh.
|
||||
# Bytes live ONLY here, on the named volume s3data. Identities: infra/seaweedfs/start.sh.
|
||||
# Lab 7: the S3 port is HTTPS only (internal CA, SAN s3).
|
||||
s3:
|
||||
image: chrislusf/seaweedfs:4.46@sha256:08d516132314207d10c8e37cbffc1f32b147d870169688734cc61c6231625b62
|
||||
entrypoint: ["/bin/sh", "/etc/seaweedfs/start.sh"]
|
||||
@@ -179,12 +212,15 @@ services:
|
||||
- s3_worker_secret_access_key
|
||||
- s3_auditor_access_key_id
|
||||
- s3_auditor_secret_access_key
|
||||
- {source: pki_s3_crt, target: s3.crt}
|
||||
- {source: pki_s3_key, target: s3.key}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
volumes:
|
||||
- ./infra/seaweedfs/start.sh:/etc/seaweedfs/start.sh:ro
|
||||
- s3data:/data
|
||||
healthcheck:
|
||||
# Unauthenticated health endpoint of the S3 gateway (200 once it serves requests).
|
||||
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8333/healthz"]
|
||||
# Unauthenticated health endpoint of the S3 gateway, over HTTPS with full verification.
|
||||
test: ["CMD", "curl", "-fsS", "-o", "/dev/null", "--cacert", "/run/secrets/internal-ca.crt", "https://localhost:8333/healthz"]
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
@@ -196,22 +232,24 @@ services:
|
||||
resources:
|
||||
limits: {cpus: "${S3_CPUS:-1.0}", memory: "${S3_MEMORY:-1g}"}
|
||||
|
||||
# Lab 5: RabbitMQ. Topology (exchange, quorum queue, DLX/DLQ) and users come from definition
|
||||
# files imported at boot (infra/rabbitmq, secrets/rabbitmq_users.json). Messages of the quorum
|
||||
# queue live on the named volume rabbitmqdata. No management UI, no host port.
|
||||
# RabbitMQ. Topology (exchange, quorum queue, DLX/DLQ) and users come from definition files
|
||||
# imported at boot (infra/rabbitmq, secrets/rabbitmq_users.json). Lab 7: AMQPS 5671 only.
|
||||
broker:
|
||||
image: rabbitmq:4.3.7-alpine@sha256:b1f997f74103d08fc1f20a13890dc44fe6cfa51d528cf521b480ada988d3ffa5
|
||||
hostname: broker # node name rabbit@broker: stable across container re-creation
|
||||
secrets:
|
||||
- source: rabbitmq_users
|
||||
target: /etc/rabbitmq/definitions.d/users.json
|
||||
- {source: pki_broker_crt, target: broker.crt}
|
||||
- {source: pki_broker_key, target: broker.key}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
volumes:
|
||||
- ./infra/rabbitmq/rabbitmq.conf:/etc/rabbitmq/conf.d/20-lab5.conf:ro
|
||||
- ./infra/rabbitmq/rabbitmq.conf:/etc/rabbitmq/conf.d/20-lab.conf:ro
|
||||
- ./infra/rabbitmq/enabled_plugins:/etc/rabbitmq/enabled_plugins:ro
|
||||
- ./infra/rabbitmq/topology.json:/etc/rabbitmq/definitions.d/topology.json:ro
|
||||
- rabbitmqdata:/var/lib/rabbitmq
|
||||
healthcheck:
|
||||
# The node runs and the AMQP listener accepts connections.
|
||||
# The node runs and its (TLS) listener accepts connections.
|
||||
test: ["CMD-SHELL", "rabbitmq-diagnostics -q ping && rabbitmq-diagnostics -q check_port_connectivity"]
|
||||
interval: 5s
|
||||
timeout: 10s
|
||||
@@ -224,8 +262,8 @@ services:
|
||||
resources:
|
||||
limits: {cpus: "${BROKER_CPUS:-1.0}", memory: "${BROKER_MEMORY:-512m}"}
|
||||
|
||||
# One-shot schema migration: runs ONCE per `up`, before any API replica starts
|
||||
# (api depends_on service_completed_successfully). Replicas never migrate themselves.
|
||||
# One-shot schema migration as the schema OWNER messenger_migrate (not a superuser): runs ONCE
|
||||
# per `up`, before any API replica starts. Replicas never migrate themselves.
|
||||
migrate:
|
||||
build:
|
||||
context: .
|
||||
@@ -235,7 +273,9 @@ services:
|
||||
command: ["python", "-m", "messenger.migrate"]
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
secrets: [database_url]
|
||||
secrets:
|
||||
- {source: database_url_migrate, target: database_url}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
@@ -253,7 +293,7 @@ services:
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
command: ["python", "-m", "messenger.s3_bootstrap"]
|
||||
environment:
|
||||
S3_ENDPOINT: ${S3_ENDPOINT:-http://s3:8333}
|
||||
S3_ENDPOINT: ${S3_ENDPOINT:-https://s3:8333}
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_STAGING_BUCKET: ${S3_STAGING_BUCKET:-messenger-staging}
|
||||
@@ -265,6 +305,7 @@ services:
|
||||
S3_WORKER_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_worker_secret_access_key
|
||||
S3_AUDITOR_ACCESS_KEY_ID_FILE: /run/secrets/s3_auditor_access_key_id
|
||||
S3_AUDITOR_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_auditor_secret_access_key
|
||||
TLS_CA_FILE: /run/secrets/internal-ca.crt
|
||||
secrets:
|
||||
- s3_admin_access_key_id
|
||||
- s3_admin_secret_access_key
|
||||
@@ -274,6 +315,7 @@ services:
|
||||
- s3_worker_secret_access_key
|
||||
- s3_auditor_access_key_id
|
||||
- s3_auditor_secret_access_key
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
depends_on:
|
||||
s3:
|
||||
condition: service_healthy
|
||||
@@ -299,19 +341,17 @@ services:
|
||||
# Lab 7: the only network listener is mTLS on 8443 (tls.py); plaintext health on loopback.
|
||||
APP_PORT: 8443
|
||||
APP_HEALTH_PORT: 8081
|
||||
TLS_CERT_FILE: /run/secrets/api.crt
|
||||
TLS_KEY_FILE: /run/secrets/api.key
|
||||
TLS_CERT_FILE: /run/secrets/service.crt
|
||||
TLS_KEY_FILE: /run/secrets/service.key
|
||||
TLS_CLIENT_CA_FILE: /run/secrets/internal-ca.crt
|
||||
MTLS_ALLOWED_CLIENTS: ${MTLS_ALLOWED_CLIENTS:-lb}
|
||||
secrets:
|
||||
- database_url
|
||||
- {source: database_url_api, target: database_url}
|
||||
- cache_url
|
||||
- source: s3_api_access_key_id
|
||||
target: s3_access_key_id
|
||||
- source: s3_api_secret_access_key
|
||||
target: s3_secret_access_key
|
||||
- {source: pki_api_crt, target: api.crt}
|
||||
- {source: pki_api_key, target: api.key}
|
||||
- {source: s3_api_access_key_id, target: s3_access_key_id}
|
||||
- {source: s3_api_secret_access_key, target: s3_secret_access_key}
|
||||
- {source: pki_api_crt, target: service.crt}
|
||||
- {source: pki_api_key, target: service.key}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
# No `ports` and no container_name: replicas are reachable only through `lb`,
|
||||
# and `--scale api=N` / deploy.replicas works.
|
||||
@@ -340,10 +380,9 @@ services:
|
||||
replicas: ${API_REPLICAS:-2}
|
||||
resources:
|
||||
# 512m: UPLOAD_CONCURRENCY (4) x 10 MiB bodies + one djpeg (<= JPEG_MAX_MEMORY_MB) + runtime;
|
||||
# measured in lab 4 (bench/upload_memory.py). No resizing happens in the API.
|
||||
# measured in lab 4. No resizing happens in the API.
|
||||
limits: {cpus: "${API_CPUS:-1.0}", memory: "${API_MEMORY:-512m}"}
|
||||
# No swap on top of the limit (Docker's default would allow as much swap again): the RAM bound
|
||||
# of the experiments is a real bound, and running out of it is visible, not hidden in swap.
|
||||
# No swap on top of the limit: the RAM bound is a real bound.
|
||||
memswap_limit: ${API_MEMORY:-512m}
|
||||
|
||||
lb:
|
||||
@@ -378,8 +417,7 @@ services:
|
||||
resources:
|
||||
limits: {cpus: "${LB_CPUS:-1.0}", memory: 128m}
|
||||
|
||||
# Lab 5: outbox relay + lease reaper (src/messenger/relay.py). One process; a second one would
|
||||
# be safe (SKIP LOCKED) but is not needed. Database + broker only, no S3 keys.
|
||||
# Outbox relay + lease reaper (src/messenger/relay.py). Database + broker only, no S3 keys.
|
||||
relay:
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
command: ["python", "-m", "messenger.relay"]
|
||||
@@ -389,9 +427,11 @@ services:
|
||||
RELAY_POLL_SECONDS: ${RELAY_POLL_SECONDS:-0.5}
|
||||
FAULT_POINTS: ${RELAY_FAULT_POINTS:-}
|
||||
secrets:
|
||||
- database_url
|
||||
- source: broker_url_relay
|
||||
target: broker_url
|
||||
- {source: database_url_relay, target: database_url}
|
||||
- {source: broker_url_relay, target: broker_url}
|
||||
- {source: pki_relay_crt, target: service.crt}
|
||||
- {source: pki_relay_key, target: service.key}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-m", "messenger.healthcheck", "--file", "/tmp/heartbeat", "--max-age", "30"]
|
||||
interval: 5s
|
||||
@@ -412,8 +452,8 @@ services:
|
||||
resources:
|
||||
limits: {cpus: "${RELAY_CPUS:-0.5}", memory: 256m}
|
||||
|
||||
# Lab 5: image worker (src/messenger/worker.py). Scalable (`--scale worker=2`): competing
|
||||
# consumers of one queue; the database lease decides who works on a job.
|
||||
# Image worker (src/messenger/worker.py). Scalable (`--scale worker=2`): competing consumers of
|
||||
# one queue; the database lease decides who works on a job.
|
||||
worker:
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
command: ["python", "-m", "messenger.worker"]
|
||||
@@ -430,13 +470,13 @@ services:
|
||||
CLEANUP_INTERVAL_SECONDS: ${CLEANUP_INTERVAL_SECONDS:-30}
|
||||
FAULT_POINTS: ${WORKER_FAULT_POINTS:-}
|
||||
secrets:
|
||||
- database_url
|
||||
- source: broker_url_worker
|
||||
target: broker_url
|
||||
- source: s3_worker_access_key_id
|
||||
target: s3_access_key_id
|
||||
- source: s3_worker_secret_access_key
|
||||
target: s3_secret_access_key
|
||||
- {source: database_url_worker, target: database_url}
|
||||
- {source: broker_url_worker, target: broker_url}
|
||||
- {source: s3_worker_access_key_id, target: s3_access_key_id}
|
||||
- {source: s3_worker_secret_access_key, target: s3_secret_access_key}
|
||||
- {source: pki_worker_crt, target: service.crt}
|
||||
- {source: pki_worker_key, target: service.key}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-m", "messenger.healthcheck", "--file", "/tmp/heartbeat", "--max-age", "30"]
|
||||
interval: 5s
|
||||
@@ -464,7 +504,7 @@ services:
|
||||
limits: {cpus: "${WORKER_CPUS:-2.0}", memory: "${WORKER_MEMORY:-1536m}"}
|
||||
memswap_limit: ${WORKER_MEMORY:-1536m}
|
||||
|
||||
# Track 2: read-only checker of the pipeline invariants (database in read-only transactions,
|
||||
# Read-only checker of the pipeline invariants (database role messenger_auditor: SELECT only,
|
||||
# S3 auditor key: Read + List, no Write). On demand: docker compose run --rm auditor
|
||||
auditor:
|
||||
profiles: ["tools"]
|
||||
@@ -474,19 +514,19 @@ services:
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
DB_TIMEOUT_SECONDS: ${AUDIT_DB_TIMEOUT_SECONDS:-30}
|
||||
S3_ENDPOINT: ${S3_ENDPOINT:-http://s3:8333}
|
||||
S3_ENDPOINT: ${S3_ENDPOINT:-https://s3:8333}
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
S3_STAGING_BUCKET: ${S3_STAGING_BUCKET:-messenger-staging}
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
||||
S3_TIMEOUT_SECONDS: ${S3_TIMEOUT_SECONDS:-3}
|
||||
TLS_CA_FILE: /run/secrets/internal-ca.crt
|
||||
secrets:
|
||||
- database_url
|
||||
- source: s3_auditor_access_key_id
|
||||
target: s3_access_key_id
|
||||
- source: s3_auditor_secret_access_key
|
||||
target: s3_secret_access_key
|
||||
- {source: database_url_auditor, target: database_url}
|
||||
- {source: s3_auditor_access_key_id, target: s3_access_key_id}
|
||||
- {source: s3_auditor_secret_access_key, target: s3_secret_access_key}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
@@ -500,7 +540,6 @@ services:
|
||||
|
||||
# Operator CLI (replay of failed jobs, reprocess with a newer pipeline, failed registry):
|
||||
# docker compose run --rm jobctl list-failed
|
||||
# docker compose run --rm jobctl replay <attachment_id> --operator alice --reason "..."
|
||||
jobctl:
|
||||
profiles: ["tools"]
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
@@ -509,7 +548,9 @@ services:
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
secrets: [database_url]
|
||||
secrets:
|
||||
- {source: database_url_jobctl, target: database_url}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
@@ -544,17 +585,21 @@ services:
|
||||
resources:
|
||||
limits: {cpus: "0.5", memory: 128m}
|
||||
|
||||
# ------------------------------------------------------------------ lab 6: observability
|
||||
# ------------------------------------------------------------------ observability (lab 6)
|
||||
# Receives OTLP from api/relay/worker, limits memory, batches, forwards to the three stores.
|
||||
# Distroless image (no shell): its health is the `up{job="otel-collector"}` scrape of :8888.
|
||||
# Distroless image (no shell). Lab 7: receiver HTTPS + client certificate required, exporters mTLS.
|
||||
otel-collector:
|
||||
image: otel/opentelemetry-collector-contrib:0.165.0@sha256:e40d61f10c9a617cca1ffd1be4d7e2b3a4b0f0001798ff07e58cabe82e618cea
|
||||
command:
|
||||
- --config=/etc/otelcol/collector.yaml
|
||||
# traces-all (keep every span) | traces-tail (tail sampling, track 1)
|
||||
# traces-all (keep every span) | traces-tail (tail sampling, lab 6 track 1)
|
||||
- --config=/etc/otelcol/${OTEL_COLLECTOR_TRACES:-traces-all}.yaml
|
||||
environment:
|
||||
GOMEMLIMIT: 360MiB # Go heap target under the 512 MiB container limit
|
||||
secrets:
|
||||
- {source: pki_otel_collector_crt, target: otel-collector.crt}
|
||||
- {source: pki_otel_collector_key, target: otel-collector.key}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
volumes:
|
||||
- ./infra/otel:/etc/otelcol:ro
|
||||
restart: unless-stopped
|
||||
@@ -564,22 +609,29 @@ services:
|
||||
limits: {cpus: "${COLLECTOR_CPUS:-1.0}", memory: 512m}
|
||||
memswap_limit: 512m
|
||||
|
||||
# Metrics store + alert rules (OTLP receiver for the Collector's pushes; scrapes otelcol_*).
|
||||
# Metrics store + alert rules. Lab 7: HTTPS + client certificate + SAN allowlist (web-config.yml).
|
||||
prometheus:
|
||||
image: prom/prometheus:v3.16.0@sha256:e04987641b57704f408e31f6373ba4138ecf27cb4a165d24aabb6c38fddd0f06
|
||||
command:
|
||||
- --config.file=/etc/prometheus/prometheus.yml
|
||||
- --web.config.file=/etc/prometheus/web-config.yml
|
||||
- --storage.tsdb.path=/prometheus
|
||||
- --storage.tsdb.retention.time=15d
|
||||
- --storage.tsdb.retention.size=2GB
|
||||
- --web.enable-otlp-receiver
|
||||
- --web.listen-address=:9090
|
||||
secrets:
|
||||
- {source: pki_prometheus_crt, target: prometheus.crt}
|
||||
- {source: pki_prometheus_key, target: prometheus.key}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
volumes:
|
||||
- ./infra/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||
- ./infra/prometheus/web-config.yml:/etc/prometheus/web-config.yml:ro
|
||||
- ./infra/prometheus/promtool-http.yml:/etc/prometheus/promtool-http.yml:ro
|
||||
- ./infra/prometheus/rules:/etc/prometheus/rules:ro
|
||||
- promdata:/prometheus
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:9090/-/ready"]
|
||||
test: ["CMD", "promtool", "check", "ready", "--url=https://localhost:9090", "--http.config.file=/etc/prometheus/promtool-http.yml"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
@@ -592,12 +644,16 @@ services:
|
||||
limits: {cpus: "${PROMETHEUS_CPUS:-1.0}", memory: 512m}
|
||||
memswap_limit: 512m
|
||||
|
||||
# Logs store (OTLP endpoint /otlp). Distroless: health = up{job="loki"} + /ready via Grafana.
|
||||
# Logs store (OTLP endpoint /otlp). Distroless. Lab 7: HTTPS + client certificate required.
|
||||
loki:
|
||||
image: grafana/loki:3.7.10@sha256:b43c257ccfc925d4a50b8717cac61a3b51df8c48d01847936057e5c4075a24a7
|
||||
command: ["-config.file=/etc/loki/lab6.yaml"]
|
||||
command: ["-config.file=/etc/loki/lab.yaml"]
|
||||
secrets:
|
||||
- {source: pki_loki_crt, target: loki.crt}
|
||||
- {source: pki_loki_key, target: loki.key}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
volumes:
|
||||
- ./infra/loki/loki.yaml:/etc/loki/lab6.yaml:ro
|
||||
- ./infra/loki/loki.yaml:/etc/loki/lab.yaml:ro
|
||||
- lokidata:/loki
|
||||
stop_grace_period: 30s
|
||||
restart: unless-stopped
|
||||
@@ -607,12 +663,16 @@ services:
|
||||
limits: {cpus: "${LOKI_CPUS:-1.0}", memory: 512m}
|
||||
memswap_limit: 512m
|
||||
|
||||
# Traces store (OTLP/HTTP :4318, query API :3200). Distroless: health = up{job="tempo"}.
|
||||
# Traces store (OTLP/HTTPS :4318, query API :3200). Distroless. Lab 7: both listeners mTLS.
|
||||
tempo:
|
||||
image: grafana/tempo:2.10.10@sha256:12b0820f13ffa10ce956b6e9acc3b03f3cffded99109be6cc09d106fe56e5d38
|
||||
command: ["-config.file=/etc/tempo/lab6.yaml"]
|
||||
command: ["-config.file=/etc/tempo/lab.yaml"]
|
||||
secrets:
|
||||
- {source: pki_tempo_crt, target: tempo.crt}
|
||||
- {source: pki_tempo_key, target: tempo.key}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
volumes:
|
||||
- ./infra/tempo/tempo.yaml:/etc/tempo/lab6.yaml:ro
|
||||
- ./infra/tempo/tempo.yaml:/etc/tempo/lab.yaml:ro
|
||||
- tempodata:/var/tempo
|
||||
stop_grace_period: 30s
|
||||
restart: unless-stopped
|
||||
@@ -622,13 +682,20 @@ services:
|
||||
limits: {cpus: "${TEMPO_CPUS:-1.0}", memory: 512m}
|
||||
memswap_limit: 512m
|
||||
|
||||
# UI: datasources (fixed UIDs) and the dashboard are provisioned from Git; only this port and the
|
||||
# LB are published, on loopback. Admin password = secrets/grafana_admin_password (init_secrets.py).
|
||||
# UI: datasources (fixed UIDs) and the dashboard are provisioned from Git. Lab 7: HTTPS on
|
||||
# 127.0.0.1/[::1]:3000 with a public-CA certificate (SAN localhost), datasources over mTLS.
|
||||
# Admin password = secrets/grafana_admin_password (init_secrets.py).
|
||||
grafana:
|
||||
image: grafana/grafana:13.2.6@sha256:b21409d7951ddcfd63a4b49083e4ef2cc35bc1437d071813bf82bfb238b00bca
|
||||
environment:
|
||||
GF_SECURITY_ADMIN_USER: admin
|
||||
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_admin_password
|
||||
GF_SERVER_PROTOCOL: https
|
||||
GF_SERVER_CERT_FILE: /run/secrets/grafana-ui.crt
|
||||
GF_SERVER_CERT_KEY: /run/secrets/grafana-ui.key
|
||||
GF_SERVER_MIN_TLS_VERSION: TLS1.2
|
||||
GF_SERVER_DOMAIN: localhost
|
||||
GF_SECURITY_COOKIE_SECURE: "true"
|
||||
GF_USERS_ALLOW_SIGN_UP: "false"
|
||||
GF_AUTH_ANONYMOUS_ENABLED: "false"
|
||||
GF_ANALYTICS_REPORTING_ENABLED: "false"
|
||||
@@ -638,8 +705,15 @@ services:
|
||||
GF_PLUGINS_PREINSTALL_DISABLED: "true" # no plugin downloads at start: works offline
|
||||
GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH: /var/lib/grafana/dashboards/messenger.json
|
||||
GF_LOG_LEVEL: warn
|
||||
GOMEMLIMIT: 700MiB # Go heap target under the 1 GiB limit (512 MiB was not enough: GC thrashing)
|
||||
secrets: [grafana_admin_password]
|
||||
GOMEMLIMIT: 700MiB # Go heap target under the 1 GiB limit
|
||||
secrets:
|
||||
- grafana_admin_password
|
||||
- {source: pki_grafana_ui_crt, target: grafana-ui.crt}
|
||||
- {source: pki_grafana_ui_key, target: grafana-ui.key}
|
||||
- {source: pki_public_ca, target: public-ca.crt}
|
||||
- {source: pki_grafana_crt, target: grafana.crt}
|
||||
- {source: pki_grafana_key, target: grafana.key}
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
volumes:
|
||||
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
||||
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
||||
@@ -648,7 +722,7 @@ services:
|
||||
- "127.0.0.1:${GRAFANA_PORT:-3000}:3000"
|
||||
- "[::1]:${GRAFANA_PORT:-3000}:3000"
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:3000/api/health"]
|
||||
test: ["CMD", "curl", "-fsS", "-o", "/dev/null", "--cacert", "/run/secrets/public-ca.crt", "https://localhost:3000/api/health"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
@@ -689,13 +763,37 @@ volumes:
|
||||
tempodata:
|
||||
grafanadata:
|
||||
|
||||
# Every value is a file in ./secrets (scripts/init_secrets.py, git-ignored), mounted read-only
|
||||
# under /run/secrets ONLY into the services listed above.
|
||||
secrets:
|
||||
postgres_password:
|
||||
file: ./secrets/postgres_password
|
||||
valkey_password:
|
||||
file: ./secrets/valkey_password
|
||||
database_url:
|
||||
file: ./secrets/database_url
|
||||
pg_migrate_password:
|
||||
file: ./secrets/pg_migrate_password
|
||||
pg_api_password:
|
||||
file: ./secrets/pg_api_password
|
||||
pg_relay_password:
|
||||
file: ./secrets/pg_relay_password
|
||||
pg_worker_password:
|
||||
file: ./secrets/pg_worker_password
|
||||
pg_jobctl_password:
|
||||
file: ./secrets/pg_jobctl_password
|
||||
pg_auditor_password:
|
||||
file: ./secrets/pg_auditor_password
|
||||
database_url_migrate:
|
||||
file: ./secrets/database_url_migrate
|
||||
database_url_api:
|
||||
file: ./secrets/database_url_api
|
||||
database_url_relay:
|
||||
file: ./secrets/database_url_relay
|
||||
database_url_worker:
|
||||
file: ./secrets/database_url_worker
|
||||
database_url_jobctl:
|
||||
file: ./secrets/database_url_jobctl
|
||||
database_url_auditor:
|
||||
file: ./secrets/database_url_auditor
|
||||
valkey_api_password:
|
||||
file: ./secrets/valkey_api_password
|
||||
cache_url:
|
||||
file: ./secrets/cache_url
|
||||
s3_admin_access_key_id:
|
||||
@@ -724,24 +822,70 @@ secrets:
|
||||
file: ./secrets/grafana_admin_password
|
||||
# Lab 7 PKI (scripts/init_pki.py). Each service mounts only its own certificate/key and the CA it
|
||||
# verifies peers with; the CA private keys are mounted nowhere.
|
||||
pki_public_ca:
|
||||
file: ./secrets/pki/public-ca.crt
|
||||
pki_internal_ca:
|
||||
file: ./secrets/pki/internal-ca.crt
|
||||
pki_ingress_pem:
|
||||
file: ./secrets/pki/ingress.pem
|
||||
pki_lb_pem:
|
||||
file: ./secrets/pki/lb.pem
|
||||
pki_internal_ca:
|
||||
file: ./secrets/pki/internal-ca.crt
|
||||
pki_api_crt:
|
||||
file: ./secrets/pki/api.crt
|
||||
pki_api_key:
|
||||
file: ./secrets/pki/api.key
|
||||
pki_lb_crt:
|
||||
file: ./secrets/pki/lb.crt
|
||||
pki_lb_key:
|
||||
file: ./secrets/pki/lb.key
|
||||
pki_api_crt:
|
||||
file: ./secrets/pki/api.crt
|
||||
pki_api_key:
|
||||
file: ./secrets/pki/api.key
|
||||
pki_relay_crt:
|
||||
file: ./secrets/pki/relay.crt
|
||||
pki_relay_key:
|
||||
file: ./secrets/pki/relay.key
|
||||
pki_worker_crt:
|
||||
file: ./secrets/pki/worker.crt
|
||||
pki_worker_key:
|
||||
file: ./secrets/pki/worker.key
|
||||
pki_postgres_crt:
|
||||
file: ./secrets/pki/postgres.crt
|
||||
pki_postgres_key:
|
||||
file: ./secrets/pki/postgres.key
|
||||
pki_valkey_crt:
|
||||
file: ./secrets/pki/valkey.crt
|
||||
pki_valkey_key:
|
||||
file: ./secrets/pki/valkey.key
|
||||
pki_s3_crt:
|
||||
file: ./secrets/pki/s3.crt
|
||||
pki_s3_key:
|
||||
file: ./secrets/pki/s3.key
|
||||
pki_broker_crt:
|
||||
file: ./secrets/pki/broker.crt
|
||||
pki_broker_key:
|
||||
file: ./secrets/pki/broker.key
|
||||
pki_otel_collector_crt:
|
||||
file: ./secrets/pki/otel-collector.crt
|
||||
pki_otel_collector_key:
|
||||
file: ./secrets/pki/otel-collector.key
|
||||
pki_prometheus_crt:
|
||||
file: ./secrets/pki/prometheus.crt
|
||||
pki_prometheus_key:
|
||||
file: ./secrets/pki/prometheus.key
|
||||
pki_loki_crt:
|
||||
file: ./secrets/pki/loki.crt
|
||||
pki_loki_key:
|
||||
file: ./secrets/pki/loki.key
|
||||
pki_tempo_crt:
|
||||
file: ./secrets/pki/tempo.crt
|
||||
pki_tempo_key:
|
||||
file: ./secrets/pki/tempo.key
|
||||
pki_grafana_crt:
|
||||
file: ./secrets/pki/grafana.crt
|
||||
pki_grafana_key:
|
||||
file: ./secrets/pki/grafana.key
|
||||
pki_grafana_ui_crt:
|
||||
file: ./secrets/pki/grafana-ui.crt
|
||||
pki_grafana_ui_key:
|
||||
file: ./secrets/pki/grafana-ui.key
|
||||
pki_foreign_lb_crt: # test only: foreign CA, SAN lb
|
||||
file: ./secrets/pki/foreign-lb.crt
|
||||
pki_foreign_lb_key:
|
||||
|
||||
Reference in New Issue
Block a user