67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Host-side private-bucket checks plus the in-network probe.
|
|
|
|
Confirms MinIO publishes no host ports, the console env is off, then runs the
|
|
compose service that performs an unauthenticated GET from the data network.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def _compose(args):
|
|
env_file = ROOT / '.env'
|
|
cmd = ['docker', 'compose']
|
|
if env_file.is_file():
|
|
cmd.extend(['--env-file', str(env_file)])
|
|
cmd.extend(args)
|
|
return subprocess.run(cmd, cwd=str(ROOT), check=True, capture_output=True, text=True)
|
|
|
|
|
|
def main() -> None:
|
|
os.chdir(ROOT)
|
|
result = _compose(['config', '--format', 'json'])
|
|
config = json.loads(result.stdout)
|
|
services = config.get('services') or {}
|
|
minio = services.get('minio')
|
|
if minio is None:
|
|
raise SystemExit('FAIL: compose config has no minio service')
|
|
ports = minio.get('ports') or []
|
|
if ports:
|
|
raise SystemExit('FAIL: minio publishes host ports: %s' % ports)
|
|
env = minio.get('environment') or {}
|
|
browser = str(env.get('MINIO_BROWSER', '')).strip().strip('"').lower()
|
|
if browser not in ('off', 'false', '0'):
|
|
raise SystemExit('FAIL: MINIO_BROWSER is %r, expected off' % env.get('MINIO_BROWSER'))
|
|
networks = (minio.get('networks') or {})
|
|
if 'edge' in networks:
|
|
raise SystemExit('FAIL: minio is attached to the edge network')
|
|
probe = subprocess.run(
|
|
[
|
|
'docker', 'compose',
|
|
*(['--env-file', str(ROOT / '.env')] if (ROOT / '.env').is_file() else []),
|
|
'--profile', 'ops',
|
|
'run', '--rm', 'check-private-bucket',
|
|
],
|
|
cwd=str(ROOT),
|
|
check=False,
|
|
text=True,
|
|
)
|
|
if probe.returncode != 0:
|
|
raise SystemExit(probe.returncode)
|
|
print('PASS: minio has no host ports, console env is off, in-network GET is 403')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
main()
|
|
except subprocess.CalledProcessError as exc:
|
|
sys.stderr.write(exc.stderr or exc.stdout or str(exc))
|
|
raise SystemExit(exc.returncode)
|