"""Revoking KV permission must stop cached API despite renew-self permission.""" import ssl,sys,time,urllib.request from pathlib import Path ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'scripts')) import bao ctx=ssl.create_default_context(cafile=str(ROOT/'secrets/ca/ca.crt')) def ready(): try: with urllib.request.urlopen('https://localhost:8443/health/ready',context=ctx,timeout=2) as r:return r.status==200 except OSError:return False assert ready(),'start with healthy APIs' started=time.monotonic() try: bao.call('sys/policies/acl/api',{'policy':'path "auth/token/renew-self" { capabilities=["update"] }'},bao.root_token(),method='PUT') while ready() and time.monotonic()-started<12:time.sleep(.5) assert not ready(),'API kept running after KV read permission revoked' elapsed=round(time.monotonic()-started,2) finally: bao.call('sys/policies/acl/api',{'policy':(ROOT/'infra/openbao/policies/api.hcl').read_text()},bao.root_token(),method='PUT') for _ in range(40): if ready():break time.sleep(1) else:raise AssertionError('API did not recover after policy restored') import json (ROOT/'evidence/policy-revocation.json').write_text(json.dumps({'kv_policy_revoked_api_stopped_seconds':elapsed,'renew_self_did_not_extend_cache':True,'recovered_after_policy_restore':True},indent=2)+'\n') print('PASS: KV policy denial stops cached APIs and restore recovers')