Secure messenger with TLS identities, scoped OpenBao secrets and worker compromise experiments
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Operator rotation/revocation, no image rebuild. Values stay in ignored files."""
|
||||
import argparse,importlib.util,json,os,secrets,subprocess,time
|
||||
from pathlib import Path
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
def load(name):
|
||||
spec=importlib.util.spec_from_file_location(name,ROOT/'scripts'/f'{name}.py');m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m);return m
|
||||
op=load('bao_operator');boot=load('bootstrap')
|
||||
def serial(role):
|
||||
out=subprocess.check_output(['openssl','x509','-in',str(ROOT/'certs/private'/role/'cert.crt'),'-noout','-serial'],text=True)
|
||||
return out.strip().split('=',1)[1].lower().lstrip('0') or '0'
|
||||
def revoke(role):
|
||||
p=ROOT/'infra/tls/revoked.json';values=json.loads(p.read_text());values.append(serial(role));p.write_text(json.dumps(sorted(set(values)))+'\n')
|
||||
def rotate(role,certificate=True):
|
||||
c=json.loads((op.OP/'credentials.json').read_text());root=json.loads((op.OP/'init.json').read_text())['root_token']
|
||||
if certificate:revoke(role);boot.issue(role,force=True)
|
||||
c[role]['db_password']=secrets.token_hex(24)
|
||||
(op.OP/'credentials.json').write_text(json.dumps(c));os.chmod(op.OP/'credentials.json',0o600)
|
||||
# New connections reject old passwords; terminate existing sessions explicitly.
|
||||
op.sql("ALTER ROLE messenger_"+role+" PASSWORD '"+c[role]['db_password']+"'; SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE usename='messenger_"+role+"' AND pid<>pg_backend_pid();")
|
||||
op.configure(root,c)
|
||||
print('Rotated '+role+' SQL secret'+(' and leaf certificate; previous serial denied' if certificate else '')+'; images unchanged; private values hidden.')
|
||||
def main():
|
||||
p=argparse.ArgumentParser();p.add_argument('action',choices=['revoke','rotate','secret']);p.add_argument('role',choices=['api','worker','dispatcher','housekeeping']);args=p.parse_args()
|
||||
if args.action=='revoke':
|
||||
revoke(args.role);root=json.loads((op.OP/'init.json').read_text())['root_token'];op.request('DELETE','auth/cert/certs/'+args.role,token=root);print('Revoked service serial and OpenBao certificate authentication.')
|
||||
else:rotate(args.role,args.action=='rotate')
|
||||
if __name__=='__main__':main()
|
||||
Reference in New Issue
Block a user