feature(container): Add claude vertex auth forwarding with GCP credential support#954
Conversation
Seluj78
left a comment
There was a problem hiding this comment.
I mean, LGTM but I am not a rust expert :) And I cannot test
Address review feedback before merge: - Gate the env var auto-forward and GCP cred mount on CLAUDE_CODE_USE_VERTEX being set (and non-empty) on the host, so non-Vertex users see no behavior change. Empty string is treated as unset, matching how the flag is conventionally interpreted. - Drop ANTHROPIC_API_KEY from the auto-forward list. Vertex auth uses GCP credentials, and force-forwarding the API key would change behavior for users who have it set on their shell for unrelated reasons. Users who want it forwarded can add it to sandbox.environment explicitly. - Gate the GCP cred mount on tool == "claude". CLAUDE_CODE_USE_VERTEX is Claude-specific; there is no reason to expose GCP credentials to other agents (opencode, codex, etc.) just because the host happens to have the flag exported globally. - Revert the change to default_sandbox_environment(): the runtime auto-forward is now the single mechanism, matching the DEFAULT_TERMINAL_ENV_VARS precedent. Adding the keys to the user-editable list created a fake opt-out (user removes it, still forwarded) and was just noise. - Add unit tests covering the cred mount in container_config: default ADC path, custom GOOGLE_APPLICATION_CREDENTIALS, missing flag, missing ADC file, non-claude tool, empty flag string. - Document the auto-detect behavior in docs/guides/sandbox.md. Rename AUTO_FORWARD_API_ENV_VARS -> AUTO_FORWARD_VERTEX_ENV_VARS to reflect the narrower scope, and add a host_vertex_enabled() helper used by both the env collector and the cred mount. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Note: this comment was drafted by Claude via back-and-forth with @njbrake. The reasoning and decisions are his; the prose is Claude's. Hey @CharlyRipp, thanks for this. Apologies for the unilateral push, but I went ahead and added a refactor commit on top of yours ( Quick summary of what changed:
The one place I'd value your input before merging: I dropped The other four items are general cleanups I'd have asked for in any review. |
|
Perfect! Exactly things I was curious about and 💯 agree with. |
Description
Auto-forward Vertex AI and API provider environment variables into sandboxed containers, and auto-mount GCP Application Default Credentials when Vertex is enabled.
Closes #952
What changed
src/session/environment.rs: NewAUTO_FORWARD_API_ENV_VARSconstant that auto-forwardsANTHROPIC_API_KEY,ANTHROPIC_VERTEX_PROJECT_ID,ANTHROPIC_VERTEX_REGION,CLAUDE_CODE_USE_VERTEX, andCLOUD_ML_REGIONwhen set on the host. UsesEnvEntry::Inherit(key-only in argv) to keep secrets out of process listings and logs.src/session/container_config.rs: WhenCLAUDE_CODE_USE_VERTEXis set, mounts GCP credentials into the container at the well-known ADC path (/root/.config/gcloud/application_default_credentials.json). Supports bothGOOGLE_APPLICATION_CREDENTIALS(custom path) and the default ADC location.src/session/config.rs: Updateddefault_sandbox_environment()to include the new API vars so they appear in the TUI new-session env list.How I tested
cargo build --release, created a sandboxed sessionenv | grep ANTHROPIC)cargo testpasses (3 pre-existing container runtime failures unrelated to this change)cargo fmt --checkandcargo clippycleanPR Type
Checklist
AI Usage
AI Model/Tool used: Claude Code
Any Additional AI Details you'd like to share:
Used Claude for codebase discovery, identifying the right env var names from official docs, edge case review, and code review of the changes. The feature idea, testing, and final decisions are mine.