fix: inject OPENAI_API_KEY/CODEX_API_KEY placeholders for Codex api-proxy routing#2136
fix: inject OPENAI_API_KEY/CODEX_API_KEY placeholders for Codex api-proxy routing#2136
Conversation
…redential isolation Codex v0.121.0 introduced a CODEX_API_KEY-based WebSocket auth flow. When neither CODEX_API_KEY nor OPENAI_API_KEY is present in the agent environment, Codex bypasses OPENAI_BASE_URL and connects directly to wss://api.openai.com/v1/responses for OAuth authentication, getting a 401 because AWF holds the real keys in the api-proxy sidecar. Fix: inject placeholder values for OPENAI_API_KEY and CODEX_API_KEY when api-proxy is active (same pattern as ANTHROPIC_AUTH_TOKEN for credential isolation). With a key present, Codex routes API calls through OPENAI_BASE_URL=http://172.30.0.30:10000. The api-proxy sidecar then replaces the placeholder Authorization header with the real key via Object.assign(forwardHeaders, injectHeaders) before forwarding to api.openai.com. The real keys are never present in the agent container; the placeholders are intercepted by the api-proxy WebSocket upgrade handler (proxyWebSocket() in server.js:689) and replaced with the real credentials. The one-shot-token LD_PRELOAD library caches and clears placeholders from /proc/self/environ as normal. Update tests to assert placeholder is set and real key is not leaked. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR addresses a Codex v0.121+ behavior where missing OPENAI_API_KEY/CODEX_API_KEY in the agent environment can cause Codex to bypass OPENAI_BASE_URL and connect directly to api.openai.com, breaking api-proxy routing and credential isolation.
Changes:
- Injects placeholder
OPENAI_API_KEYandCODEX_API_KEYinto the agent container when OpenAI api-proxy routing is configured. - Updates docker-manager tests to assert placeholders are present and host keys are not leaked to the agent.
Show a summary per file
| File | Description |
|---|---|
src/docker-manager.ts |
Adds OpenAI/Codex placeholder key injection alongside OPENAI_BASE_URL proxy configuration. |
src/docker-manager.test.ts |
Updates existing tests to validate placeholder injection and prevent secret leakage under normal and --env-all scenarios. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…keys The health check was blocking startup when OPENAI_API_KEY or CODEX_API_KEY contained the placeholder value 'sk-placeholder-for-api-proxy', treating it as a credential isolation failure. Update the check to allow the known placeholder value while still rejecting any real (non-placeholder) keys. This mirrors the Anthropic pattern where ANTHROPIC_AUTH_TOKEN is allowed to hold its placeholder value. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Smoke Test Results:
Status: FAIL - gh CLI not authenticated for PR listing
|
🔥 Smoke Test: Copilot BYOK — PASS
Running in BYOK offline mode ( Overall: PASS | PR by @lpcox (no assignees)
|
🧪 Smoke Test Results — @lpcox
Overall: FAIL (MCP GraphQL unavailable; REST API functional)
|
|
OpenCode smoke test results PR titles (last 2 merged):
Overall status: PASS Warning
|
|
Smoke Test Results Warning
|
Chroot Version Comparison Results
Overall: ❌ Tests did not all pass — Python and Node.js versions differ between host and chroot environments.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Smoke Test: GitHub Actions Services Connectivity ✅All checks passed:
|
Problem
Codex v0.121.0 introduced a
CODEX_API_KEY-based WebSocket auth flow. When neitherCODEX_API_KEYnorOPENAI_API_KEYis present in the agent environment, Codex bypassesOPENAI_BASE_URLand connects directly towss://api.openai.com/v1/responsesfor OAuth authentication — getting a 401 because AWF holds the real keys in the api-proxy sidecar.Diagnostic evidence from the failing smoke run:
auth_env_openai_api_key_present=falseauth_env_codex_api_key_present=falseauth_env_codex_api_key_enabled=trueauth_header_attached=falseapi.openai.comdirectlyFix
Inject placeholder values for
OPENAI_API_KEYandCODEX_API_KEYin the agent container when--enable-api-proxyis active — the same pattern already used for Anthropic credential isolation (ANTHROPIC_AUTH_TOKENplaceholder).With a key present, Codex finds it, routes API calls through
OPENAI_BASE_URL=http://172.30.0.30:10000, and the api-proxy WebSocket upgrade handler (proxyWebSocket()) replaces the placeholder'sAuthorizationheader with the real key viaObject.assign(forwardHeaders, injectHeaders)before forwarding toapi.openai.com.The real keys are never present in the agent container. The one-shot-token
LD_PRELOADlibrary caches and clears the placeholder from/proc/self/environas normal.Changes
src/docker-manager.ts: SetOPENAI_API_KEYandCODEX_API_KEYtosk-placeholder-for-api-proxywhen api-proxy is enabledsrc/docker-manager.test.ts: Update 3 tests to assert placeholder is set and real key is not leaked