feat: separate PostgreSQL roles and Valkey ACL per service

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 14:10:09 +03:00
co-authored by Claude Opus 5.5
parent c5b03e6efa
commit d5eaeb3183
44 changed files with 4013 additions and 129 deletions
+26
View File
@@ -22,6 +22,7 @@ from src.config.settings import (
ApiTls,
App,
Auth,
DbRoles,
Settings,
Telemetry,
Uploads,
@@ -254,6 +255,31 @@ def test_client_tls_from_environment(monkeypatch: pytest.MonkeyPatch) -> None:
assert _EnvironmentOnly().client_tls.ca_file == "/run/secrets/ca.crt"
def test_db_roles_from_environment(monkeypatch: pytest.MonkeyPatch) -> None:
"""Спек `service-configuration`, «Подключение к PostgreSQL»: пароли ролей
читает bootstrap из `DB_ROLES__*`, по умолчанию пусто; в шаблоне toml их
нет (источник — `.env`)."""
loaded = _EnvironmentOnly()
assert loaded.db_roles == DbRoles()
assert loaded.db_roles.api_password.get_secret_value() == ""
monkeypatch.setenv("DB_ROLES__WORKER_PASSWORD", "worker-secret")
loaded = _EnvironmentOnly()
assert loaded.db_roles.worker_password.get_secret_value() == (
"worker-secret"
)
assert "worker-secret" not in repr(loaded.db_roles)
assert "db_roles" not in EXAMPLE_TOML_PATH.read_text()
def test_cache_username_from_environment(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Пользователь ACL Valkey: пусто — `default`, у API — `api`."""
assert _EnvironmentOnly().cache.username == ""
monkeypatch.setenv("CACHE__USERNAME", "api")
assert _EnvironmentOnly().cache.username == "api"
def test_s3_endpoint_is_https() -> None:
"""Шлюз S3 — только HTTPS (change `storage-tls`): URL с именем хоста."""
s3 = _ArgumentsOnly(s3={"host": "s3", "port": 8333}).s3