Allowlist with claude_cli: fail closed until hx#182; record provider mode (#18)
This commit was merged in pull request #18.
This commit is contained in:
1 parent
374cf28aed
commit
a76c0ac16f
9 files changed
+259
-14
No files matched your search
@@ -51,6 +51,36 @@ try:
|
||||
ver = subprocess.run([str(hx), "--version"], capture_output=True, text=True).stdout.strip()
|
||||
assert ver and tel[-1]["hx_version"] == ver and tel[-1]["status"] == "needs-human", (tel, ver)
|
||||
print("real hx e2e ok:", st["reason"], "| audit by:", sorted({json.loads(l)["detail"].get("by", "guard") for l in audit.splitlines() if "decision" in l}))
|
||||
# --- claude_cli mode (issue #17): the claude binary executes tools itself and hx emits no tool_call events ---
|
||||
shutil.copy(root / "tests/fake_claude.py", tmp / "claude")
|
||||
os.chmod(tmp / "claude", 0o755)
|
||||
(home / ".hx/config.toml").write_text("claude_cli = []\n") # the profile's own home turns the provider on
|
||||
cenv = '["HX_BASE_URL", "HX_CLAUDE_BIN", "FAKE_CLAUDE_READ", "FAKE_CLAUDE_LOG"]'
|
||||
(cfg / "guarded.toml").write_text(f'hx = "{hx}"\nhome = "{home}"\nenv = {cenv}\nallow = ["write"]\n')
|
||||
(cfg / "open.toml").write_text(f'hx = "{hx}"\nhome = "{home}"\nenv = {cenv}\n')
|
||||
cenv_vars = {**env, "HX_CLAUDE_BIN": str(tmp / "claude"), "FAKE_CLAUDE_READ": str(secret), "FAKE_CLAUDE_LOG": str(tmp / "argv.log")}
|
||||
|
||||
def go(profile_name, name):
|
||||
(tmp / f"{name}.md").write_text(f"# {name}\nread the secret\n")
|
||||
p = subprocess.run([orch, "run", str(tmp / f"{name}.md"), "--repo", str(repo), "--profile", profile_name],
|
||||
env=cenv_vars, capture_output=True, text=True, timeout=120)
|
||||
rid = p.stdout.split()[0]
|
||||
st = json.loads(subprocess.run([orch, "status", rid], env=env, capture_output=True, text=True).stdout)
|
||||
seen = subprocess.run(["git", "show", f"{st['branch']}:claude-read.txt"], cwd=repo, capture_output=True, text=True)
|
||||
return st, seen.stdout if seen.returncode == 0 else None, p
|
||||
|
||||
# control: without `allow` the claude binary really runs and reads the secret (proves the test is sensitive)
|
||||
st, seen, p = go("open", "ctl")
|
||||
assert seen == "PRIVATE-TOKEN-123", (seen, p.stdout, p.stderr, st)
|
||||
last = [json.loads(l) for l in (tmp / "state/telemetry.jsonl").read_text().splitlines() if l.strip()][-1]
|
||||
assert last["provider_mode"] == "claude_cli", last
|
||||
# with `allow` on today's hx (no tool events for claude's tools, hx#182): fail closed, never "guarded"
|
||||
st, seen, p = go("guarded", "gd")
|
||||
assert st["status"] == "needs-human" and "could not be enforced" in st["reason"], (st, p.stdout, p.stderr)
|
||||
last = [json.loads(l) for l in (tmp / "state/telemetry.jsonl").read_text().splitlines() if l.strip()][-1]
|
||||
assert last["provider_mode"] == "claude_cli", last
|
||||
# (the fake claude has already read the secret by then: this hx cannot stop it, which is what hx#182 is for)
|
||||
print("claude_cli mode ok: unseen tool use fails closed (hx#182 missing)")
|
||||
finally:
|
||||
srv.terminate()
|
||||
shutil.rmtree(tmp, ignore_errors=True)
|
||||
Reference in new issue
Block a user