"""Qualification Dockerfile must fail if privileged material or forbidden egress is visible.""" import socket from pathlib import Path for path in ( "/clone/id", "/push/config.json", "/private/repo/.git/config", "/workspace/.git/config", "/var/run/secrets/kubernetes.io/serviceaccount/token", ): assert not Path(path).exists(), "Credential or Git metadata visible to RUN" for process in Path("/proc").iterdir(): if not process.name.isdigit(): continue for relative in ("root/clone/id", "root/push/config.json"): try: exposed = (process / relative).is_file() except OSError: exposed = False assert not exposed, "Sibling credential visible through procfs" for host in ("kubernetes.default.svc", "example.com"): try: connection = socket.create_connection((host, 443), timeout=3) except OSError: continue connection.close() raise AssertionError("Forbidden egress reachable")