Реализовать лабораторную 7: mTLS, OpenBao и защита worker

This commit is contained in:
wpyatzy
2026-12-04 20:35:40 +03:00
parent 20afc2c790
commit 1b865eac83
146 changed files with 9552 additions and 87 deletions
+744
View File
@@ -0,0 +1,744 @@
name: mtusi-lab7
services:
db:
user: '501:20'
cap_drop: &id001
- ALL
security_opt: &id002
- no-new-privileges:true
read_only: true
tmpfs: &id003
- /tmp
restart: unless-stopped
image: haproxy:3.0.5-alpine
entrypoint:
- haproxy
command:
- -W
- -db
- -f
- /run/mesh.cfg
volumes:
- ./.secrets/roles/db:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/db.cfg:/run/mesh.cfg:ro
cpus: 0.25
mem_limit: 64m
s3:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
image: haproxy:3.0.5-alpine
entrypoint:
- haproxy
command:
- -W
- -db
- -f
- /run/mesh.cfg
volumes:
- ./.secrets/roles/s3:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/s3.cfg:/run/mesh.cfg:ro
cpus: 0.25
mem_limit: 64m
broker:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
image: haproxy:3.0.5-alpine
entrypoint:
- haproxy
command:
- -W
- -db
- -f
- /run/mesh.cfg
volumes:
- ./.secrets/roles/broker:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/broker.cfg:/run/mesh.cfg:ro
cpus: 0.25
mem_limit: 64m
cache:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
image: haproxy:3.0.5-alpine
entrypoint:
- haproxy
command:
- -W
- -db
- -f
- /run/mesh.cfg
volumes:
- ./.secrets/roles/cache:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/cache.cfg:/run/mesh.cfg:ro
cpus: 0.25
mem_limit: 64m
collector:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
image: haproxy:3.0.5-alpine
entrypoint:
- haproxy
command:
- -W
- -db
- -f
- /run/mesh.cfg
volumes:
- ./.secrets/roles/collector:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/collector.cfg:/run/mesh.cfg:ro
cpus: 0.25
mem_limit: 64m
ports:
- 127.0.0.1:8887:18888
prometheus:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
image: haproxy:3.0.5-alpine
entrypoint:
- haproxy
command:
- -W
- -db
- -f
- /run/mesh.cfg
volumes:
- ./.secrets/roles/prometheus:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/prometheus.cfg:/run/mesh.cfg:ro
cpus: 0.25
mem_limit: 64m
ports:
- 127.0.0.1:9097:19090
loki:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
image: haproxy:3.0.5-alpine
entrypoint:
- haproxy
command:
- -W
- -db
- -f
- /run/mesh.cfg
volumes:
- ./.secrets/roles/loki:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/loki.cfg:/run/mesh.cfg:ro
cpus: 0.25
mem_limit: 64m
ports:
- 127.0.0.1:3107:13100
tempo:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
image: haproxy:3.0.5-alpine
entrypoint:
- haproxy
command:
- -W
- -db
- -f
- /run/mesh.cfg
volumes:
- ./.secrets/roles/tempo:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/tempo.cfg:/run/mesh.cfg:ro
cpus: 0.25
mem_limit: 64m
ports:
- 127.0.0.1:3207:13200
grafana:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
image: haproxy:3.0.5-alpine
entrypoint:
- haproxy
command:
- -W
- -db
- -f
- /run/mesh.cfg
volumes:
- ./.secrets/roles/grafana:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/grafana.cfg:/run/mesh.cfg:ro
cpus: 0.25
mem_limit: 64m
ports:
- 127.0.0.1:3007:13000
db-engine:
image: postgres:16.6-alpine
network_mode: service:db
depends_on:
- db
command:
- postgres
- -c
- listen_addresses=127.0.0.1
- -c
- hba_file=/etc/postgresql/pg_hba.conf
volumes:
- postgres_data:/var/lib/postgresql/data
- ./infra/postgres/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro
environment:
GOMAXPROCS: '1'
POSTGRES_USER: messenger
POSTGRES_DB: messenger
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Run bootstrap}
restart: unless-stopped
cpus: 1
mem_limit: 512m
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp
cap_add:
- CHOWN
- DAC_OVERRIDE
- FOWNER
- SETGID
- SETUID
s3-engine:
image: minio/minio@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e
network_mode: service:s3
depends_on:
- s3
command:
- server
- /data
- --address
- 127.0.0.1:9000
- --console-address
- 127.0.0.1:9001
volumes:
- ./.secrets/output/data/minio:/data
environment:
GOMAXPROCS: '1'
MINIO_ROOT_USER: lab7root
MINIO_ROOT_PASSWORD: ${S3_ROOT_PASSWORD:?Run bootstrap}
MINIO_BROWSER: 'off'
restart: unless-stopped
cpus: 0.5
mem_limit: 768m
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp
user: '501:20'
read_only: true
broker-engine:
image: valkey/valkey:8.0.2-alpine
network_mode: service:broker
depends_on:
- broker
command:
- valkey-server
- --bind
- 127.0.0.1
- --appendonly
- 'yes'
- --appendfsync
- always
- --aclfile
- /run/users.acl
volumes:
- ./.secrets/output/data/broker:/data
- ./.secrets/broker.acl:/run/users.acl:ro
environment:
GOMAXPROCS: '1'
restart: unless-stopped
cpus: 0.5
mem_limit: 128m
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp
user: '501:20'
read_only: true
working_dir: /data
cache-engine:
image: valkey/valkey:8.0.2-alpine
network_mode: service:cache
depends_on:
- cache
command:
- valkey-server
- --bind
- 127.0.0.1
- --appendonly
- 'yes'
- --appendfsync
- always
- --aclfile
- /run/users.acl
volumes:
- ./.secrets/output/data/cache:/data
- ./.secrets/cache.acl:/run/users.acl:ro
environment:
GOMAXPROCS: '1'
restart: unless-stopped
cpus: 0.5
mem_limit: 128m
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp
user: '501:20'
read_only: true
working_dir: /data
collector-engine:
image: otel/opentelemetry-collector-contrib:0.117.0
network_mode: service:collector
depends_on:
- collector
command:
- --config=/etc/otel/config.yaml
volumes:
- ./infra/otel/collector.yaml:/etc/otel/config.yaml:ro
environment:
GOMAXPROCS: '1'
restart: unless-stopped
cpus: 0.5
mem_limit: 256m
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp
user: '501:20'
read_only: true
loki-engine:
image: grafana/loki:3.3.2
network_mode: service:loki
depends_on:
- loki
command:
- -config.file=/etc/loki/config.yaml
volumes:
- ./infra/loki.yaml:/etc/loki/config.yaml:ro
- ./.secrets/output/data/loki:/loki
environment:
GOMAXPROCS: '1'
restart: unless-stopped
cpus: 0.5
mem_limit: 256m
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp
user: '501:20'
read_only: true
stop_grace_period: 60s
tempo-engine:
image: grafana/tempo:2.6.1
network_mode: service:tempo
depends_on:
- tempo
command:
- -config.file=/etc/tempo/config.yaml
volumes:
- ./infra/tempo.yaml:/etc/tempo/config.yaml:ro
- ./.secrets/output/data/tempo:/var/tempo
environment:
GOMAXPROCS: '1'
restart: unless-stopped
cpus: 0.5
mem_limit: 512m
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp
user: '501:20'
read_only: true
stop_grace_period: 60s
prometheus-engine:
image: prom/prometheus:v3.1.0
network_mode: service:prometheus
depends_on:
- prometheus
command:
- --config.file=/etc/prometheus/prometheus.yaml
- --web.listen-address=127.0.0.1:9090
- --storage.tsdb.retention.time=3d
volumes:
- ./infra/prometheus:/etc/prometheus:ro
- ./.secrets/output/data/prometheus:/prometheus
- ./.secrets/roles/prometheus:/run/identity:ro
- ./.secrets/public:/run/trust:ro
environment:
GOMAXPROCS: '1'
restart: unless-stopped
cpus: 0.5
mem_limit: 256m
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp
user: '501:20'
read_only: true
grafana-engine:
image: grafana/grafana:11.4.0
network_mode: service:grafana
depends_on:
- grafana
command: []
volumes:
- ./infra/grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards:ro
- ./.secrets/grafana-datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml:ro
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
- ./.secrets/output/data/grafana:/var/lib/grafana
environment:
GOMAXPROCS: '1'
GF_SERVER_HTTP_ADDR: 127.0.0.1
GF_SECURITY_ADMIN_USER: admin
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD:?Run bootstrap}
GF_USERS_ALLOW_SIGN_UP: 'false'
GF_ANALYTICS_REPORTING_ENABLED: 'false'
restart: unless-stopped
cpus: 0.5
mem_limit: 256m
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp
user: '501:20'
read_only: true
openbao:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
image: openbao/openbao:2.1.1
command:
- server
- -config=/bao/config/server.hcl
volumes:
- ./infra/openbao/server.hcl:/bao/config/server.hcl:ro
- ./.secrets/roles/openbao/service.pem:/run/pki/server.pem:ro
- ./.secrets/ca.crt:/run/pki/ca.crt:ro
- bao_data:/bao/data
ports:
- 127.0.0.1:8207:8200
cpus: 0.5
mem_limit: 256m
api:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
build: .
image: mtusi-lab7-api:local
command:
- python
- service.py
- api
environment:
PYTHONPATH: /app
SERVICE_ROLE: api
OTEL_SERVICE_NAME: messenger-api
OTEL_EXPORTER_OTLP_ENDPOINT: http://127.0.0.1:14317
OTEL_ENABLED: 'true'
BAO_ADDR: https://openbao:8200
BAO_ROLE: api
S3_ENDPOINT: http://127.0.0.1:19000
S3_BUCKET: messenger-attachments
SESSION_STORE: valkey
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DB_POOL_MAX_SIZE: 5
JOB_MAX_ATTEMPTS: 5
JOB_TIMEOUT_SECONDS: 20
JOB_LEASE_SECONDS: 30
MAX_PENDING_JOBS: 100
volumes:
- ./.secrets/roles/api:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/api.cfg:/run/mesh.cfg:ro
cpus: 2
mem_limit: 512m
stop_grace_period: 15s
deploy:
replicas: 2
healthcheck:
test:
- CMD
- python
- -c
- import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready',timeout=3)
interval: 2s
timeout: 4s
retries: 3
worker:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
build: .
image: mtusi-lab7-api:local
command:
- python
- service.py
- worker.py
environment:
PYTHONPATH: /app
SERVICE_ROLE: worker
OTEL_SERVICE_NAME: messenger-worker
OTEL_EXPORTER_OTLP_ENDPOINT: http://127.0.0.1:14317
OTEL_ENABLED: 'true'
BAO_ADDR: https://openbao:8200
BAO_ROLE: worker
S3_ENDPOINT: http://127.0.0.1:19000
S3_BUCKET: messenger-attachments
SESSION_STORE: valkey
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DB_POOL_MAX_SIZE: 5
JOB_MAX_ATTEMPTS: 5
JOB_TIMEOUT_SECONDS: 20
JOB_LEASE_SECONDS: 30
MAX_PENDING_JOBS: 100
volumes:
- ./.secrets/roles/worker:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/worker.cfg:/run/mesh.cfg:ro
cpus: 1
mem_limit: 768m
stop_grace_period: 15s
publisher:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
build: .
image: mtusi-lab7-api:local
command:
- python
- service.py
- publisher.py
environment:
PYTHONPATH: /app
SERVICE_ROLE: publisher
OTEL_SERVICE_NAME: messenger-publisher
OTEL_EXPORTER_OTLP_ENDPOINT: http://127.0.0.1:14317
OTEL_ENABLED: 'true'
BAO_ADDR: https://openbao:8200
BAO_ROLE: publisher
S3_ENDPOINT: http://127.0.0.1:19000
S3_BUCKET: messenger-attachments
SESSION_STORE: valkey
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DB_POOL_MAX_SIZE: 5
JOB_MAX_ATTEMPTS: 5
JOB_TIMEOUT_SECONDS: 20
JOB_LEASE_SECONDS: 30
MAX_PENDING_JOBS: 100
volumes:
- ./.secrets/roles/publisher:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/publisher.cfg:/run/mesh.cfg:ro
cpus: 1
mem_limit: 512m
stop_grace_period: 15s
observer:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
build: .
image: mtusi-lab7-api:local
command:
- python
- service.py
- observe.py
environment:
PYTHONPATH: /app
SERVICE_ROLE: observer
OTEL_SERVICE_NAME: messenger-observer
OTEL_EXPORTER_OTLP_ENDPOINT: http://127.0.0.1:14317
OTEL_ENABLED: 'true'
BAO_ADDR: https://openbao:8200
BAO_ROLE: observer
S3_ENDPOINT: http://127.0.0.1:19000
S3_BUCKET: messenger-attachments
SESSION_STORE: valkey
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DB_POOL_MAX_SIZE: 5
JOB_MAX_ATTEMPTS: 5
JOB_TIMEOUT_SECONDS: 20
JOB_LEASE_SECONDS: 30
MAX_PENDING_JOBS: 100
volumes:
- ./.secrets/roles/observer:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/observer.cfg:/run/mesh.cfg:ro
cpus: 1
mem_limit: 512m
stop_grace_period: 15s
janitor:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
build: .
image: mtusi-lab7-api:local
command:
- python
- service.py
- janitor.py
environment:
PYTHONPATH: /app
SERVICE_ROLE: janitor
OTEL_SERVICE_NAME: messenger-janitor
OTEL_EXPORTER_OTLP_ENDPOINT: http://127.0.0.1:14317
OTEL_ENABLED: 'true'
BAO_ADDR: https://openbao:8200
BAO_ROLE: janitor
S3_ENDPOINT: http://127.0.0.1:19000
S3_BUCKET: messenger-attachments
SESSION_STORE: valkey
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DB_POOL_MAX_SIZE: 5
JOB_MAX_ATTEMPTS: 5
JOB_TIMEOUT_SECONDS: 20
JOB_LEASE_SECONDS: 30
MAX_PENDING_JOBS: 100
volumes:
- ./.secrets/roles/janitor:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/janitor.cfg:/run/mesh.cfg:ro
cpus: 1
mem_limit: 512m
stop_grace_period: 15s
operator:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: 'no'
build: .
image: mtusi-lab7-api:local
command:
- python
- service.py
- operator
environment:
PYTHONPATH: /app
SERVICE_ROLE: operator
OTEL_SERVICE_NAME: messenger-operator
OTEL_EXPORTER_OTLP_ENDPOINT: http://127.0.0.1:14317
OTEL_ENABLED: 'false'
BAO_ADDR: https://openbao:8200
BAO_ROLE: operator
S3_ENDPOINT: http://127.0.0.1:19000
S3_BUCKET: messenger-attachments
SESSION_STORE: valkey
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DB_POOL_MAX_SIZE: 5
JOB_MAX_ATTEMPTS: 5
JOB_TIMEOUT_SECONDS: 20
JOB_LEASE_SECONDS: 30
MAX_PENDING_JOBS: 100
volumes:
- ./.secrets/roles/operator:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/operator.cfg:/run/mesh.cfg:ro
- ./.secrets/operator-env.json:/run/operator-env.json:ro
- ./tests:/app/tests:ro
- ./scripts:/app/scripts:ro
cpus: 1
mem_limit: 512m
stop_grace_period: 15s
profiles:
- tools
lb:
user: '501:20'
cap_drop: *id001
security_opt: *id002
read_only: true
tmpfs: *id003
restart: unless-stopped
image: haproxy:3.0.5-alpine
entrypoint:
- haproxy
command:
- -W
- -db
- -f
- /run/mesh.cfg
volumes:
- ./.secrets/roles/lb:/run/identity:ro
- ./.secrets/public:/run/trust:ro
- ./infra/mesh/lb.cfg:/run/mesh.cfg:ro
ports:
- 127.0.0.1:8443:8443
cpus: 0.25
mem_limit: 64m
depends_on:
- api
volumes:
postgres_data: {}
bao_data: {}