forked from mtusi2026/mtusi2026lab7
24 lines
1.5 KiB
Python
24 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Bounded short-token test: sealed Bao cannot silently refresh application credentials."""
|
|
import json,subprocess,sys,time,urllib.error
|
|
from pathlib import Path
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'scripts'));import bao,security
|
|
|
|
def main():
|
|
token=bao.operator_token();normal=bao.call('auth/cert/certs/api',token=token)['data'];short=dict(normal,token_ttl=30,token_max_ttl=30)
|
|
bao.call('auth/cert/certs/api',short,token)
|
|
security.compose('restart','api');subprocess.run([sys.executable,str(ROOT/'scripts/wait-ready.py')],check=True,stdout=subprocess.DEVNULL)
|
|
started=time.monotonic()
|
|
try:
|
|
bao.call('sys/seal',{},token)
|
|
for _ in range(55):
|
|
status,_,_=security.request('/health/ready')
|
|
if status==503:break
|
|
time.sleep(1)
|
|
else:raise AssertionError('API served beyond short grant lifetime while Bao sealed')
|
|
elapsed=time.monotonic()-started;assert elapsed<=45
|
|
finally:
|
|
bao.unseal();token=bao.operator_token();bao.call('auth/cert/certs/api',normal,token);security.compose('restart','api');subprocess.run([sys.executable,str(ROOT/'scripts/wait-ready.py')],check=True,stdout=subprocess.DEVNULL)
|
|
(ROOT/'evidence/sealed.json').write_text(json.dumps({'short_token_ttl_seconds':30,'fail_closed_seconds':elapsed,'recovered_after_operator_unseal':True,'plaintext_fallback':False},indent=2)+'\n');print('PASS: sealed OpenBao produces bounded fail-closed and recovers after operator unseal')
|
|
if __name__=='__main__':main()
|