forked from mtusi2026/mtusi2026lab7
feat: require mTLS with certificate login for RabbitMQ and split relay and worker rights
Broker accepts only TLS 1.3 with a client certificate checked against the stand CRL; login is EXTERNAL by certificate DNS SAN, broker passwords are gone. Relay may declare its queue and publish, worker may only consume. Definitions and TLS material checks come from infra/rabbitmq/start.sh; temporary stands, CI, bench and the fault hook use the same mTLS identities. Adds make broker_mtls_check [REPORT=1] and drops the rollback broker compose. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,14 @@ from typing import Any
|
||||
import pytest
|
||||
|
||||
from src.config import settings
|
||||
from src.config.settings import BASE_DIR, S3, Cache, Database, Settings
|
||||
from src.config.settings import (
|
||||
BASE_DIR,
|
||||
S3,
|
||||
Broker,
|
||||
Cache,
|
||||
Database,
|
||||
Settings,
|
||||
)
|
||||
from src.infra.cache import client as cache_client
|
||||
from src.infra.cache.client import TlsConnection, create_cache
|
||||
from src.infra.db import engine as db_engine
|
||||
@@ -112,6 +119,20 @@ def _settings(**sections: Any) -> Settings:
|
||||
database=Database(host=sections.pop("database_host", "postgres")),
|
||||
cache=Cache(host=sections.pop("cache_host", "valkey")),
|
||||
s3=S3(host=sections.pop("s3_host", "s3")),
|
||||
broker=sections.pop("broker", Broker()),
|
||||
)
|
||||
|
||||
|
||||
def _broker(pki: Path, host: str = "rabbitmq") -> Broker:
|
||||
"""Брокер с действующими файлами identity `relay` стенда (change
|
||||
`messaging-telemetry-mtls`): у процесса с брокером проверка файлов
|
||||
пройдена, и остаётся проверка адреса."""
|
||||
stand = pki / "stand"
|
||||
return Broker(
|
||||
host=host,
|
||||
cert_file=str(stand / "relay.crt"),
|
||||
key_file=str(stand / "relay.key"),
|
||||
crl_file=str(stand / "crl.pem"),
|
||||
)
|
||||
|
||||
|
||||
@@ -143,9 +164,9 @@ def test_problems_ca_file(tmp_path: Path, pki: Path) -> None:
|
||||
("storages", "expected"),
|
||||
[
|
||||
(API_STORAGES, ["database.host", "cache.host", "s3.host"]),
|
||||
(WORKER_STORAGES, ["database.host", "s3.host"]),
|
||||
(WORKER_STORAGES, ["database.host", "s3.host", "broker.host"]),
|
||||
(CLEANER_STORAGES, ["database.host", "s3.host"]),
|
||||
(RELAY_STORAGES, ["database.host"]),
|
||||
(RELAY_STORAGES, ["database.host", "broker.host"]),
|
||||
(MIGRATION_STORAGES, ["database.host"]),
|
||||
],
|
||||
)
|
||||
@@ -154,12 +175,14 @@ def test_problems_ip_host_per_process(
|
||||
storages: tuple[str, ...],
|
||||
expected: list[str],
|
||||
) -> None:
|
||||
"""IP-адрес вместо имени (`.env` до change) — поле хранилища процесса."""
|
||||
"""IP-адрес вместо имени (`.env` до change) — поле хранилища процесса;
|
||||
брокер — только у relay и worker (change `messaging-telemetry-mtls`)."""
|
||||
loaded = _settings(
|
||||
client_tls={"ca_file": str(pki / "stand" / "ca.crt")},
|
||||
database_host="127.0.0.1",
|
||||
cache_host="::1",
|
||||
s3_host="10.0.0.5",
|
||||
broker=_broker(pki, host="127.0.0.1"),
|
||||
)
|
||||
assert client_tls_problems(loaded, storages) == expected
|
||||
|
||||
@@ -278,6 +301,12 @@ def _run_entrypoint(
|
||||
"DATABASE__HOST": "localhost",
|
||||
"CACHE__HOST": "localhost",
|
||||
"S3__HOST": "localhost",
|
||||
# брокер relay и worker (change messaging-telemetry-mtls):
|
||||
# действующие файлы identity, чтобы дойти до проверяемого поля
|
||||
"BROKER__HOST": "localhost",
|
||||
"BROKER__CERT_FILE": str(stand / "relay.crt"),
|
||||
"BROKER__KEY_FILE": str(stand / "relay.key"),
|
||||
"BROKER__CRL_FILE": str(stand / "crl.pem"),
|
||||
"TELEMETRY__ENABLED": "false",
|
||||
**env,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user