-
Notifications
You must be signed in to change notification settings - Fork 7
fix: exclude API keys from agent when api-proxy is enabled #814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -320,6 +320,14 @@ export function generateDockerCompose( | |||||||||||||||||
| 'SUDO_GID', // Sudo metadata | ||||||||||||||||||
| ]); | ||||||||||||||||||
|
|
||||||||||||||||||
| // When api-proxy is enabled, exclude API keys from agent environment | ||||||||||||||||||
| // The keys are passed to the api-proxy sidecar only (not to the agent) | ||||||||||||||||||
| const willUseApiProxy = config.enableApiProxy && (config.openaiApiKey || config.anthropicApiKey); | ||||||||||||||||||
| if (willUseApiProxy) { | ||||||||||||||||||
| EXCLUDED_ENV_VARS.add('ANTHROPIC_API_KEY'); | ||||||||||||||||||
| EXCLUDED_ENV_VARS.add('OPENAI_API_KEY'); | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+325
to
+329
|
||||||||||||||||||
|
|
||||||||||||||||||
| // Start with required/overridden environment variables | ||||||||||||||||||
| // Use the real user's home (not /root when running with sudo) | ||||||||||||||||||
| const homeDir = getRealUserHome(); | ||||||||||||||||||
|
|
@@ -386,7 +394,11 @@ export function generateDockerCompose( | |||||||||||||||||
| if (process.env.GH_TOKEN) environment.GH_TOKEN = process.env.GH_TOKEN; | ||||||||||||||||||
| if (process.env.GITHUB_PERSONAL_ACCESS_TOKEN) environment.GITHUB_PERSONAL_ACCESS_TOKEN = process.env.GITHUB_PERSONAL_ACCESS_TOKEN; | ||||||||||||||||||
| // Anthropic API key for Claude Code | ||||||||||||||||||
| if (process.env.ANTHROPIC_API_KEY) environment.ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY; | ||||||||||||||||||
| // Only pass ANTHROPIC_API_KEY to agent when api-proxy is NOT enabled | ||||||||||||||||||
| // When api-proxy IS enabled, the key goes to the sidecar only (not to agent) | ||||||||||||||||||
| if (process.env.ANTHROPIC_API_KEY && !willUseApiProxy) { | ||||||||||||||||||
| environment.ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY; | ||||||||||||||||||
| } | ||||||||||||||||||
|
||||||||||||||||||
| } | |
| } | |
| // OpenAI API key for OpenAI-based models | |
| // Only pass OPENAI_API_KEY to agent when api-proxy is NOT enabled | |
| // When api-proxy IS enabled, the key goes to the sidecar only (not to agent) | |
| if (process.env.OPENAI_API_KEY && !willUseApiProxy) { | |
| environment.OPENAI_API_KEY = process.env.OPENAI_API_KEY; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage: The changes introduce important security logic to exclude API keys from the agent environment when api-proxy is enabled. However, there are no tests verifying that ANTHROPIC_API_KEY and OPENAI_API_KEY are actually excluded from the agent environment when api-proxy is enabled.
Consider adding test cases that: