forked from mtusi2026/mtusi2026lab7
feat: require TLS to PostgreSQL, Valkey and S3
Storage servers accept only TLS 1.3 (pg_hba hostssl / hostnossl reject, Valkey port 0, S3 gateway HTTPS only) with stand identities postgres, valkey and s3. Clients trust only the stand CA from [client_tls] ca_file and check the host name; no switch to disable verification. Processes exit with code 2 without a CA or with an IP storage address. Temporary stands, CI and bench/ run on TLS storages; make storage_tls_check adds negative checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -69,6 +69,7 @@ from src.infra.db import ( # noqa: E402
|
||||
)
|
||||
from src.infra.db.models.base import Base # noqa: E402
|
||||
from src.infra.db.uow import SqlAlchemyUnitOfWork # noqa: E402
|
||||
from src.infra.tls import build_client_context # noqa: E402
|
||||
|
||||
_created = False
|
||||
|
||||
@@ -99,6 +100,9 @@ async def _admin_connection(database: str = "postgres") -> asyncpg.Connection:
|
||||
password=source.password.get_secret_value(),
|
||||
database=database,
|
||||
timeout=source.connect_timeout_seconds,
|
||||
# PostgreSQL стенда по сети — только TLS (change storage-tls): тот же
|
||||
# контекст клиента, что у процессов, CA — CLIENT_TLS__CA_FILE от make
|
||||
ssl=build_client_context(settings.client_tls.ca_file),
|
||||
)
|
||||
|
||||
|
||||
@@ -137,8 +141,13 @@ def anyio_backend() -> str:
|
||||
|
||||
|
||||
def make_engine(**overrides: object) -> AsyncEngine:
|
||||
"""Свой engine к временной базе: тот же `create_engine`, что у процессов."""
|
||||
return create_engine(settings.database.model_copy(update=overrides))
|
||||
"""Свой engine к временной базе: тот же `create_engine`, что у процессов,
|
||||
по TLS с CA стенда. Через `TcpProxy` — `host="localhost"`: прокси передаёт
|
||||
байты TLS как есть, имя сервера проверяется по SAN identity postgres."""
|
||||
return create_engine(
|
||||
settings.database.model_copy(update=overrides),
|
||||
ca_file=settings.client_tls.ca_file,
|
||||
)
|
||||
|
||||
|
||||
def make_uow(
|
||||
|
||||
Reference in New Issue
Block a user