forked from mtusi2026/mtusi2026lab4
feat: add 4 grade things
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def command(args):
|
||||
return subprocess.check_output(args, cwd=ROOT, text=True).strip()
|
||||
|
||||
|
||||
def main():
|
||||
evidence = []
|
||||
for service in ("s3", "api", "upload-cleanup"):
|
||||
ids = command(["docker", "compose", "ps", "-q", service]).splitlines()
|
||||
assert ids, "service is not running: " + service
|
||||
for cid in ids:
|
||||
info = json.loads(command(["docker", "inspect", cid]))[0]
|
||||
sources = [
|
||||
Path(mount["Source"]).name
|
||||
for mount in info["Mounts"]
|
||||
if mount["Type"] == "bind"
|
||||
]
|
||||
if service == "s3":
|
||||
assert not info["HostConfig"]["PortBindings"], "S3 ports are published"
|
||||
assert "MINIO_BROWSER=off" in info["Config"]["Env"], (
|
||||
"MinIO console is enabled"
|
||||
)
|
||||
assert set(info["NetworkSettings"]["Networks"]) == {
|
||||
"highload-lab4_data"
|
||||
}
|
||||
else:
|
||||
assert (
|
||||
"s3_access_key_id" not in sources
|
||||
and "s3_secret_access_key" not in sources
|
||||
), "root credentials mounted into " + service
|
||||
assert (
|
||||
"s3_api_access_key_id" in sources
|
||||
and "s3_api_secret_access_key" in sources
|
||||
)
|
||||
if service == "api":
|
||||
assert (
|
||||
info["HostConfig"]["Tmpfs"]["/tmp/uploads"].find("size=16m") >= 0
|
||||
), "upload tmpfs limit missing"
|
||||
assert info["HostConfig"]["Memory"] == 512 * 1048576
|
||||
evidence.append(
|
||||
{
|
||||
"service": service,
|
||||
"container": info["Config"]["Hostname"],
|
||||
"bind_filenames": sources,
|
||||
"published_ports": info["HostConfig"]["PortBindings"],
|
||||
"tmpfs": info["HostConfig"].get("Tmpfs", {}),
|
||||
}
|
||||
)
|
||||
directory = ROOT / ".memory/s3-permissions"
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
(directory / "isolation.json").write_text(json.dumps(evidence, indent=2) + "\n")
|
||||
print(
|
||||
"PASS: private S3 network, disabled console, restricted API mounts, bounded tmpfs"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user