litellm/tests/claude_code
Cursor Agent 5ad351bbd2
fix(cron_vm): veria — isolate $HOME and hide credential dotdirs from claude
The cron systemd unit's `ProtectHome=read-only` blocks writes to
/home/mateo but still allows reads. With `HOME=/home/mateo` forwarded
to the `claude` subprocess, a compromised @anthropic-ai/claude-code
release (running during the `claude --version` probe) — or a
model-directed `Read` tool call during a PDF cell (which passes
`--allowed-tools Read`) — could read host credential files like
~/.config/gh/hosts.yml (gh-host token), ~/.ssh/, or ~/.bash_history
and exfiltrate them.

Two complementary mitigations, addressing veria's exact recommendation:

1. Per-invocation isolated HOME for every `claude` subprocess:
   * cli_driver.py: drop HOME from _CLI_ENV_ALLOWLIST; create a
     fresh empty tmpdir under tempfile.gettempdir() (`PrivateTmp=true`
     keeps it on a service-private tmpfs) and pass it as HOME to
     each `claude` invocation. Cleaned up in a `finally` so
     timeouts and CLI-not-found don't leak tmpdirs.
   * run_daily.sh: the up-front `claude --version` probe also runs
     under $CLAUDE_PROBE_HOME (a per-run dir under ${WORKDIR}) so
     the probe can never reach the runtime user's real home; the
     existing `cleanup` trap removes ${WORKDIR}.
   * Closes the `os.path.expanduser('~/.config/gh/hosts.yml')`-style
     attack from a compromised CLI / model.

2. Filesystem-level hiding of credential dotdirs in the systemd unit:
   * Add `InaccessiblePaths=-/home/mateo/.config/gh -/home/mateo/.ssh
     -/home/mateo/.aws -/home/mateo/.docker -/home/mateo/.kube
     -/home/mateo/.gnupg`. The kernel hides these paths from every
     process in the unit's mount namespace, defeating the absolute-path
     attack (`Read('/home/mateo/.config/gh/...')`) that the per-
     invocation HOME override alone cannot block.
   * Drop `/home/mateo/.config/gh` from `ReadWritePaths=` (it's
     now hidden, and we pass GH_TOKEN inline to every `gh` call).
   * Pass GH_TOKEN inline to `gh repo clone` in run_daily.sh
     (was relying on host gh-cli config); the docs repo is public
     so this is a no-op functionally, but it lets us drop the
     ~/.config/gh dependency entirely.

Tests:
  * test_run_claude_uses_isolated_per_invocation_home: pin that the
    CLI subprocess never sees the parent's $HOME, and that the
    isolated HOME is a fresh tmpdir prefixed claude-cli-home-.
  * test_run_claude_isolated_home_is_distinct_per_invocation: pin that
    each call gets its own dir (no cross-call planting).
  * test_run_claude_isolated_home_cleaned_up_after_run / on_subprocess
    _failure: pin that the tmpdir is rm-rf'd on both the happy path
    and the timeout/CLI-error path.
  * test_version_probe_uses_isolated_home_not_runtime_user_home: pin
    that run_daily.sh's probe forwards $CLAUDE_PROBE_HOME, not
    ${HOME}, into its `env -i` block.
  * test_systemd_unit_credential_isolation.py (new): pin that
    InaccessiblePaths covers all credential dotdirs, that
    .config/gh is not under ReadWritePaths, and that ProtectHome
    stays at least read-only.

All 349 existing claude_code unit tests still pass.

