fix: address rotation-revocation narrow verify findings

Name restarting both the LB and the replicas when the LB has no ready
replica, state the measured 25 s bound of the LB metrics port, narrow the
missing files of a held identity to its certificate, and cover refusals
and signals during CRL issue with fast tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 17:45:36 +03:00
co-authored by Claude Opus 5.5
parent 10973231a0
commit 452c5953b8
17 changed files with 220 additions and 38 deletions
+15 -5
View File
@@ -364,19 +364,25 @@ def _revoked(root: Path) -> bool:
return row.startswith("R")
@pytest.mark.parametrize("step", ["-revoke", "-gencrl"])
@pytest.mark.parametrize("when", ["before", "after"])
@pytest.mark.parametrize("number", ["HUP", "INT", "TERM"])
def test_hold_survives_a_signal(number: str, when: str, root: Path) -> None:
"""Сигнал самой команде или всей группе во время отзыва (до записи в базу
и после неё): отзыв доведён до CRL, отметка стоит — `stand` отозванной
identity ключа не выдаст."""
def test_hold_survives_a_signal(
number: str,
when: str,
step: str,
root: Path,
) -> None:
"""Сигнал самой команде или всей группе во время отзыва и выпуска CRL (до
записи openssl и после неё): отзыв доведён до CRL, отметка стоит — `stand`
отозванной identity ключа не выдаст."""
body = (
f"kill -{number} $PPID $$"
if when == "before"
else f'real "$@"; kill -{number} $PPID $$; exit 0'
)
crl = (root / "stand" / "crl.pem").read_bytes()
env = _fake_openssl(root, "-revoke", body)
env = _fake_openssl(root, step, body)
result = _run_in(root, "revoke", "relay", "--hold", env=env)
assert result.returncode == 0, result.stderr
assert _revoked(root)
@@ -506,6 +512,8 @@ def test_two_held_in_a_recreated_stand_directory(root: Path, pki: Run) -> None:
)
assert out.count(chain) == 2 # noqa: PLR2004
assert "rotate worker;" not in out
assert out.count("only from make rotate_leaf IDENTITY=") == 1
assert "only from make rotate_leaf IDENTITY=worker" in out
def test_hold_in_a_recreated_stand_directory(root: Path, pki: Run) -> None:
@@ -516,6 +524,7 @@ def test_hold_in_a_recreated_stand_directory(root: Path, pki: Run) -> None:
shutil.rmtree(root / "stand")
out = pki("stand").stdout
assert "held relay: missing" in out
assert "rotate_leaf" not in out
assert (
"held relay: compose cannot start without its files; to return it: "
"infra/pki/pki.sh rotate relay; make stop; make bao_unseal; "
@@ -574,6 +583,7 @@ def test_status_marks_revoked(root: Path, pki: Run) -> None:
def test_revoke_unknown_flag(root: Path, pki: Run, flag: str) -> None:
before = _state(root)
assert pki("revoke", "relay", flag).returncode == 2 # noqa: PLR2004
assert "PKI_LOCK_WAIT" in pki("revoke", "relay", flag).stderr
assert _state(root) == before
assert "held" not in pki("stand").stdout
+52 -1
View File
@@ -469,6 +469,7 @@ def test_require_ready(stand: RunStand) -> None:
def test_require_files(name: str, stand: RunStand) -> None:
_ready(stand)
(stand.pki_dir / name).unlink()
stand.missing = {"relay"}
with pytest.raises(rotation.NotReady, match=f"no {name}"):
stand.require(set())
@@ -563,7 +564,7 @@ def test_require_of_revoked_owner(status: str, stand: RunStand) -> None:
LB_HINT = (
"run make run_docker first; if the LB still has no ready replica: docker "
"compose restart api"
"compose restart haproxy api"
)
@@ -593,6 +594,11 @@ LB_HINT = (
{"api", "api-client"},
"run make rotate_leaf IDENTITY=api-client first",
),
(
"haproxy",
{"api-client", "haproxy"},
"run make rotate_leaf IDENTITY=api-client first",
),
("api", {"api"}, "run make rotate_leaf IDENTITY=api first"),
("relay", {"api-client"}, "run make run_docker first"),
("haproxy", {"relay"}, LB_HINT),
@@ -636,6 +642,51 @@ def test_recreated_stand_directory(stand: RunStand) -> None:
assert f"$(held_missing){'; '.join(rotation.RECREATED_STEPS)}" in script
@pytest.mark.parametrize("missing", ["worker", "openbao", "api"])
@pytest.mark.parametrize(
"command",
[
"leaf relay",
"leaf openbao",
"leaf api",
"revoke relay",
"renew",
"secret postgres/worker",
],
)
def test_command_in_a_recreated_stand_directory(
command: str,
missing: str,
stand: RunStand,
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
) -> None:
"""Сценарий «Каталог стенда создан заново»: сертификата удержанной нет —
каждая команда читает статус PKI и отказывает с цепочкой до изменений: код
2, кроме чтения статуса не запущено ничего, `.env` прежний."""
_ready(stand, worker=("running", None, NEW))
stand.on(
"pki.sh status",
f"leaf {missing}: MISSING, held until infra/pki/pki.sh rotate "
f"{missing} (x)\n",
)
stand.env_file = stand.pki_dir / ".env"
env = "POSTGRES_WORKER_PASSWORD=0123456789abcdef\n"
stand.env_file.write_text(env)
monkeypatch.delenv("POSTGRES_WORKER_PASSWORD", raising=False)
name, *args = command.split()
call = getattr(rotation, f"cmd_{name}")
assert rotation.execute(stand, lambda: call(stand, *args)) == 2 # noqa: PLR2004
steps = "; ".join(rotation.RECREATED_STEPS)
assert capsys.readouterr().out == (
f"rotation: no files of the revoked {missing} in the stand directory: "
f"run infra/pki/pki.sh rotate {missing}; {steps}; nothing changed\n"
)
assert stand.changed is False
assert [c.text.split("pki.sh ")[-1] for c in stand.calls] == ["status"]
assert stand.env_file.read_text() == env
def _rollout_refuses(stand: RunStand) -> None:
stand.on("rolling-update.sh", (2, "", "error: replica x is not UP\n"))