Files
dizi a8edaf058d
CI / verify (pull_request) Successful in 14m53s
chore: finalize lab7 security verification
2026-11-06 22:00:42 +03:00

1119 lines
36 KiB
YAML

x-messenger-config-volume: &messenger-config-volume
type: bind
source: ./config/messenger.yaml
target: /etc/messenger/messenger.yaml
read_only: true
x-telemetry-environment: &telemetry-environment
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT}
OTEL_EXPORTER_OTLP_PROTOCOL: ${OTEL_EXPORTER_OTLP_PROTOCOL}
OTEL_EXPORTER_OTLP_INSECURE: "false"
OTEL_EXPORTER_OTLP_CERTIFICATE: /run/security/internal-ca/ca.crt
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: /run/security/client/tls.crt
OTEL_EXPORTER_OTLP_CLIENT_KEY: /run/security/client/tls.key
OTEL_EXPORTER_OTLP_SERVER_NAME: otel-gateway
OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=${DEPLOYMENT_ENVIRONMENT},service.version=${SERVICE_VERSION}
x-app-hardening: &app-hardening
read_only: true
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp:rw,noexec,nosuid,size=64m
services:
security-bootstrap:
image: alpine:3.24.2
entrypoint: ["/bin/sh", "/install.sh"]
volumes:
- ./.runtime/security:/source:ro
- ./infra/pki/install.sh:/install.sh:ro
- api_security:/target/api
- nginx_security:/target/nginx
- prometheus_security:/target/prometheus
- client_security:/target/client
- postgres_security:/target/postgres
- valkey_security:/target/valkey
- redis_broker_security:/target/redis-broker
- redis_gateway_security:/target/redis-gateway
- minio_security:/target/minio
- otel_gateway_security:/target/otel-gateway
- dispatcher_security:/target/dispatcher
- worker_security:/target/worker
- migrate_security:/target/migrate
- reconciler_security:/target/reconciler
- postgres_bootstrap_security:/target/postgres-bootstrap
- postgres_exporter_security:/target/postgres-exporter
- valkey_exporter_security:/target/valkey-exporter
- redis_exporter_security:/target/redis-exporter
- s3_bootstrap_security:/target/s3-bootstrap
- openbao_security:/target/openbao
- openbao_agent_security:/target/openbao-agent
- telemetry_gateway_security:/target/telemetry-gateway
- collector_security:/target/collector
- grafana_security:/target/grafana
healthcheck:
disable: true
restart: "no"
network_mode: none
acl-bootstrap:
image: alpine:3.24.2
entrypoint: ["/bin/sh", "-c"]
command:
- |
/bootstrap-acl.sh valkey /target/valkey/valkey/users.acl
/bootstrap-acl.sh broker /target/redis/redis-broker/users.acl
chown 999:999 /target/valkey/valkey/users.acl /target/redis/redis-broker/users.acl
environment:
VALKEY_API_PASSWORD: ${VALKEY_API_PASSWORD}
VALKEY_EXPORTER_PASSWORD: ${VALKEY_EXPORTER_PASSWORD}
VALKEY_HEALTH_PASSWORD: ${VALKEY_HEALTH_PASSWORD}
REDIS_DISPATCHER_PASSWORD: ${REDIS_DISPATCHER_PASSWORD}
REDIS_WORKER_PASSWORD: ${REDIS_WORKER_PASSWORD}
REDIS_EXPORTER_PASSWORD: ${REDIS_EXPORTER_PASSWORD}
REDIS_HEALTH_PASSWORD: ${REDIS_HEALTH_PASSWORD}
volumes:
- ./infra/redis/bootstrap-acl.sh:/bootstrap-acl.sh:ro
- valkey_security:/target/valkey
- redis_broker_security:/target/redis
depends_on:
security-bootstrap:
condition: service_completed_successfully
healthcheck:
disable: true
restart: "no"
network_mode: none
postgres:
image: postgres:17.6-alpine3.22
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
command: ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"]
volumes:
- postgres_data:/var/lib/postgresql/data
- postgres_security:/run/security:ro
- ./infra/postgres/postgresql.conf:/etc/postgresql/postgresql.conf:ro
- ./infra/postgres/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 5s
timeout: 3s
retries: 20
cpus: ${POSTGRES_CPUS}
mem_limit: ${POSTGRES_MEMORY}
restart: unless-stopped
depends_on:
security-bootstrap:
condition: service_completed_successfully
networks: [data]
valkey:
image: valkey/valkey:8.1.4-alpine
command: ["valkey-server", "/etc/valkey/valkey.conf"]
environment:
VALKEY_HEALTH_PASSWORD: ${VALKEY_HEALTH_PASSWORD}
volumes:
- valkey_data:/data
- valkey_security:/run/security:ro
- ./infra/redis/valkey.conf:/etc/valkey/valkey.conf:ro
healthcheck:
test: ["CMD-SHELL", "valkey-cli --no-auth-warning -s /tmp/valkey.sock --user valkey_health -a \"$$VALKEY_HEALTH_PASSWORD\" ping | grep -q PONG"]
interval: 5s
timeout: 3s
retries: 20
cpus: ${VALKEY_CPUS}
mem_limit: ${VALKEY_MEMORY}
restart: unless-stopped
depends_on:
acl-bootstrap:
condition: service_completed_successfully
networks: [data_backend]
redis-broker:
image: redis:8.2.2-alpine
command: ["redis-server", "/etc/redis/redis.conf"]
environment:
REDIS_HEALTH_PASSWORD: ${REDIS_HEALTH_PASSWORD}
volumes:
- redis_broker_data:/data
- redis_broker_security:/run/security:ro
- ./infra/redis/redis-broker.conf:/etc/redis/redis.conf:ro
healthcheck:
test: ["CMD-SHELL", "redis-cli --no-auth-warning -s /tmp/redis.sock --user redis_health -a \"$$REDIS_HEALTH_PASSWORD\" ping | grep -q PONG"]
interval: 5s
timeout: 3s
retries: 20
cpus: ${REDIS_BROKER_CPUS}
mem_limit: ${REDIS_BROKER_MEMORY}
restart: unless-stopped
depends_on:
acl-bootstrap:
condition: service_completed_successfully
networks: [data_backend]
redis-gateway:
image: envoyproxy/envoy:v1.35.2
command: ["-c", "/etc/envoy/gateway.yaml", "--log-level", "warning"]
volumes:
- ./infra/redis/gateway.yaml:/etc/envoy/gateway.yaml:ro
- redis_gateway_security:/run/security:ro
expose: ["16379", "26379", "36379"]
depends_on:
valkey:
condition: service_healthy
redis-broker:
condition: service_healthy
healthcheck:
disable: true
cpus: ${REDIS_GATEWAY_CPUS}
mem_limit: ${REDIS_GATEWAY_MEMORY}
restart: unless-stopped
networks: [data, data_backend, secure_clients]
s3:
build:
context: .
dockerfile: infra/minio/server.Dockerfile
args:
MINIO_VERSION: RELEASE.2025-10-15T17-29-55Z
image: mtusi-minio:RELEASE.2025-10-15T17-29-55Z
command: ["server", "/data", "--address", ":9000", "--certs-dir", "/run/security/minio"]
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
MINIO_BROWSER: "off"
MINIO_PROMETHEUS_AUTH_TYPE: public
SSL_CERT_FILE: /run/security/internal-ca/ca.crt
volumes:
- s3_data:/data
- minio_security:/run/security:ro
expose:
- "9000"
healthcheck:
test: ["CMD", "wget", "-q", "-O", "/dev/null", "https://s3:9000/minio/health/ready"]
interval: 5s
timeout: 3s
retries: 20
cpus: ${S3_CPUS}
mem_limit: ${S3_MEMORY}
restart: unless-stopped
depends_on:
security-bootstrap:
condition: service_completed_successfully
networks: [data]
s3-bootstrap:
build:
context: .
dockerfile: infra/minio/client.Dockerfile
args:
MC_VERSION: RELEASE.2025-08-13T08-35-41Z
image: mtusi-mc:RELEASE.2025-08-13T08-35-41Z
entrypoint: ["/bin/sh", "/usr/local/bin/bootstrap.sh"]
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
S3_BUCKET: ${S3_BUCKET}
S3_API_ACCESS_KEY: ${S3_API_ACCESS_KEY}
S3_API_SECRET_KEY: ${S3_API_SECRET_KEY}
S3_WORKER_ACCESS_KEY: ${S3_WORKER_ACCESS_KEY}
S3_WORKER_SECRET_KEY: ${S3_WORKER_SECRET_KEY}
S3_RECONCILER_ACCESS_KEY: ${S3_RECONCILER_ACCESS_KEY}
S3_RECONCILER_SECRET_KEY: ${S3_RECONCILER_SECRET_KEY}
SSL_CERT_FILE: /run/security/internal-ca/ca.crt
MC_CONFIG_DIR: /tmp/mc-bootstrap
volumes:
- s3_bootstrap_security:/run/security:ro
- ./infra/minio/bootstrap.sh:/usr/local/bin/bootstrap.sh:ro
depends_on:
s3:
condition: service_healthy
healthcheck:
disable: true
cpus: ${S3_BOOTSTRAP_CPUS}
mem_limit: ${S3_BOOTSTRAP_MEMORY}
restart: "no"
networks: [data]
postgres-roles:
image: postgres:17.6-alpine3.22
command: ["/bootstrap/bootstrap-roles.sh", "create"]
environment: &postgres-role-environment
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_API_PASSWORD: ${POSTGRES_API_PASSWORD}
POSTGRES_DISPATCHER_PASSWORD: ${POSTGRES_DISPATCHER_PASSWORD}
POSTGRES_WORKER_PASSWORD: ${POSTGRES_WORKER_PASSWORD}
POSTGRES_RECONCILER_PASSWORD: ${POSTGRES_RECONCILER_PASSWORD}
POSTGRES_EXPORTER_PASSWORD: ${POSTGRES_EXPORTER_PASSWORD}
POSTGRES_MIGRATE_PASSWORD: ${POSTGRES_MIGRATE_PASSWORD}
volumes:
- ./infra/postgres:/bootstrap:ro
- postgres_bootstrap_security:/run/security:ro
depends_on:
postgres:
condition: service_healthy
healthcheck:
disable: true
restart: "no"
networks: [data]
migrate:
image: ${API_IMAGE:-mtusi-messenger:lab7}
command: ["/app/messenger", "migrate"]
environment:
MESSENGER_CONFIG_PATH: /etc/messenger/messenger.yaml
DATABASE_URL: ${DATABASE_MIGRATE_URL}
volumes:
- *messenger-config-volume
- migrate_security:/run/security:ro
depends_on:
postgres-roles:
condition: service_completed_successfully
healthcheck:
disable: true
cpus: ${MIGRATE_CPUS}
mem_limit: ${MIGRATE_MEMORY}
restart: "no"
networks: [data]
postgres-grants:
image: postgres:17.6-alpine3.22
command: ["/bootstrap/bootstrap-roles.sh", "grant"]
environment: *postgres-role-environment
volumes:
- ./infra/postgres:/bootstrap:ro
- postgres_bootstrap_security:/run/security:ro
depends_on:
migrate:
condition: service_completed_successfully
healthcheck:
disable: true
restart: "no"
networks: [data]
openbao-permissions:
image: alpine:3.24.2
command: ["/bin/sh", "-c", "chown -R 100:100 /openbao/data && chown -R 10001:10001 /secrets/api /secrets/worker"]
volumes:
- openbao_data:/openbao/data
- openbao_api_secrets:/secrets/api
- openbao_worker_secrets:/secrets/worker
depends_on:
security-bootstrap:
condition: service_completed_successfully
healthcheck:
disable: true
restart: "no"
network_mode: none
openbao:
image: openbao/openbao:2.7.1
command: ["server", "-config=/etc/openbao/config.hcl"]
environment:
BAO_ENABLE_FILE_PERMISSIONS_CHECK: "false"
volumes:
- ./infra/openbao/config.hcl:/etc/openbao/config.hcl:ro
- openbao_data:/openbao/data
- openbao_security:/run/security:ro
ports:
- "${OPENBAO_BIND_ADDRESS}:8200"
depends_on:
openbao-permissions:
condition: service_completed_successfully
read_only: true
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp:rw,noexec,nosuid,size=16m
- /run/openbao:rw,noexec,nosuid,size=8m
cpus: ${OPENBAO_CPUS}
mem_limit: ${OPENBAO_MEMORY}
restart: unless-stopped
networks: [secrets, edge]
openbao-cli:
profiles: ["tools"]
image: openbao/openbao:2.7.1
user: "0:0"
entrypoint: ["bao"]
environment:
BAO_ADDR: https://openbao:8200
BAO_CACERT: /run/security/openbao/ca.crt
BAO_TOKEN: ${BAO_TOKEN:-}
volumes:
- openbao_agent_security:/run/security:ro
depends_on:
- openbao
networks: [secrets]
openbao-identity-install:
profiles: ["tools"]
image: alpine:3.24.2
entrypoint: ["/bin/sh", "/install-identity.sh"]
volumes:
- ./infra/openbao/install-identity.sh:/install-identity.sh:ro
- ./.runtime/openbao/approle:/source:ro
- openbao_api_identity:/identities/api
- openbao_worker_identity:/identities/worker
network_mode: none
restart: "no"
openbao-agent-api:
image: openbao/openbao:2.7.1
user: "10001:10001"
command: ["agent", "-config=/etc/openbao-agent/agent.hcl"]
volumes:
- ./infra/openbao/agent/api.hcl:/etc/openbao-agent/agent.hcl:ro
- ./infra/openbao/agent/api-secrets.ctmpl:/etc/openbao-agent/api-secrets.ctmpl:ro
- openbao_api_identity:/run/openbao-identity:ro
- openbao_api_secrets:/run/openbao-secrets
- openbao_agent_security:/run/security:ro
depends_on:
openbao-permissions:
condition: service_completed_successfully
openbao:
condition: service_started
healthcheck:
test: ["CMD-SHELL", "test -s /run/openbao-secrets/secrets.json && BAO_ADDR=https://openbao:8200 BAO_CACERT=/run/security/openbao/ca.crt BAO_TOKEN=$$(cat /run/openbao-agent/token) bao token lookup >/dev/null 2>&1"]
interval: 2s
timeout: 1s
retries: 60
read_only: true
security_opt:
- no-new-privileges:true
cap_drop: ["ALL"]
tmpfs:
- /tmp:rw,noexec,nosuid,size=8m
- /run/openbao-agent:rw,noexec,nosuid,size=8m,uid=10001,gid=10001,mode=0700
restart: unless-stopped
networks: [secrets]
openbao-agent-worker:
image: openbao/openbao:2.7.1
user: "10001:10001"
command: ["agent", "-config=/etc/openbao-agent/agent.hcl"]
volumes:
- ./infra/openbao/agent/worker.hcl:/etc/openbao-agent/agent.hcl:ro
- ./infra/openbao/agent/worker-secrets.ctmpl:/etc/openbao-agent/worker-secrets.ctmpl:ro
- openbao_worker_identity:/run/openbao-identity:ro
- openbao_worker_secrets:/run/openbao-secrets
- openbao_agent_security:/run/security:ro
depends_on:
openbao-permissions:
condition: service_completed_successfully
openbao:
condition: service_started
healthcheck:
test: ["CMD-SHELL", "test -s /run/openbao-secrets/secrets.json && BAO_ADDR=https://openbao:8200 BAO_CACERT=/run/security/openbao/ca.crt BAO_TOKEN=$$(cat /run/openbao-agent/token) bao token lookup >/dev/null 2>&1"]
interval: 2s
timeout: 1s
retries: 60
read_only: true
security_opt:
- no-new-privileges:true
cap_drop: ["ALL"]
tmpfs:
- /tmp:rw,noexec,nosuid,size=8m
- /run/openbao-agent:rw,noexec,nosuid,size=8m,uid=10001,gid=10001,mode=0700
restart: unless-stopped
networks: [secrets]
api:
<<: *app-hardening
build: .
image: ${API_IMAGE:-mtusi-messenger:lab7}
environment:
<<: *telemetry-environment
OTEL_SERVICE_NAME: messenger-api
MESSENGER_CONFIG_PATH: /etc/messenger/messenger.yaml
APP_HOST: ${APP_HOST}
APP_PORT: ${APP_PORT}
APP_HEALTH_ADDRESS: ${APP_HEALTH_ADDRESS}
MESSENGER_SECRETS_FILE: /run/openbao-secrets/secrets.json
SWAGGER_PORT: ${SWAGGER_PORT}
S3_ENDPOINT: https://${S3_ENDPOINT}
S3_REGION: ${S3_REGION}
S3_BUCKET: ${S3_BUCKET}
volumes:
- *messenger-config-volume
- api_security:/run/security:ro
- openbao_api_secrets:/run/openbao-secrets:ro
expose:
- "8443"
- "9091"
depends_on:
security-bootstrap:
condition: service_completed_successfully
migrate:
condition: service_completed_successfully
postgres-grants:
condition: service_completed_successfully
redis-gateway:
condition: service_started
s3-bootstrap:
condition: service_completed_successfully
openbao-agent-api:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8082/health/ready || exit 1"]
interval: 2s
timeout: 1s
start_period: 5s
retries: 2
deploy:
replicas: ${API_REPLICAS:-2}
cpus: ${API_CPUS}
mem_limit: ${API_MEMORY}
stop_grace_period: 8s
restart: unless-stopped
networks: [application, data, monitoring]
dispatcher:
<<: *app-hardening
image: ${API_IMAGE:-mtusi-messenger:lab7}
command: ["/app/messenger", "dispatch"]
environment:
<<: *telemetry-environment
OTEL_SERVICE_NAME: messenger-dispatcher
MESSENGER_CONFIG_PATH: /etc/messenger/messenger.yaml
DATABASE_URL: ${DATABASE_DISPATCHER_URL}
BROKER_URL: ${BROKER_DISPATCHER_URL}
volumes:
- *messenger-config-volume
- dispatcher_security:/run/security:ro
expose:
- "9091"
depends_on:
migrate:
condition: service_completed_successfully
postgres-grants:
condition: service_completed_successfully
redis-gateway:
condition: service_started
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:9092/health/live || exit 1"]
interval: 5s
timeout: 2s
retries: 20
cpus: ${DISPATCHER_CPUS}
mem_limit: ${DISPATCHER_MEMORY}
restart: unless-stopped
networks: [data, monitoring]
worker:
<<: *app-hardening
image: ${API_IMAGE:-mtusi-messenger:lab7}
command: ["/app/messenger", "worker"]
environment:
<<: *telemetry-environment
OTEL_SERVICE_NAME: messenger-worker
MESSENGER_CONFIG_PATH: /etc/messenger/messenger.yaml
MESSENGER_SECRETS_FILE: /run/openbao-secrets/secrets.json
S3_ENDPOINT: https://${S3_ENDPOINT}
S3_REGION: ${S3_REGION}
S3_BUCKET: ${S3_BUCKET}
volumes:
- *messenger-config-volume
- worker_security:/run/security:ro
- openbao_worker_secrets:/run/openbao-secrets:ro
expose:
- "9091"
depends_on:
migrate:
condition: service_completed_successfully
postgres-grants:
condition: service_completed_successfully
redis-gateway:
condition: service_started
s3-bootstrap:
condition: service_completed_successfully
openbao-agent-worker:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:9092/health/live || exit 1"]
interval: 5s
timeout: 2s
retries: 20
cpus: ${WORKER_CPUS}
mem_limit: ${WORKER_MEMORY}
stop_grace_period: 8s
restart: unless-stopped
networks: [data, monitoring]
reconciler:
profiles: ["maintenance"]
<<: *app-hardening
image: ${API_IMAGE:-mtusi-messenger:lab7}
command: ["/app/messenger", "reconcile-attachments", "--grace-period=1h", "--page-size=100"]
environment:
MESSENGER_CONFIG_PATH: /etc/messenger/messenger.yaml
DATABASE_URL: ${DATABASE_RECONCILER_URL}
S3_ENDPOINT: https://${S3_ENDPOINT}
S3_REGION: ${S3_REGION}
S3_BUCKET: ${S3_BUCKET}
S3_ACCESS_KEY: ${S3_RECONCILER_ACCESS_KEY}
S3_SECRET_KEY: ${S3_RECONCILER_SECRET_KEY}
volumes:
- *messenger-config-volume
- reconciler_security:/run/security:ro
depends_on:
postgres-grants:
condition: service_completed_successfully
s3-bootstrap:
condition: service_completed_successfully
healthcheck:
disable: true
networks: [data]
nginx:
build:
context: .
target: loadbalancer
image: ${NGINX_IMAGE:-mtusi-nginx:lab7}
ports:
- "${API_BIND_ADDRESS}:8443"
volumes:
- nginx_security:/run/security:ro
depends_on:
security-bootstrap:
condition: service_completed_successfully
api:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8081/stub_status || exit 1"]
interval: 2s
timeout: 1s
retries: 10
cpus: ${NGINX_CPUS}
mem_limit: ${NGINX_MEMORY}
restart: unless-stopped
networks: [edge, application, monitoring]
security-tests:
profiles: ["security"]
build:
context: .
target: security-test
environment:
PUBLIC_TLS_HOST: nginx
PUBLIC_TLS_PORT: "8443"
API_TLS_ADDRESS: api:8443
METRICS_TLS_ADDRESS: api:9091
SECURITY_DIR: /src/.runtime/security
volumes:
- ./.runtime/security:/src/.runtime/security:ro
depends_on:
nginx:
condition: service_healthy
networks: [edge, application]
dependency-tests:
profiles: ["security"]
image: mtusi-mc:RELEASE.2025-08-13T08-35-41Z
user: "0:0"
entrypoint: ["/bin/sh", "/test-dependency-matrix.sh"]
environment:
SECURITY_DIR: /run/security-source
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_API_PASSWORD: ${POSTGRES_API_PASSWORD}
POSTGRES_WORKER_PASSWORD: ${POSTGRES_WORKER_PASSWORD}
POSTGRES_DISPATCHER_PASSWORD: ${POSTGRES_DISPATCHER_PASSWORD}
VALKEY_API_PASSWORD: ${VALKEY_API_PASSWORD}
REDIS_DISPATCHER_PASSWORD: ${REDIS_DISPATCHER_PASSWORD}
REDIS_WORKER_PASSWORD: ${REDIS_WORKER_PASSWORD}
S3_BUCKET: ${S3_BUCKET}
S3_API_ACCESS_KEY: ${S3_API_ACCESS_KEY}
S3_API_SECRET_KEY: ${S3_API_SECRET_KEY}
S3_WORKER_ACCESS_KEY: ${S3_WORKER_ACCESS_KEY}
S3_WORKER_SECRET_KEY: ${S3_WORKER_SECRET_KEY}
volumes:
- ./infra/security/test-dependency-matrix.sh:/test-dependency-matrix.sh:ro
- ./.runtime/security:/run/security-source:ro
depends_on:
api:
condition: service_healthy
dispatcher:
condition: service_healthy
worker:
condition: service_healthy
otel-gateway:
condition: service_started
networks: [data, data_backend, secure_clients]
swagger:
build:
context: .
target: swagger
image: ${SWAGGER_IMAGE:-mtusi-swagger:lab7}
ports:
- "${SWAGGER_BIND_ADDRESS}:8080"
depends_on:
nginx:
condition: service_healthy
cpus: ${SWAGGER_CPUS}
mem_limit: ${SWAGGER_MEMORY}
restart: unless-stopped
networks: [edge]
tests:
profiles: ["tests"]
build:
context: .
target: test
environment:
TEST_DATABASE_URL: postgres://messenger_migrate:${POSTGRES_MIGRATE_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=verify-full&sslrootcert=/run/database-security/internal-ca/ca.crt&sslcert=/run/database-security/client/tls.crt&sslkey=/run/database-security/client/tls.key
TEST_CACHE_URL: ${CACHE_URL}
TEST_CACHE_TLS_CA_PATH: /run/cache-security/internal-ca/ca.crt
TEST_CACHE_TLS_CERTIFICATE_PATH: /run/cache-security/client/tls.crt
TEST_CACHE_TLS_PRIVATE_KEY_PATH: /run/cache-security/client/tls.key
TEST_CACHE_TLS_SERVER_NAME: redis-gateway
volumes:
- migrate_security:/run/database-security:ro
- api_security:/run/cache-security:ro
depends_on:
postgres-grants:
condition: service_completed_successfully
redis-gateway:
condition: service_started
cpus: ${TEST_CPUS}
mem_limit: ${TEST_MEMORY}
networks: [data]
lab5-experiment:
profiles: ["experiments"]
image: ${API_IMAGE:-mtusi-messenger:lab7}
command: ["/app/lab5experiment"]
environment:
MESSENGER_CONFIG_PATH: /etc/messenger/messenger.yaml
DATABASE_URL: ${DATABASE_WORKER_URL}
S3_ENDPOINT: https://${S3_ENDPOINT}
S3_REGION: ${S3_REGION}
S3_BUCKET: ${S3_BUCKET}
S3_ACCESS_KEY: ${S3_WORKER_ACCESS_KEY}
S3_SECRET_KEY: ${S3_WORKER_SECRET_KEY}
BROKER_URL: ${BROKER_WORKER_URL}
volumes:
- *messenger-config-volume
- worker_security:/run/security:ro
depends_on:
migrate:
condition: service_completed_successfully
redis-broker:
condition: service_healthy
s3-bootstrap:
condition: service_completed_successfully
cpus: ${TEST_CPUS}
mem_limit: ${TEST_MEMORY}
networks: [application, data]
postgres-exporter:
image: quay.io/prometheuscommunity/postgres-exporter:v0.20.1
environment:
DATA_SOURCE_NAME: postgres://messenger_exporter:${POSTGRES_EXPORTER_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=verify-full&sslrootcert=/run/security/internal-ca/ca.crt&sslcert=/run/security/client/tls.crt&sslkey=/run/security/client/tls.key
PG_EXPORTER_COLLECTION_TIMEOUT: 5s
PG_EXPORTER_EXTEND_QUERY_PATH: /etc/postgres_exporter/queries.yml
volumes:
- ./monitoring/postgres-queries.yml:/etc/postgres_exporter/queries.yml:ro
- postgres_exporter_security:/run/security:ro
depends_on:
postgres-grants:
condition: service_completed_successfully
cpus: ${EXPORTER_CPUS}
mem_limit: ${EXPORTER_MEMORY}
restart: unless-stopped
networks: [data, monitoring]
valkey-exporter:
image: oliver006/redis_exporter:v1.89.0-alpine
environment:
REDIS_ADDR: rediss://valkey:6379
REDIS_USER: valkey_exporter
REDIS_PASSWORD: ${VALKEY_EXPORTER_PASSWORD}
REDIS_EXPORTER_TLS_CLIENT_KEY_FILE: /run/security/client/tls.key
REDIS_EXPORTER_TLS_CLIENT_CERT_FILE: /run/security/client/tls.crt
REDIS_EXPORTER_TLS_CA_CERT_FILE: /run/security/internal-ca/ca.crt
REDIS_EXPORTER_TLS_SERVER_NAME: valkey
volumes:
- valkey_exporter_security:/run/security:ro
depends_on:
valkey:
condition: service_healthy
cpus: ${EXPORTER_CPUS}
mem_limit: ${EXPORTER_MEMORY}
restart: unless-stopped
networks: [data_backend, monitoring]
redis-broker-exporter:
image: oliver006/redis_exporter:v1.89.0-alpine
environment:
REDIS_ADDR: rediss://redis-broker:6379
REDIS_USER: redis_exporter
REDIS_PASSWORD: ${REDIS_EXPORTER_PASSWORD}
REDIS_EXPORTER_TLS_CLIENT_KEY_FILE: /run/security/client/tls.key
REDIS_EXPORTER_TLS_CLIENT_CERT_FILE: /run/security/client/tls.crt
REDIS_EXPORTER_TLS_CA_CERT_FILE: /run/security/internal-ca/ca.crt
REDIS_EXPORTER_TLS_SERVER_NAME: redis-broker
REDIS_EXPORTER_CHECK_SINGLE_STREAMS: attachment-jobs,attachment-jobs-failed
volumes:
- redis_exporter_security:/run/security:ro
depends_on:
redis-broker:
condition: service_healthy
cpus: ${EXPORTER_CPUS}
mem_limit: ${EXPORTER_MEMORY}
restart: unless-stopped
networks: [data_backend, monitoring]
nginx-exporter:
image: nginx/nginx-prometheus-exporter:1.5.1
command: ["--nginx.scrape-uri=http://nginx:8081/stub_status"]
depends_on:
nginx:
condition: service_healthy
cpus: ${EXPORTER_CPUS}
mem_limit: ${EXPORTER_MEMORY}
restart: unless-stopped
networks: [monitoring]
prometheus:
build:
context: .
target: prometheus
image: ${PROMETHEUS_IMAGE:-mtusi-prometheus:lab7}
command:
- --config.file=/etc/prometheus/prometheus.yml
- --storage.tsdb.path=/prometheus
- --storage.tsdb.retention.time=7d
- --web.enable-remote-write-receiver
volumes:
- prometheus_data:/prometheus
- prometheus_security:/run/security:ro
ports:
- "${PROMETHEUS_BIND_ADDRESS}:9090"
healthcheck:
test: ["CMD", "promtool", "query", "instant", "http://127.0.0.1:9090", "up"]
interval: 5s
timeout: 3s
retries: 20
depends_on:
security-bootstrap:
condition: service_completed_successfully
api:
condition: service_healthy
nginx-exporter:
condition: service_started
postgres-exporter:
condition: service_started
valkey-exporter:
condition: service_started
redis-broker-exporter:
condition: service_started
dispatcher:
condition: service_healthy
worker:
condition: service_healthy
s3:
condition: service_healthy
otel-collector:
condition: service_healthy
loki:
condition: service_healthy
tempo:
condition: service_healthy
cpus: ${PROMETHEUS_CPUS}
mem_limit: ${PROMETHEUS_MEMORY}
restart: unless-stopped
networks: [application, data, monitoring, telemetry_storage]
grafana:
build:
context: .
target: grafana
image: ${GRAFANA_IMAGE:-mtusi-grafana:lab7}
environment:
GF_SECURITY_ADMIN_USER: admin
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD}
GF_USERS_ALLOW_SIGN_UP: "false"
GF_EXPLORE_ENABLED: "true"
GF_SERVER_PROTOCOL: https
GF_SERVER_CERT_FILE: /run/security/grafana-server.crt
GF_SERVER_CERT_KEY: /run/security/grafana-server.key
GF_SERVER_DOMAIN: localhost
SSL_CERT_FILE: /run/security/internal-ca/ca.crt
volumes:
- grafana_data:/var/lib/grafana
- grafana_security:/run/security:ro
ports:
- "${GRAFANA_BIND_ADDRESS}:3000"
depends_on:
prometheus-grafana-gateway:
condition: service_started
loki-grafana-gateway:
condition: service_started
tempo-grafana-gateway:
condition: service_started
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null https://localhost:3000/api/health || exit 1"]
interval: 5s
timeout: 3s
retries: 20
cpus: ${GRAFANA_CPUS}
mem_limit: ${GRAFANA_MEMORY}
restart: unless-stopped
networks: [edge, secure_clients]
loki:
image: grafana/loki:3.7.9
command: ["-config.file=/etc/loki/loki.yaml"]
volumes:
- ./infra/loki/loki.yaml:/etc/loki/loki.yaml:ro
- loki_data:/loki
healthcheck:
test: ["CMD", "/usr/bin/loki", "-version"]
interval: 10s
timeout: 3s
retries: 10
cpus: ${LOKI_CPUS}
mem_limit: ${LOKI_MEMORY}
restart: unless-stopped
networks: [telemetry_storage]
tempo:
image: grafana/tempo:2.10.10
command: ["-config.file=/etc/tempo/tempo.yaml"]
volumes:
- ./infra/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro
- tempo_data:/var/tempo
healthcheck:
test: ["CMD", "/tempo", "-version"]
interval: 10s
timeout: 3s
retries: 10
cpus: ${TEMPO_CPUS}
mem_limit: ${TEMPO_MEMORY}
restart: unless-stopped
networks: [telemetry_storage]
otel-gateway:
image: envoyproxy/envoy:v1.35.2
command: ["-c", "/etc/envoy/gateway.yaml", "--log-level", "warning"]
volumes:
- ./infra/otel/gateway.yaml:/etc/envoy/gateway.yaml:ro
- otel_gateway_security:/run/security:ro
expose: ["4317", "4318"]
depends_on:
security-bootstrap:
condition: service_completed_successfully
otel-collector:
condition: service_healthy
cpus: ${OTEL_GATEWAY_CPUS}
mem_limit: ${OTEL_GATEWAY_MEMORY}
restart: unless-stopped
networks: [data, telemetry_backend]
tempo-collector-gateway:
<<: *app-hardening
image: ${API_IMAGE:-mtusi-messenger:lab7}
command: ["/app/mtlsproxy"]
environment:
PROXY_LISTEN_ADDRESS: 0.0.0.0:8443
PROXY_TARGET_ADDRESS: tempo:4317
PROXY_TLS_CA_PATH: /run/security/internal-ca/ca.crt
PROXY_TLS_CERTIFICATE_PATH: /run/security/telemetry-gateway/tls.crt
PROXY_TLS_PRIVATE_KEY_PATH: /run/security/telemetry-gateway/tls.key
PROXY_ALLOWED_CLIENT_URI: spiffe://mtusi/lab7/collector
PROXY_ALPN_PROTOCOLS: h2
volumes:
- telemetry_gateway_security:/run/security:ro
depends_on:
security-bootstrap:
condition: service_completed_successfully
tempo:
condition: service_healthy
healthcheck:
disable: true
restart: unless-stopped
networks: [secure_clients, telemetry_storage]
loki-collector-gateway:
<<: *app-hardening
image: ${API_IMAGE:-mtusi-messenger:lab7}
command: ["/app/mtlsproxy"]
environment:
PROXY_LISTEN_ADDRESS: 0.0.0.0:8443
PROXY_TARGET_ADDRESS: loki:3100
PROXY_TLS_CA_PATH: /run/security/internal-ca/ca.crt
PROXY_TLS_CERTIFICATE_PATH: /run/security/telemetry-gateway/tls.crt
PROXY_TLS_PRIVATE_KEY_PATH: /run/security/telemetry-gateway/tls.key
PROXY_ALLOWED_CLIENT_URI: spiffe://mtusi/lab7/collector
PROXY_ALPN_PROTOCOLS: http/1.1
volumes:
- telemetry_gateway_security:/run/security:ro
depends_on:
security-bootstrap:
condition: service_completed_successfully
loki:
condition: service_healthy
healthcheck:
disable: true
restart: unless-stopped
networks: [secure_clients, telemetry_storage]
prometheus-grafana-gateway:
<<: *app-hardening
image: ${API_IMAGE:-mtusi-messenger:lab7}
command: ["/app/mtlsproxy"]
environment:
PROXY_LISTEN_ADDRESS: 0.0.0.0:8443
PROXY_TARGET_ADDRESS: prometheus:9090
PROXY_TLS_CA_PATH: /run/security/internal-ca/ca.crt
PROXY_TLS_CERTIFICATE_PATH: /run/security/telemetry-gateway/tls.crt
PROXY_TLS_PRIVATE_KEY_PATH: /run/security/telemetry-gateway/tls.key
PROXY_ALLOWED_CLIENT_URI: spiffe://mtusi/lab7/grafana
PROXY_ALPN_PROTOCOLS: http/1.1
volumes:
- telemetry_gateway_security:/run/security:ro
depends_on:
prometheus:
condition: service_healthy
healthcheck:
disable: true
restart: unless-stopped
networks: [secure_clients, telemetry_storage]
loki-grafana-gateway:
<<: *app-hardening
image: ${API_IMAGE:-mtusi-messenger:lab7}
command: ["/app/mtlsproxy"]
environment:
PROXY_LISTEN_ADDRESS: 0.0.0.0:8443
PROXY_TARGET_ADDRESS: loki:3100
PROXY_TLS_CA_PATH: /run/security/internal-ca/ca.crt
PROXY_TLS_CERTIFICATE_PATH: /run/security/telemetry-gateway/tls.crt
PROXY_TLS_PRIVATE_KEY_PATH: /run/security/telemetry-gateway/tls.key
PROXY_ALLOWED_CLIENT_URI: spiffe://mtusi/lab7/grafana
PROXY_ALPN_PROTOCOLS: http/1.1
volumes:
- telemetry_gateway_security:/run/security:ro
depends_on:
loki:
condition: service_healthy
healthcheck:
disable: true
restart: unless-stopped
networks: [secure_clients, telemetry_storage]
tempo-grafana-gateway:
<<: *app-hardening
image: ${API_IMAGE:-mtusi-messenger:lab7}
command: ["/app/mtlsproxy"]
environment:
PROXY_LISTEN_ADDRESS: 0.0.0.0:8443
PROXY_TARGET_ADDRESS: tempo:3200
PROXY_TLS_CA_PATH: /run/security/internal-ca/ca.crt
PROXY_TLS_CERTIFICATE_PATH: /run/security/telemetry-gateway/tls.crt
PROXY_TLS_PRIVATE_KEY_PATH: /run/security/telemetry-gateway/tls.key
PROXY_ALLOWED_CLIENT_URI: spiffe://mtusi/lab7/grafana
PROXY_ALPN_PROTOCOLS: http/1.1
volumes:
- telemetry_gateway_security:/run/security:ro
depends_on:
tempo:
condition: service_healthy
healthcheck:
disable: true
restart: unless-stopped
networks: [secure_clients, telemetry_storage]
otel-collector:
image: otel/opentelemetry-collector-contrib:0.160.0
command: ["--config=/etc/otelcol-contrib/collector.yaml"]
volumes:
- ./infra/otel/collector.yaml:/etc/otelcol-contrib/collector.yaml:ro
- collector_security:/run/security:ro
expose:
- "4317"
- "4318"
- "8888"
- "8889"
- "13133"
depends_on:
- loki
- tempo
healthcheck:
test: ["CMD", "/otelcol-contrib", "components"]
interval: 10s
timeout: 3s
retries: 10
cpus: ${OTEL_COLLECTOR_CPUS}
mem_limit: ${OTEL_COLLECTOR_MEMORY}
restart: unless-stopped
networks: [telemetry_backend, secure_clients, monitoring]
volumes:
api_security:
nginx_security:
prometheus_security:
client_security:
postgres_security:
valkey_security:
redis_broker_security:
redis_gateway_security:
minio_security:
otel_gateway_security:
dispatcher_security:
worker_security:
migrate_security:
reconciler_security:
postgres_bootstrap_security:
postgres_exporter_security:
valkey_exporter_security:
redis_exporter_security:
s3_bootstrap_security:
openbao_security:
openbao_agent_security:
telemetry_gateway_security:
collector_security:
grafana_security:
openbao_api_secrets:
openbao_worker_secrets:
openbao_api_identity:
openbao_worker_identity:
openbao_data:
postgres_data:
valkey_data:
redis_broker_data:
prometheus_data:
grafana_data:
loki_data:
tempo_data:
s3_data:
networks:
edge:
application:
internal: true
data:
internal: true
data_backend:
internal: true
monitoring:
internal: true
telemetry_backend:
internal: true
telemetry_storage:
internal: true
secure_clients:
internal: true
secrets:
internal: true