forked from mtusi2026/mtusi2026lab7
lab7
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import os,sys,ssl,json,time,urllib.request
|
||||
ctx=ssl.create_default_context(cafile='/tls/ca.crt')
|
||||
ctx.load_cert_chain('/identity/cert.crt','/identity/cert.key')
|
||||
role=os.environ['BAO_ROLE']; base=os.environ['BAO_ADDR']
|
||||
def call(path,body=None,token=None):
|
||||
headers={'Content-Type':'application/json'}
|
||||
if token: headers['X-Vault-Token']=token
|
||||
req=urllib.request.Request(base+'/v1/'+path,data=json.dumps(body).encode() if body is not None else None,headers=headers)
|
||||
with urllib.request.urlopen(req,context=ctx,timeout=5) as r: return json.load(r)
|
||||
for i in range(120):
|
||||
try:
|
||||
token=call('auth/cert/login',{'name':role})['auth']['client_token']
|
||||
values=call('secret/data/'+role,token=token)['data']['data']; break
|
||||
except Exception:
|
||||
time.sleep(2)
|
||||
else: sys.exit('OpenBao unavailable or access denied')
|
||||
os.environ.update(values); os.execvp(sys.argv[1],sys.argv[1:])
|
||||
Reference in New Issue
Block a user