forked from mtusi2026/mtusi2026lab7
fix: address rotation-revocation control verify findings
Keep the hold mark of an identity whose revocation has started whatever signal ends pki.sh, refuse every rotation command while the files of a held identity are missing, bound the handshake of the LB metrics port, name sessions of another password until verify ends, and run Makefile prerequisites in order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -936,27 +936,29 @@ def test_secret_failure_names_phase(
|
||||
assert f"FAILED in phase '{phase}'" in out
|
||||
assert "make rotate_secret SECRET=postgres/api" in out
|
||||
assert "make run_docker" in out
|
||||
# от новой строки .env до закрытия сессии прежнего пароля открыты, и
|
||||
# run_docker их не закроет: названо
|
||||
open_sessions = phase != "verify"
|
||||
assert ("opened with the previous password" in out) is open_sessions
|
||||
assert ("only restores the service" in out) is open_sessions
|
||||
# от новой строки .env до конца verify: сессия могла сменить пароль роли
|
||||
# раньше закрытия и открыть другую, а run_docker её не закроет
|
||||
assert "sessions of role api opened with another password may" in out
|
||||
assert "only restores the service" in out
|
||||
assert "or run `make run_docker`" not in out
|
||||
|
||||
|
||||
@pytest.mark.parametrize("fail", ["apply", "check"])
|
||||
def test_failure_after_the_sessions_are_closed(
|
||||
fail: str,
|
||||
secret_env: Path,
|
||||
capsys: pytest.CaptureFixture[str],
|
||||
) -> None:
|
||||
"""Сессии роли без реплик закрыты сразу после смены пароля: дальше сбой
|
||||
сводит и `run_docker`, открытых сессий вывод не называет."""
|
||||
"""Сессии роли без реплик закрыты сразу после смены пароля, но что
|
||||
открытых не осталось, подтверждает только verify: до его конца вывод их
|
||||
называет."""
|
||||
stand = FakeStand(secret_env)
|
||||
stand.seeded = {"postgres/cleaner": 2}
|
||||
stand.fail = "apply"
|
||||
stand.fail = fail
|
||||
assert _run(stand, rotation.cmd_secret, "postgres/cleaner") == 1
|
||||
out = capsys.readouterr().out.split("FAILED", 1)[1]
|
||||
assert "in phase 'processes'" in out
|
||||
assert "opened with the previous password" not in out
|
||||
assert "or run `make run_docker` to converge" in out
|
||||
assert "sessions of role cleaner opened with another password" in out
|
||||
assert "or run `make run_docker`" not in out
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", ["postgres/worker", "s3/api", "valkey/api"])
|
||||
@@ -1326,7 +1328,46 @@ def _idle(pki_dir: Path) -> int:
|
||||
).returncode
|
||||
|
||||
|
||||
@pytest.mark.parametrize("argv", [["leaf", "relay"], ["secret", "s3/api"]])
|
||||
@pytest.mark.skipif(os.getuid() == 0, reason="root ignores file modes")
|
||||
@pytest.mark.parametrize("how", ["file", "directory", "parent"])
|
||||
def test_lock_file_is_named(
|
||||
how: str,
|
||||
tmp_path: Path,
|
||||
capsys: pytest.CaptureFixture[str],
|
||||
) -> None:
|
||||
"""Чужой файл блокировки, каталог только на чтение и недоступный — код 2 с
|
||||
путём; каталога нет — `make pki_stand`."""
|
||||
stand = FakeStand()
|
||||
stand.pki_dir = tmp_path / "parent" / "stand"
|
||||
stand.pki_dir.mkdir(parents=True)
|
||||
lock = stand.pki_dir / ".rotation.lock"
|
||||
path = {
|
||||
"file": lock,
|
||||
"directory": stand.pki_dir,
|
||||
"parent": stand.pki_dir.parent,
|
||||
}[how]
|
||||
lock.touch() if how == "file" else None
|
||||
mode = path.stat().st_mode
|
||||
path.chmod(0o500 if how == "directory" else 0)
|
||||
try:
|
||||
code = rotation.execute(stand, lambda: rotation.cmd_idle(stand))
|
||||
out = capsys.readouterr().out
|
||||
finally:
|
||||
path.chmod(mode)
|
||||
assert code == 2 # noqa: PLR2004
|
||||
assert out == (
|
||||
f"rotation: cannot lock {lock}: Permission denied; nothing changed\n"
|
||||
)
|
||||
stand.pki_dir = tmp_path / "missing"
|
||||
assert rotation.execute(stand, stand.lock) == 2 # noqa: PLR2004
|
||||
out = capsys.readouterr().out
|
||||
assert f"no {tmp_path / 'missing'}: run make pki_stand" in out
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"argv",
|
||||
[["leaf", "relay"], ["secret", "s3/api"], ["renew"], ["revoke", "relay"]],
|
||||
)
|
||||
def test_busy_command_changes_nothing(
|
||||
argv: list[str],
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
@@ -1337,7 +1378,7 @@ def test_busy_command_changes_nothing(
|
||||
|
||||
monkeypatch.setattr(rotation.Stand, "lock", busy)
|
||||
monkeypatch.setattr(rotation.signal, "signal", lambda *_args: None)
|
||||
for name in ("cmd_leaf", "cmd_secret"):
|
||||
for name in ("cmd_leaf", "cmd_secret", "cmd_renew", "cmd_revoke"):
|
||||
monkeypatch.setattr(
|
||||
rotation,
|
||||
name,
|
||||
|
||||
Reference in New Issue
Block a user