forked from mtusi2026/mtusi2026lab7
Лабораторная 7
This commit is contained in:
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Operator rollover: issue leaf, revoke old serial, replace Bao binding, restart
|
||||
only the affected service (and LB reload), with no image build. Old key retained
|
||||
operator-side solely for the explicit negative verification, never mounted in app.
|
||||
"""
|
||||
import os,shutil,subprocess,sys
|
||||
from pathlib import Path
|
||||
ROOT=Path(__file__).resolve().parents[1];os.chdir(ROOT)
|
||||
role=sys.argv[1] if len(sys.argv)>1 else ''
|
||||
if role not in ['lb','api1','api2','worker','dispatcher','cleanup']:raise SystemExit('choose lb/api1/api2/worker/dispatcher/cleanup')
|
||||
def command(*args):subprocess.run(args,check=True,stdout=subprocess.DEVNULL)
|
||||
d=Path('secrets/tls')/role;old=Path('secrets/operator/previous-leaf')/role;old.mkdir(parents=True,exist_ok=True)
|
||||
for name in ['cert.crt','key.key']:
|
||||
if (old/name).exists():(old/name).chmod(0o600)
|
||||
shutil.copy2(d/name,old/name)
|
||||
serial=subprocess.check_output(['openssl','x509','-in',str(old/'cert.crt'),'-serial','-noout'],text=True).strip().split('=')[1].lower().lstrip('0')
|
||||
command('python3','scripts/pki.py','--rotate',role)
|
||||
p=Path('secrets/public/revoked-serials');p.chmod(0o600)
|
||||
with p.open('a') as f:f.write(serial+'\n')
|
||||
p.chmod(0o444)
|
||||
if role!='lb':command('python3','scripts/bao-operator.py','configure')
|
||||
service='nginx' if role=='lb' else role
|
||||
command('docker','compose','--env-file','.env','restart',service)
|
||||
print('Leaf rotated; old serial denied on new connections; images unchanged.')
|
||||
Reference in New Issue
Block a user