Reversible clean-root candidate rebuilt from oak/benchmarks main@009dead264ca; original repository retained.

Commit bc79bb5d

bc79bb5d3dadMergedon mrmrs-a60a8c

mrmrs · 13 days ago · 4 files · +1 added · ~3 modified

Details

Commit
bc79bb5d3dad
Parent
094f0e0f5a0e

cloudflare/agent-runner/server.pymodifiedView file

@@ -8,8 +8,10 @@
88
99 Steps: write the manifest (container config paths, isolation attestation),
1010 `agent_campaign.py plan`, containment self-check as the agent user, `run`,
11-`report`. Secrets are passed to the harness environment only; they are never
12-written to disk or echoed in status.
11+`report`. Secrets are passed to the harness environment only. The agent holds
12+the key and could print it, so every file is scrubbed of each secret value
13+before the bundle is packaged, and status output is scrubbed too
14+(redaction.json records counts, never values).
1315 """
1416 from __future__ import annotations
1517
@@ -117,6 +119,7 @@
117119 manifest["isolation_attestation"] = {"worker_root": str(WORK), "unrestricted_cli_acknowledged": True}
118120 (job_dir / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n")
119121 secrets = {k: v for k, v in (request.get("secrets") or {}).items() if k in SECRET_KEYS and isinstance(v, str)}
122+ job["redact"] = {k: v for k, v in secrets.items() if len(v) >= 8}
120123 env = harness_env(job_dir, secrets)
121124 campaign = job_dir / "campaign"
122125 script = str(BENCH / "scripts" / "agent_campaign.py")
@@ -146,11 +149,36 @@
146149 job["step"] = None
147150
148151
152+def scrub_text(job: dict, text: str) -> str:
153+ for name, value in job.get("redact", {}).items():
154+ text = text.replace(value, f"[REDACTED:{name}]")
155+ return text
156+
157+
158+def scrub_tree(job: dict) -> dict:
159+ """Replace every secret value in every file under the job dir. Returns counts."""
160+ counts = {name: 0 for name in job.get("redact", {})}
161+ needles = {name: value.encode() for name, value in job.get("redact", {}).items()}
162+ for path in job["dir"].rglob("*"):
163+ if not path.is_file() or path.is_symlink():
164+ continue
165+ data = path.read_bytes()
166+ changed = data
167+ for name, needle in needles.items():
168+ hits = changed.count(needle)
169+ if hits:
170+ counts[name] += hits
171+ changed = changed.replace(needle, f"[REDACTED:{name}]".encode())
172+ if changed is not data:
173+ path.write_bytes(changed)
174+ return counts
175+
176+
149177 def log_tail(job: dict, lines: int = 30) -> list[str]:
150178 logs = sorted((job["dir"] / "logs").glob("*.log"), key=lambda p: p.stat().st_mtime) if (job["dir"] / "logs").exists() else []
151179 if not logs:
152180 return []
153- return logs[-1].read_text(errors="replace").splitlines()[-lines:]
181+ return scrub_text(job, logs[-1].read_text(errors="replace")).splitlines()[-lines:]
154182
155183
156184 class Handler(BaseHTTPRequestHandler):
@@ -197,13 +225,16 @@
197225 return self.send_json(404, {"error": "unknown job"})
198226 if not suffix:
199227 return self.send_json(200, {"job_id": job_id, "state": job["state"], "step": job["step"],
200- "exit_codes": job["exit_codes"], "error": job["error"],
228+ "exit_codes": job["exit_codes"], "error": scrub_text(job, job["error"] or "") or None,
201229 "egress_policy": job.get("egress_policy"),
202230 "runner_image": RUNNER_IMAGE_VERSION, "log_tail": log_tail(job)})
203231 if job["state"] == "running":
204232 return self.send_json(409, {"error": "job still running"})
205233 archive = WORK / f"{job_id}.tar.gz"
206234 if not archive.exists():
235+ counts = scrub_tree(job)
236+ (job["dir"] / "redaction.json").write_text(json.dumps(
237+ {"scrubbed_secret_names": sorted(counts), "occurrences_replaced": counts}, indent=2) + "\n")
207238 with tarfile.open(archive, "w:gz") as tar:
208239 tar.add(job["dir"], arcname=job_id,
209240 filter=lambda info: None if "/harness-home" in info.name else info)