lab7: mTLS-границы, OpenBao raft, TLS-телеметрия, evidence уровней 3-4

This commit is contained in:
2026-11-27 23:05:20 +03:00
parent 6b44b067c4
commit cf6b78f899
31 changed files with 572 additions and 116 deletions
+19 -21
View File
@@ -3,7 +3,8 @@
Identity = CN сертификата (messenger-api / messenger-worker). Права выданы
раздельно и ограничены topology лаборатории (см. infra/rabbitmq/init.sh).
Topology:
Topology объявляется инфраструктурой (infra/rabbitmq/definitions.json) при
старте RabbitMQ, а не приложением: приложению не нужны права на declare.
exchange: lab5 (direct, durable)
routing_key: attachment.process.v1 → queue attachment.process.v1 (durable)
DLX: lab5.dlx (direct)
@@ -15,6 +16,7 @@ import ssl
import threading
import pika
from pika.credentials import ExternalCredentials
from . import config
@@ -43,7 +45,7 @@ def _connect():
host=config.BROKER_HOST,
port=config.BROKER_PORT,
virtual_host=config.BROKER_VHOST,
credentials=pika.ExternalCredentials(),
credentials=ExternalCredentials(),
ssl_options=pika.SSLOptions(_ssl_context(), server_hostname=config.BROKER_HOST),
heartbeat=30,
blocked_connection_timeout=30,
@@ -52,23 +54,18 @@ def _connect():
))
def connect():
"""Новое соединение TLS+EXTERNAL (worker использует его для consume)."""
return _connect()
def get_channel():
"""Один канал на процесс; worker также использует для consume."""
"""Один канал на процесс; topology объявлена инфраструктурой."""
global _channel
if _channel is None or _channel.is_closed:
with _lock:
if _channel is None or _channel.is_closed:
ch = _connect().channel()
ch.exchange_declare(EXCHANGE, exchange_type="direct", durable=True)
ch.exchange_declare(DLX, exchange_type="direct", durable=True)
ch.queue_declare(
QUEUE, durable=True,
arguments={"x-dead-letter-exchange": DLX,
"x-dead-letter-routing-key": "attachment.failed"})
ch.queue_declare(FAILED_QUEUE, durable=True)
ch.queue_bind(QUEUE, EXCHANGE, routing_key=QUEUE)
ch.queue_bind(FAILED_QUEUE, DLX, routing_key="attachment.failed")
_channel = ch
_channel = _connect().channel()
return _channel
@@ -101,7 +98,12 @@ def publish(job_payload, headers=None):
def declare_only():
get_channel()
"""Broker доступен по TLS+EXTERNAL и topology на месте (passive declare)."""
conn = _connect()
try:
conn.channel().queue_declare(QUEUE, passive=True)
finally:
conn.close()
def wait_ready(timeout=30):
@@ -111,12 +113,8 @@ def wait_ready(timeout=30):
last = None
while time.monotonic() < deadline:
try:
conn = _connect()
try:
conn.channel().queue_declare(QUEUE, passive=True)
return True
finally:
conn.close()
declare_only()
return True
except Exception as exc: # noqa: BLE001 - readiness probe
last = exc
time.sleep(0.5)