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:
2026-11-18 21:17:49 +03:00
co-authored by Claude Opus 5.5
parent 25f5d981c0
commit 8bca5543fd
56 changed files with 2562 additions and 176 deletions
+25 -4
View File
@@ -214,10 +214,18 @@ class ObjectStorage:
открываются при первом запросе.
"""
def __init__(self, s3: S3Settings, *, namespace: str) -> None:
def __init__(
self,
s3: S3Settings,
*,
namespace: str,
ca_file: str,
) -> None:
self.namespace = namespace
self.bucket = s3.bucket
self._settings = s3
# CA стенда (`[client_tls] ca_file`): шлюз — только HTTPS
self._ca_file = ca_file
self._endpoint = f"{s3.host}:{s3.port}"
self._timeout_seconds = s3.timeout_seconds
self._client: Any = None
@@ -363,6 +371,12 @@ class ObjectStorage:
def _create_client(self) -> Any:
s3 = self._settings
# TLS к шлюзу (change storage-tls, design, решение 5): botocore
# проверяет цепочку только по этому CA и имя s3.host. Пустой путь
# botocore понял бы как verify=False — без CA клиента нет (точки
# входа проверяют поле до старта, `client_tls_problems`)
if not self._ca_file:
raise ValueError("client_tls.ca_file is required for S3")
config = AioConfig(
# виртуальные хосты bucket.s3 Docker DNS не разрешает
s3={"addressing_style": "path"},
@@ -387,6 +401,7 @@ class ObjectStorage:
return get_session().create_client(
"s3",
endpoint_url=s3.endpoint_url,
verify=self._ca_file,
region_name=s3.region,
aws_access_key_id=s3.access_key_id.get_secret_value(),
aws_secret_access_key=s3.secret_access_key.get_secret_value(),
@@ -562,6 +577,12 @@ class ObjectStorage:
return round((time.monotonic() - started) * 1000)
def create_object_storage(s3: S3Settings, *, namespace: str) -> ObjectStorage:
"""Хранилище объектов по `[s3]`; клиент и соединения — лениво."""
return ObjectStorage(s3, namespace=namespace)
def create_object_storage(
s3: S3Settings,
*,
namespace: str,
ca_file: str,
) -> ObjectStorage:
"""Хранилище объектов по `[s3]` по HTTPS с CA `ca_file`; клиент и
соединения — лениво."""
return ObjectStorage(s3, namespace=namespace, ca_file=ca_file)