Files

44 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Repeat bootstrap with an existing API object, then check least-privilege S3 access."""
import argparse
import json
from pathlib import Path
import subprocess
import sys
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'tests'))
from client import Client, check, run
def compose(*args):
return subprocess.check_output(['docker','compose','--env-file','.env',*args],cwd=ROOT,
stderr=subprocess.STDOUT,text=True)
def main():
p=argparse.ArgumentParser()
p.add_argument('--base-url',default='http://localhost:18084')
args=p.parse_args()
c=Client(args.base_url,timeout=30)
alice,bob,eve,chat=c.bootstrap()
attachment,original=c.attachment(alice,chat)
for _ in range(2):
compose('run','--rm','--no-deps','s3-init')
downloaded=c.call('GET','/api/v1/attachments/'+attachment['id']+'/content',actor=bob)
check(downloaded['bytes']==original,'bootstrap changed an existing object or API credentials')
print('PASS: two bootstrap runs preserve an existing API attachment and credentials.')
config=json.loads(compose('config','--format','json'))
check(not config['services']['s3'].get('ports'),'S3 ports are published')
check(config['services']['s3']['environment']['MINIO_BROWSER']=='off','admin console is enabled')
keys={x['source'] for x in config['services']['api']['secrets']}
check(not keys.intersection({'s3_root_user','s3_root_password'}),'API has root credentials')
print('PASS: S3 has no published ports or browser console; API has no root credentials.')
output=compose('run','--rm','--no-deps','s3-check')
for line in output.splitlines():
if line.startswith('PASS:'): print(line)
if __name__=='__main__':
run(main)