text stringlengths 0 252 |
|---|
forbidden_paths: Sequence[Path], |
evidence_path: Path, |
) -> None: |
identity = _runtime_identity() |
evidence_path.parent.mkdir(parents=True, exist_ok=True) |
if identity is None: |
evidence_path.write_text( |
json.dumps({"status": "skipped-outside-container"}, indent=2) + "\n", |
encoding="utf-8", |
) |
return |
expected_paths = [str(path) for path in forbidden_paths] |
expected_egress = [f"{host}:{port}" for host, port in EGRESS_PROBE_TARGETS] |
probe_fd, probe_name = tempfile.mkstemp( |
prefix=".frontierphysics-read-probe-", |
dir="/tmp", |
) |
os.close(probe_fd) |
probe_source = Path(probe_name) |
probe_source.write_text( |
"import json, os, pathlib, socket, sys\n" |
"request = json.loads(pathlib.Path(sys.argv[1]).read_text())\n" |
"paths = request['paths']\n" |
"targets = request['egress']\n" |
"path_results = {}\n" |
"for value in paths:\n" |
" try:\n" |
" path = pathlib.Path(value)\n" |
" if path.is_dir():\n" |
" list(path.iterdir())\n" |
" else:\n" |
" with path.open('rb') as stream:\n" |
" stream.read(1)\n" |
" except Exception as error:\n" |
" path_results[value] = {'readable': False, 'error': type(error).__name__}\n" |
" else:\n" |
" path_results[value] = {'readable': True, 'error': None}\n" |
"egress_results = {}\n" |
"for host, port in targets:\n" |
" key = f'{host}:{port}'\n" |
" connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n" |
" connection.settimeout(2.0)\n" |
" try:\n" |
" connection.connect((host, int(port)))\n" |
" except OSError as error:\n" |
" egress_results[key] = {\n" |
" 'connected': False,\n" |
" 'error': type(error).__name__,\n" |
" 'errno': error.errno,\n" |
" }\n" |
" else:\n" |
" egress_results[key] = {\n" |
" 'connected': True,\n" |
" 'error': None,\n" |
" 'errno': None,\n" |
" }\n" |
" finally:\n" |
" connection.close()\n" |
"result = {\n" |
" 'euid': os.geteuid(),\n" |
" 'paths': path_results,\n" |
" 'egress': egress_results,\n" |
"}\n" |
"print(json.dumps(result, sort_keys=True))\n" |
"violation = any(item['readable'] for item in path_results.values())\n" |
"violation = violation or any(item['connected'] for item in egress_results.values())\n" |
"raise SystemExit(91 if violation else 0)\n", |
encoding="utf-8", |
) |
try: |
run = run_isolated_python( |
probe_source, |
{ |
"request": json.dumps( |
{ |
"paths": expected_paths, |
"egress": EGRESS_PROBE_TARGETS, |
} |
).encode(), |
}, |
["{input:request}"], |
timeout_seconds=15, |
) |
try: |
evidence = { |
"status": "failed", |
"runtime_user": identity.name, |
"uid": identity.uid, |
"returncode": run.completed.returncode, |
"stdout": run.completed.stdout, |
"stderr": run.completed.stderr, |
} |
failure: str | None = None |
try: |
results = json.loads(run.completed.stdout) |
except json.JSONDecodeError as error: |
results = None |
failure = f"invalid JSON stdout: {error}" |
else: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.