#!/usr/bin/env python3 """Operator leaf rotation without image rebuild; root CA remains offline from services.""" import shutil,sys from pathlib import Path sys.path.insert(0,str(Path(__file__).resolve().parent));import bootstrap,bao,security role=sys.argv[1] if len(sys.argv)>1 else 'lb' if role not in ['lb','api','dispatcher']:raise SystemExit('Use lb/api/dispatcher; worker incident response uses rotate-worker.py') s=bao.S;o=bao.O;old=s/(role+'-old') if old.exists():shutil.rmtree(old) shutil.copytree(s/role,old);old.chmod(0o755) token=bao.operator_token() bootstrap.run('openssl','ca','-config',str(o/'ca.cnf'),'-revoke',str(old/'tls.crt')) for f in ['tls.crt','tls.key']:(s/role/f).unlink() bootstrap.issue(role);bootstrap.main() for p in old.iterdir():p.chmod(0o444) if role!='lb':bao.call('auth/cert/certs/'+role,{'certificate':(s/role/'tls.crt').read_text(),'token_policies':[role],'token_ttl':300,'token_max_ttl':1800,'token_no_default_policy':True},token) security.compose('restart',role) print('Leaf replaced and old serial revoked without rebuilding the image:',role)