Files
mtusi2026lab4/tests_student/private_bucket.py
T

39 lines
1.6 KiB
Python

"""Anonymous S3 access is denied, and the console/API ports are not published."""
import json
import subprocess
import sys
def run(args):
return subprocess.check_output(args, text=True)
def main() -> None:
report = json.loads(run(["docker", "exec", "mtusi-api-1", "python", "-m", "app.admin", "check-private"]))
if not report.get("private"):
raise SystemExit("anonymous S3 access was not denied: " + json.dumps(report))
ports = json.loads(run(["docker", "inspect", "mtusi-minio", "--format", "{{json .NetworkSettings.Ports}}"]))
published = []
for bindings in (ports or {}).values():
if bindings:
published.extend(bindings)
if published:
raise SystemExit("MinIO published a host port, including the console if 9001 is mapped")
mounts = json.loads(run(["docker", "inspect", "mtusi-api-1", "--format", "{{json .Mounts}}"]))
if mounts:
raise SystemExit("API replica has a volume; originals must not live on the API filesystem")
env = run(["docker", "exec", "mtusi-api-1", "python", "-c", "import os; print('MINIO_ROOT_USER' in os.environ)"])
if env.strip() != "False":
raise SystemExit("API process can see the MinIO root user")
print(json.dumps({"private_bucket": report, "minio_published_ports": published, "api_mounts": mounts}, ensure_ascii=False))
print("PASS: private bucket, no published MinIO ports, API has no volume and no root credentials")
if __name__ == "__main__":
try:
main()
except Exception as exc:
print("FAIL:", exc)
raise SystemExit(1)