ЛР 7: реализация мессенджера и сценарии проверки

This commit is contained in:
Russiankryt
2026-12-03 17:20:53 +03:00
parent 20afc2c790
commit 3dd0587e7d
57 changed files with 3470 additions and 55 deletions
+37
View File
@@ -0,0 +1,37 @@
"""Rotate the worker's S3 password and reconfigure scoped OpenBao KV."""
import ssl
import subprocess
from secrets import token_hex
from bao_operator import ROOT, SECRETS, STATE, install
from pki import CA_CERT, publish
import json
def update_s3():
subprocess.run(["docker", "compose", "run", "--rm", "--no-deps", "s3-init"],
cwd=ROOT, check=True, timeout=75, capture_output=True)
def main():
path = SECRETS / "worker_s3_secret"
old = path.read_bytes()
new = (token_hex(24) + "\n").encode("ascii")
state = json.loads(STATE.read_text(encoding="utf-8"))
context = ssl.create_default_context(cafile=CA_CERT)
try:
publish(path, new)
update_s3()
install(context, state, ("worker",))
except Exception:
publish(path, old)
update_s3()
install(context, state, ("worker",))
raise SystemExit("Rotation failed. Previous credential restored.") from None
print("Worker password changed. The running worker reloads after its next OpenBao refresh.")
if __name__ == "__main__":
main()