"""Проверка старого и нового сертификатов на обоих входах.""" import importlib.util import os import sys import tempfile from pathlib import Path root = Path(__file__).resolve().parents[1] sys.path.insert(0, str(root / "scripts")) spec = importlib.util.spec_from_file_location("rotate_leaf", root / "scripts/rotate-leaf.py") rotation = importlib.util.module_from_spec(spec) spec.loader.exec_module(rotation) os.umask(0o077) if rotation.pending.exists(): raise SystemExit("Завершите прерванную ротацию через scripts/rotate-leaf.py.") def expect(pair, endpoint, allowed): status = rotation.probe(pair, endpoint) if status not in allowed: raise SystemExit(f"{endpoint}: неожиданный HTTP {status}") print(f"{endpoint}: HTTP {status}", flush=True) with tempfile.TemporaryDirectory(dir="/tmp") as directory: old = Path(directory) / "old.crt", Path(directory) / "old.key" current = rotation.cert, rotation.key for source, dest in zip(current, old): dest.write_bytes(source.read_bytes()) for endpoint in ("bao", "otel"): expect(old, endpoint, {"200"}) rotation.main() for endpoint in ("bao", "otel"): expect(current, endpoint, {"200"}) expect(old, "bao", {"400", "403"}) expect(old, "otel", {"403"}) rotation.compose("exec", "-T", "worker", "sh", "-c", """curl -fsS --max-time 10 --cacert /tls/ca.crt --cert /tls/client.crt --key /tls/client.key -H 'Content-Type: application/json' -d '{"resourceSpans":[]}' https://otel-collector:4318/v1/traces >/dev/null""") print("PASS: старый сертификат отклонён, новый и действующий worker приняты.")