34 lines
1.5 KiB
Python
34 lines
1.5 KiB
Python
"""Offline tests of admission safeguards and OpenBao contracts; no Docker needed."""
|
|
import ast
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
from cryptography import x509
|
|
|
|
BASE=Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0,str(BASE))
|
|
|
|
def main():
|
|
from app.secrets import ALLOWED
|
|
assert ALLOWED['api'] != ALLOWED['worker']
|
|
assert 'BROKER_PASSWORD' in ALLOWED['worker'] and 'BROKER_PASSWORD' in ALLOWED['dispatcher']
|
|
assert 'ROOT_TOKEN' not in str(ALLOWED)
|
|
for role in ALLOWED:
|
|
p=(BASE/'infra/openbao/policies'/f'{role}.hcl').read_text()
|
|
assert f'kv/data/{role}' in p and 'capabilities = ["read"]' in p
|
|
assert all(f'kv/data/{other}' not in p for other in ALLOWED if other!=role)
|
|
for name in ('ingress','api1','api2','broker','otel','metrics'):
|
|
cfg=(BASE/'infra/tls'/ (name+'.cfg')).read_text()
|
|
assert 'ssl' in cfg and 'crt ' in cfg
|
|
for name in ('api1','api2','broker','otel'):
|
|
cfg=(BASE/'infra/tls'/(name+'.cfg')).read_text()
|
|
assert 'verify required' in cfg
|
|
assert 'ssl_c_san' in cfg
|
|
pki=BASE/'.local/pki'
|
|
if (pki/'ca.crt').exists():
|
|
c=x509.load_pem_x509_certificate((pki/'ingress.crt').read_bytes())
|
|
san=c.extensions.get_extension_for_class(x509.SubjectAlternativeName).value
|
|
assert 'localhost' in san.get_values_for_type(x509.DNSName)
|
|
print('PASS: scoped OpenBao policies, mTLS identity ACLs, public SAN configuration')
|
|
if __name__=='__main__': main()
|