forked from mtusi2026/mtusi2026lab7
feat: complete lab 7 grade 4 security controls and report
This commit is contained in:
@@ -4,6 +4,7 @@ import json
|
||||
import subprocess
|
||||
|
||||
APP_ROLES = {"api", "worker", "dispatcher", "upload-cleanup"}
|
||||
READ_ONLY = APP_ROLES | {"haproxy", "otel-collector", "prometheus", "loki", "tempo", "grafana"}
|
||||
ALLOWED_PORTS = {("haproxy", "8443/tcp"), ("grafana", "3000/tcp"),
|
||||
("openbao", "8200/tcp"), ("s3", "9000/tcp")}
|
||||
|
||||
@@ -21,6 +22,15 @@ def main():
|
||||
for port, bindings in (config.get("PortBindings") or {}).items():
|
||||
assert (name, port) in ALLOWED_PORTS, (name, port)
|
||||
assert all(binding["HostIp"] == "127.0.0.1" for binding in bindings), name
|
||||
if name in READ_ONLY:
|
||||
assert config["ReadonlyRootfs"] and config["CapDrop"] == ["ALL"], name
|
||||
assert "no-new-privileges:true" in config["SecurityOpt"], name
|
||||
assert config["Memory"] > 0 and config["NanoCpus"] > 0, name
|
||||
assert config["Tmpfs"], name
|
||||
if name == "worker":
|
||||
env = dict(item.split("=", 1) for item in service["Config"]["Env"] if "=" in item)
|
||||
assert 0 < int(env["JOB_TIMEOUT_SECONDS"]) <= 60, name
|
||||
assert config["Memory"] <= 512 * 1024 * 1024 and config["NanoCpus"] <= 10**9, name
|
||||
if name in APP_ROLES:
|
||||
assert service["Config"]["User"] == "app:app", name
|
||||
assert config["CapDrop"] == ["ALL"] and not config["CapAdd"], name
|
||||
@@ -29,7 +39,7 @@ def main():
|
||||
assert not any(path.startswith("/run/secrets") for path in mounts), name
|
||||
assert not any("BAO_TOKEN=" in field for field in service["Config"]["Env"]), name
|
||||
assert APP_ROLES <= {svc["Config"]["Labels"]["com.docker.compose.service"] for svc in services}
|
||||
print("PASS: local-only ports, runtime secrets on tmpfs, non-root app roles with limits and dropped capabilities")
|
||||
print("PASS: local ports, read-only app/ingress/telemetry, no-new-privileges, dropped capabilities, worker CPU/RAM/time budget")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user