forked from mtusi2026/mtusi2026lab7
feat: load process secrets from OpenBao via cert auth
OpenBao 2.7.3 (raft, TLS 1.3 with client certificates) holds the PostgreSQL role passwords, the Valkey password and the S3 keys; each process logs in with its own mTLS identity, reads only its paths and renews its token in the background. Operator init, unseal, configure and seed go through infra/openbao/bao.py and make bao_*; checks are make bao_check and driver.py openbao-outage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -444,3 +444,78 @@ def test_auth_from_environment_over_file(
|
||||
assert _EnvAndToml().auth.login_max_failures_per_account == 7
|
||||
monkeypatch.setenv("AUTH__LOGIN_MAX_FAILURES_PER_ACCOUNT", "3")
|
||||
assert _EnvAndToml().auth.login_max_failures_per_account == 3
|
||||
|
||||
|
||||
# --- [secrets] (change openbao-secrets, design, решения 7, 10; спек
|
||||
# service-configuration, «Параметры хранилища секретов»)
|
||||
|
||||
|
||||
def test_secrets_defaults() -> None:
|
||||
"""«Значения по умолчанию»: OpenBao в сети стенда, ожидание при старте
|
||||
30 с, повтор 2 с; файлов identity по умолчанию нет."""
|
||||
loaded = _ArgumentsOnly().secrets
|
||||
assert loaded.address == "https://openbao:8200"
|
||||
assert loaded.startup_timeout_seconds == 30
|
||||
assert loaded.retry_seconds == 2
|
||||
assert loaded.request_timeout_seconds < loaded.startup_timeout_seconds
|
||||
assert (loaded.cert_file, loaded.key_file, loaded.crl_file) == ("", "", "")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("field", "value"),
|
||||
[
|
||||
("address", "http://openbao:8200"),
|
||||
("address", "https://openbao:8200/v1"),
|
||||
("address", "https://openbao:8200?x=1"),
|
||||
("address", "https://user:pw@openbao:8200"),
|
||||
("address", "https://openbao"),
|
||||
("connect_timeout_seconds", 0),
|
||||
("request_timeout_seconds", float("inf")),
|
||||
("startup_timeout_seconds", 0),
|
||||
("startup_timeout_seconds", float("nan")),
|
||||
("retry_seconds", -1),
|
||||
],
|
||||
)
|
||||
def test_wrong_secrets_value_names_field(field: str, value: object) -> None:
|
||||
"""«Адрес только https», «Неверный срок»: ошибка называет поле."""
|
||||
with pytest.raises(ValidationError) as caught:
|
||||
_ArgumentsOnly(secrets={field: value})
|
||||
assert ("secrets", field) in {e["loc"] for e in caught.value.errors()}
|
||||
|
||||
|
||||
def test_secrets_request_shorter_than_startup() -> None:
|
||||
with pytest.raises(ValidationError) as caught:
|
||||
_ArgumentsOnly(
|
||||
secrets={
|
||||
"request_timeout_seconds": 10,
|
||||
"startup_timeout_seconds": 10,
|
||||
},
|
||||
)
|
||||
assert ("secrets", "startup_timeout_seconds") in {
|
||||
e["loc"] for e in caught.value.errors()
|
||||
}
|
||||
|
||||
|
||||
def test_wrong_secrets_from_environment_names_field(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setenv("SECRETS__STARTUP_TIMEOUT_SECONDS", "0")
|
||||
with pytest.raises(ValidationError) as caught:
|
||||
_EnvironmentOnly()
|
||||
assert ("secrets", "startup_timeout_seconds") in {
|
||||
e["loc"] for e in caught.value.errors()
|
||||
}
|
||||
|
||||
|
||||
def test_example_toml_has_no_secrets_paths() -> None:
|
||||
"""Адрес и пути identity задают compose и цели make: в шаблоне только
|
||||
закомментированные сроки, и он загружается с умолчаниями."""
|
||||
text = EXAMPLE_TOML_PATH.read_text()
|
||||
section = text.split("[secrets]", 1)[1]
|
||||
active = [
|
||||
line
|
||||
for line in section.splitlines()
|
||||
if line.strip() and not line.lstrip().startswith("#")
|
||||
]
|
||||
assert active == []
|
||||
assert _ExampleToml().secrets == _ArgumentsOnly().secrets
|
||||
|
||||
Reference in New Issue
Block a user