forked from mtusi2026/mtusi2026lab7
fix: address openbao-tooling verify findings
- secrets summary: per-life gap between logins (OpenBao outages excluded) catches a renewal thread that died after the first login; delta and rule updated, fast tests on synthetic logs - record the apply deviation (operator materials read by the leak scan) and switch the leak scan to patterns - test_secret_new_version checks N -> N+1, sealed-by-operator test unseals right after the waiting record - driver: operator dir refusal exits with code 2 - fast test for Operator.wait_active, check counts 158 -> 164 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6961,6 +6961,9 @@ SECRETS_REQUEST_TIMEOUT_S = 5
|
||||
RENEW_FRACTION = 2 / 3
|
||||
# остановка процесса — меньше срока Docker по умолчанию
|
||||
STOP_BUDGET_S = 10
|
||||
# от docker start до начала загрузки секретов (старт интерпретатора, импорт
|
||||
# настроек) — с запасом
|
||||
PROCESS_START_SLACK_S = 2
|
||||
|
||||
|
||||
def renewal_bound_s() -> float:
|
||||
@@ -7113,7 +7116,13 @@ def test_openbao_sealed_by_operator(api: Api, stand: Stand) -> None:
|
||||
"""Спек `secret-store`, «OpenBao запечатан оператором»: работающий стенд
|
||||
обслуживает запросы; новый процесс API ждёт OpenBao («Waiting for secrets
|
||||
store») и не становится `healthy`; после `unseal` тот же процесс без
|
||||
перезапуска загружает секреты и становится `healthy` в срок ожидания."""
|
||||
перезапуска загружает секреты и становится `healthy` в срок ожидания.
|
||||
|
||||
Распечатывание — сразу после записи «Waiting» (правки verify S5): срок
|
||||
ожидания API идёт с его старта, и время unseal (`bao.py` и ожидание
|
||||
активного узла) входит в него; сообщения падения называют длительность
|
||||
unseal. До unseal процесс не `healthy`: «Loaded process secrets» пишется
|
||||
раньше «Started API», и её `waited_seconds` покрывает время до unseal."""
|
||||
assert_bao_stand(stand)
|
||||
stand("seal", "openbao")
|
||||
try:
|
||||
@@ -7125,21 +7134,29 @@ def test_openbao_sealed_by_operator(api: Api, stand: Stand) -> None:
|
||||
stand("kill-api")
|
||||
stand("start-api", "nowait")
|
||||
started = time.monotonic()
|
||||
restarts = api_state(stand)["restart_count"]
|
||||
waiting = wait_api_event(
|
||||
stand,
|
||||
before,
|
||||
"Waiting for secrets store",
|
||||
timeout=SECRETS_STARTUP_TIMEOUT_S / 2,
|
||||
)
|
||||
assert waiting["timeout_seconds"] == SECRETS_STARTUP_TIMEOUT_S
|
||||
state = api_state(stand)
|
||||
assert state["running"] and state["health"] != "healthy", state
|
||||
restarts = state["restart_count"]
|
||||
unseal_started = time.monotonic()
|
||||
stand("unseal", "openbao")
|
||||
unseal_s = time.monotonic() - unseal_started
|
||||
assert waiting["timeout_seconds"] == SECRETS_STARTUP_TIMEOUT_S
|
||||
deadline = started + SECRETS_STARTUP_TIMEOUT_S
|
||||
while (state := api_state(stand))["health"] != "healthy":
|
||||
assert state["running"], f"API exited while waiting: {state}"
|
||||
assert time.monotonic() < deadline, f"API not healthy: {state}"
|
||||
assert state["running"], (
|
||||
f"API exited while waiting (unseal took {unseal_s:.1f} s, "
|
||||
f"started {unseal_started - started:.1f} s after the API): "
|
||||
f"{state}"
|
||||
)
|
||||
assert time.monotonic() < deadline, (
|
||||
f"API not healthy in {SECRETS_STARTUP_TIMEOUT_S:.0f} s "
|
||||
f"(unseal took {unseal_s:.1f} s, started "
|
||||
f"{unseal_started - started:.1f} s after the API): {state}"
|
||||
)
|
||||
time.sleep(0.2)
|
||||
assert state["restart_count"] == restarts, state
|
||||
records = new_api_records(stand, before)
|
||||
@@ -7147,6 +7164,12 @@ def test_openbao_sealed_by_operator(api: Api, stand: Stand) -> None:
|
||||
r for r in records if r.get("event") == "Loaded process secrets"
|
||||
]
|
||||
assert len(loaded) == 1, loaded
|
||||
# процесс ждал не меньше, чем до начала unseal (запас — старт
|
||||
# интерпретатора до начала загрузки)
|
||||
assert (
|
||||
loaded[0]["waited_seconds"]
|
||||
>= unseal_started - started - PROCESS_START_SLACK_S
|
||||
), (loaded[0], unseal_started - started)
|
||||
assert loaded[0]["waited_seconds"] > 0, loaded[0]
|
||||
assert (
|
||||
sum(r.get("event") == "Waiting for secrets store" for r in records)
|
||||
@@ -7263,6 +7286,8 @@ def test_secret_new_version(api: Api, stand: Stand) -> None:
|
||||
timeout=renewal_bound_s(),
|
||||
match=lambda r: r.get("path") == "messenger/data/postgres/api",
|
||||
)
|
||||
# N → N+1: процесс загрузил версию N, в OpenBao теперь N+1
|
||||
assert changed["loaded_version"] == old, changed
|
||||
assert changed["current_version"] == new, changed
|
||||
assert "password" not in json.dumps(changed), changed
|
||||
api.send_message(alice, chat["id"], "same password, new version")
|
||||
|
||||
Reference in New Issue
Block a user