forked from mtusi2026/mtusi2026lab7
lab7: обязательное mTLS LB->API с allowlist identity (SAN lb), health только на loopback, скрипт отрицательных проверок mtls_check
This commit is contained in:
+61
-2
@@ -296,6 +296,13 @@ services:
|
||||
environment:
|
||||
<<: [*api-env, *otel-env]
|
||||
OTEL_SERVICE_NAME: messenger-api
|
||||
# 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_CLIENT_CA_FILE: /run/secrets/internal-ca.crt
|
||||
MTLS_ALLOWED_CLIENTS: ${MTLS_ALLOWED_CLIENTS:-lb}
|
||||
secrets:
|
||||
- database_url
|
||||
- cache_url
|
||||
@@ -303,9 +310,12 @@ services:
|
||||
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: 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. X-Instance-Id = container hostname.
|
||||
expose: ["8080"]
|
||||
# and `--scale api=N` / deploy.replicas works.
|
||||
expose: ["8443"]
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-m", "messenger.healthcheck"]
|
||||
interval: 2s
|
||||
@@ -343,6 +353,10 @@ services:
|
||||
secrets:
|
||||
- source: pki_ingress_pem # public-ca leaf + key, SAN localhost/127.0.0.1/::1
|
||||
target: ingress.pem
|
||||
- source: pki_lb_pem # client identity towards the API (internal CA, SAN lb)
|
||||
target: lb.pem
|
||||
- source: pki_internal_ca
|
||||
target: internal-ca.crt # verifies the replicas (SAN api)
|
||||
ports:
|
||||
# The ONLY public entry point: HTTPS, on the loopback interfaces only. Both IPv4 and IPv6:
|
||||
# on Windows `localhost` resolves to ::1 first, and a refused ::1 connection costs ~2 s
|
||||
@@ -505,6 +519,31 @@ services:
|
||||
resources:
|
||||
limits: {cpus: "0.5", memory: 128m}
|
||||
|
||||
# Lab 7: proof of the LB -> API mTLS against every replica directly (scripts/mtls_check.py):
|
||||
# docker compose run --rm mtls-check
|
||||
# Joins `edge` like the LB. Test-only material: the LB client key (positive case), the worker
|
||||
# certificate (trusted CA, wrong role) and a certificate of a foreign CA with SAN lb.
|
||||
mtls-check:
|
||||
profiles: ["tools"]
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
entrypoint: ["python", "/opt/check/mtls_check.py"]
|
||||
command: []
|
||||
volumes:
|
||||
- ./scripts/mtls_check.py:/opt/check/mtls_check.py:ro
|
||||
secrets:
|
||||
- {source: pki_internal_ca, target: internal-ca.crt}
|
||||
- {source: pki_lb_crt, target: lb.crt}
|
||||
- {source: pki_lb_key, target: lb.key}
|
||||
- {source: pki_worker_crt, target: worker.crt}
|
||||
- {source: pki_worker_key, target: worker.key}
|
||||
- {source: pki_foreign_lb_crt, target: foreign-lb.crt}
|
||||
- {source: pki_foreign_lb_key, target: foreign-lb.key}
|
||||
restart: "no"
|
||||
networks: [edge]
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: "0.5", memory: 128m}
|
||||
|
||||
# ------------------------------------------------------------------ lab 6: observability
|
||||
# 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.
|
||||
@@ -687,3 +726,23 @@ secrets:
|
||||
# verifies peers with; the CA private keys are mounted nowhere.
|
||||
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_worker_crt:
|
||||
file: ./secrets/pki/worker.crt
|
||||
pki_worker_key:
|
||||
file: ./secrets/pki/worker.key
|
||||
pki_foreign_lb_crt: # test only: foreign CA, SAN lb
|
||||
file: ./secrets/pki/foreign-lb.crt
|
||||
pki_foreign_lb_key:
|
||||
file: ./secrets/pki/foreign-lb.key
|
||||
|
||||
Reference in New Issue
Block a user