#!/usr/bin/env python3 """Rotate the allowlisted LB client leaf and roll the CRL across both API proxies.""" import fcntl import hashlib import os import subprocess import time from pki import ROOT, STATE, issue, openssl, crl CONFIG = "/usr/local/etc/haproxy/haproxy.cfg" def compose(*args, capture=False): return subprocess.run([str(ROOT / "scripts/compose.sh"), *args], check=True, timeout=45, capture_output=capture).stdout def reload(service): host_file = STATE / ("lb/client.pem" if service == "lb" else "trust/ca.crl") mounted_file = "/run/identity/client.pem" if service == "lb" else "/run/trust/ca.crl" expected = hashlib.sha256(host_file.read_bytes()).hexdigest().encode() for _ in range(25): try: actual = compose("exec", "-T", service, "sha256sum", mounted_file, capture=True).split()[0] if expected == actual: compose("exec", "-T", service, "haproxy", "-c", "-f", CONFIG, capture=True) break except subprocess.CalledProcessError: pass time.sleep(0.2) else: raise RuntimeError("HAProxy cannot read or validate the newly mounted TLS file") before = compose("exec", "-T", service, "cat", "/proc/1/task/1/children", capture=True).split() compose("exec", "-T", service, "sh", "-ec", 'tr "\\000" " "