lab7
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import json,ssl,urllib.request,pathlib,getpass
|
||||
ctx=ssl.create_default_context(cafile='secrets/ca.crt'); token=getpass.getpass('Operator root token: ')
|
||||
def post(path,data):
|
||||
req=urllib.request.Request('https://localhost:8200/v1/'+path,data=json.dumps(data).encode(),headers={'X-Vault-Token':token,'Content-Type':'application/json'}); urllib.request.urlopen(req,context=ctx).close()
|
||||
env=dict(x.split('=',1) for x in pathlib.Path('.env').read_text().splitlines())
|
||||
try:
|
||||
post('sys/auth/cert', {'type': 'cert'})
|
||||
post('sys/mounts/secret', {'type': 'kv', 'options': {'version': '2'}})
|
||||
except urllib.error.HTTPError as e:
|
||||
print(e.read().decode())
|
||||
raise SystemExit(1)
|
||||
for role in ('api','worker','operator'):
|
||||
post('sys/policies/acl/'+role,{'policy':pathlib.Path('infra/openbao/'+role+'.hcl').read_text()}); post('auth/cert/certs/'+role,{'certificate':pathlib.Path('secrets/'+role+'/cert.crt').read_text(),'token_policies':[role],'token_ttl':'10m','token_max_ttl':'30m'}); post('secret/data/'+role,{'data':{'DATABASE_URL':'postgresql://messenger:'+env['POSTGRES_PASSWORD']+'@postgres:5432/messenger?sslmode=verify-full&sslrootcert=/tls/ca.crt','S3_ACCESS_KEY_ID':'lab','S3_SECRET_ACCESS_KEY':env['S3_SECRET_ACCESS_KEY'],'BROKER_URL':'amqps://lab:'+env['BROKER_PASSWORD']+'@broker:5671/%2F'}})
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
subprocess.run([sys.executable, 'scripts/update_roles_bao.py'], check=True)
|
||||
Reference in New Issue
Block a user