Co-authored-by: Mateo Wang <mateo-berri@users.noreply.github.com>
2026-05-19 05:49:18 +00:00
..
_builder_unit_tests fix(matrix-builder): greptile — surface pass over not_applicable when mixed 2026-05-19 03:01:19 +00:00
_driver_unit_tests fix(cron_vm): veria — isolate $HOME and hide credential dotdirs from claude 2026-05-19 05:49:18 +00:00
_pr_gate_unit_tests fix(ci): veria — shell-quote PR-gate resolver output written to $BASH_ENV 2026-05-19 03:07:04 +00:00
_publisher_unit_tests fix(cron_vm): veria — isolate $HOME and hide credential dotdirs from claude 2026-05-19 05:49:18 +00:00
basic_messaging_non_streaming fix(claude_code): harden parallel runner + de-dup basic_messaging cells 2026-05-17 06:35:15 +00:00
basic_messaging_streaming fix(claude_code): verify streaming wire in basic_messaging_streaming cells 2026-05-17 22:47:47 +00:00
count_tokens feat(claude_code): rename thinking row + add 4 feature rows (15 total) 2026-05-16 20:37:01 +00:00
cron_vm fix(cron_vm): veria — isolate $HOME and hide credential dotdirs from claude 2026-05-19 05:49:18 +00:00
long_context_1m feat(claude_code): rename thinking row + add 4 feature rows (15 total) 2026-05-16 20:37:01 +00:00
pdf_input compat-matrix: parallel-fanout refactor + 5 new feature dirs + rate limiter 2026-05-06 23:31:19 +00:00
prompt_caching_1h compat-matrix: parallel-fanout refactor + 5 new feature dirs + rate limiter 2026-05-06 23:31:19 +00:00
prompt_caching_5m compat-matrix: parallel-fanout refactor + 5 new feature dirs + rate limiter 2026-05-06 23:31:19 +00:00
structured_outputs feat(claude_code): rename thinking row + add 4 feature rows (15 total) 2026-05-16 20:37:01 +00:00
thinking feat(claude_code): rename thinking row + add 4 feature rows (15 total) 2026-05-16 20:37:01 +00:00
thinking_with_tool_use fix(ci): scrub pytest env + narrow Bash tool-use to exact echo pong 2026-05-18 00:25:43 +00:00
tool_search feat(claude_code): rename thinking row + add 4 feature rows (15 total) 2026-05-16 20:37:01 +00:00
tool_use fix(ci): scrub pytest env + narrow Bash tool-use to exact echo pong 2026-05-18 00:25:43 +00:00
tool_use_streaming fix(ci): scrub pytest env + narrow Bash tool-use to exact echo pong 2026-05-18 00:25:43 +00:00
vision compat-matrix: fix vision, extended_thinking, web_search test bugs 2026-05-07 02:16:10 +00:00
web_search compat-matrix: fix vision, extended_thinking, web_search test bugs 2026-05-07 02:16:10 +00:00
__init__.py RALPH: tracer-bullet for Claude Code compatibility matrix (#26477, PRD #26476) 2026-05-06 23:27:05 +00:00
_basic_messaging.py fix(claude_code): verify streaming wire in basic_messaging_streaming cells 2026-05-17 22:47:47 +00:00
cli_driver.py fix(cron_vm): veria — isolate $HOME and hide credential dotdirs from claude 2026-05-19 05:49:18 +00:00
conftest.py fix: clear manifest cache between sessions and align PR gate pytest with cron 2026-05-17 07:04:49 +00:00
http_probe.py fix(claude_code): rate-limit HTTP probe rows alongside CLI rows 2026-05-17 01:40:23 +00:00
manifest.yaml feat(claude_code): rename thinking row + add 4 feature rows (15 total) 2026-05-16 20:37:01 +00:00
matrix_builder.py fix(matrix-builder): greptile — surface pass over not_applicable when mixed 2026-05-19 03:01:19 +00:00
pr_gate_version_resolver.py fix(pr-gate): greptile — exclude npm pre-release tags from version resolver 2026-05-19 01:58:23 +00:00
rate_limiter.py compat-matrix: parallel-fanout refactor + 5 new feature dirs + rate limiter 2026-05-06 23:31:19 +00:00
run_compat.sh feat(claude_code): rename thinking row + add 4 feature rows (15 total) 2026-05-16 20:37:01 +00:00
sample_compatibility-matrix.json feat(claude_code): rename thinking row + add 4 feature rows (15 total) 2026-05-16 20:37:01 +00:00
test_config.yaml compat-matrix: parallel-fanout refactor + 5 new feature dirs + rate limiter 2026-05-06 23:31:19 +00:00