lab7: обязательное mTLS LB->API с allowlist identity (SAN lb), health только на loopback, скрипт отрицательных проверок mtls_check

This commit is contained in:
Alexey Bodanyuk
2026-11-27 16:14:05 +03:00
parent 7c43d31dc7
commit f36da97951
10 changed files with 401 additions and 20 deletions
+3 -2
View File
@@ -1,6 +1,7 @@
"""Docker HEALTHCHECK probe without curl/wget in the image: `python -m messenger.healthcheck`.
(no arguments) API: GET /health/ready on the local port
(no arguments) API: GET /health/ready on the loopback health port
(APP_HEALTH_PORT, lab 7: the main port requires mTLS)
--file /tmp/heartbeat --max-age 30 relay/worker: the main loop wrote its heartbeat recently
(it writes it only while its database/broker work)
"""
@@ -19,7 +20,7 @@ def main(argv: list[str]) -> int:
return 0 if time.time() - float(f.read().strip()) <= float(argv[3]) else 1
except (OSError, ValueError):
return 1
port = os.environ.get("APP_PORT", "8080").strip() or "8080"
port = os.environ.get("APP_HEALTH_PORT", "").strip() or os.environ.get("APP_PORT", "8080").strip() or "8080"
try:
with urllib.request.urlopen(f"http://127.0.0.1:{port}/health/ready", timeout=2) as response:
return 0 if response.status == 200 else 1