Files
mtusi2026lab7/scripts/check-layout.py
T
2026-11-22 20:57:19 +03:00

21 lines
863 B
Python

"""Check generated identities and explicit trust boundaries without a running stack."""
from pathlib import Path
import subprocess
root=Path(__file__).resolve().parents[1]
ca=root/'.local/ca.crt'
def verify(role,host,allowed=True):
cert=root/'.local/id'/role/'cert.pem'
p=subprocess.run(['openssl','verify','-CAfile',str(ca),'-verify_hostname',host,str(cert)],capture_output=True)
if (p.returncode==0)!=allowed:
raise SystemExit(f'Unexpected certificate result for {role} / {host}')
for d in sorted((root/'.local/id').iterdir()):
if d.name!='foreign':
verify(d.name,d.name)
verify('lb','localhost')
verify('openbao','localhost')
verify('grafana','localhost')
verify('lb','wrong.invalid',False)
verify('foreign','lb',False)
print('PASS: generated service SANs, local ingress/admin hostnames, foreign issuer and hostname mismatch')