From fbbe2be069474cb1f871b7fdedf72ade58ff6c62 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Mar 2026 20:22:52 +0000 Subject: [PATCH 1/2] Initial plan From 4ee85de8c1e95574e49d95a33372daec7a99101a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Mar 2026 20:50:34 +0000 Subject: [PATCH 2/2] fix: restore GITHUB_API_URL in agent container when api-proxy is enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: commit 5a56789 excluded GITHUB_API_URL from the agent container when api-proxy is enabled, based on the incorrect theory that its presence would cause the Copilot CLI to route token exchange through api.github.com with the placeholder token. Evidence from CI logs: successful runs (worktree-audit-observability) had GITHUB_API_URL present and worked; all failing runs lacked it and failed immediately with "Authentication failed" after ~1.2 seconds. The Copilot CLI needs GITHUB_API_URL to locate the GitHub API. Its Copilot-specific calls (token exchange, inference) already route through COPILOT_API_URL → api-proxy regardless of GITHUB_API_URL being set. Fix: - Remove EXCLUDED_ENV_VARS.add('GITHUB_API_URL') from api-proxy block - Change conditional GITHUB_API_URL assignment to unconditional - Update test to expect GITHUB_API_URL present even with api-proxy enabled Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/db4a1afe-02b9-43f2-bfae-41febbcbc8b5 --- src/docker-manager.test.ts | 14 +++++++------- src/docker-manager.ts | 22 +++++++++------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/docker-manager.test.ts b/src/docker-manager.test.ts index ce5f3366d..ff7354968 100644 --- a/src/docker-manager.test.ts +++ b/src/docker-manager.test.ts @@ -2025,10 +2025,10 @@ describe('docker-manager', () => { } }); - it('should not leak GITHUB_API_URL to agent when api-proxy is enabled with envAll', () => { - // When api-proxy is enabled, GITHUB_API_URL must be excluded so the Copilot CLI - // routes token exchange through COPILOT_API_URL → api-proxy (not directly to api.github.com - // with the placeholder COPILOT_GITHUB_TOKEN, which would cause a 401). + it('should pass GITHUB_API_URL to agent when api-proxy is enabled with envAll', () => { + // GITHUB_API_URL must remain in the agent environment even when api-proxy is enabled. + // The Copilot CLI needs it to locate the GitHub API (token exchange, user info, etc.). + // Copilot-specific calls route through COPILOT_API_URL → api-proxy regardless. // See: github/gh-aw#20875 const origUrl = process.env.GITHUB_API_URL; process.env.GITHUB_API_URL = 'https://api.github.com'; @@ -2037,9 +2037,9 @@ describe('docker-manager', () => { const result = generateDockerCompose(configWithProxy, mockNetworkConfigWithProxy); const agent = result.services.agent; const env = agent.environment as Record; - // GITHUB_API_URL should NOT be passed to agent when api-proxy is enabled - expect(env.GITHUB_API_URL).toBeUndefined(); - // COPILOT_API_URL should be set to route through the api-proxy + // GITHUB_API_URL should be passed to agent even when api-proxy is enabled + expect(env.GITHUB_API_URL).toBe('https://api.github.com'); + // COPILOT_API_URL should also be set to route Copilot calls through the api-proxy expect(env.COPILOT_API_URL).toBe('http://172.30.0.30:10002'); } finally { if (origUrl !== undefined) { diff --git a/src/docker-manager.ts b/src/docker-manager.ts index cde4ed7d5..441c8efe4 100644 --- a/src/docker-manager.ts +++ b/src/docker-manager.ts @@ -455,12 +455,10 @@ export function generateDockerCompose( EXCLUDED_ENV_VARS.add('ANTHROPIC_API_KEY'); EXCLUDED_ENV_VARS.add('CLAUDE_API_KEY'); // COPILOT_GITHUB_TOKEN gets a placeholder (not excluded), protected by one-shot-token - // GITHUB_API_URL must be excluded so the Copilot CLI routes ALL requests (including - // token exchange) through COPILOT_API_URL → api-proxy, not directly to api.github.com. - // If GITHUB_API_URL is present, the CLI may call api.github.com/copilot_internal/v2/token - // with the placeholder COPILOT_GITHUB_TOKEN (bypassing the api-proxy injection), causing 401. + // GITHUB_API_URL is intentionally NOT excluded: the Copilot CLI needs it to know the + // GitHub API base URL. Copilot-specific API calls (inference and token exchange) go + // through COPILOT_API_URL → api-proxy regardless of GITHUB_API_URL being set. // See: github/gh-aw#20875 - EXCLUDED_ENV_VARS.add('GITHUB_API_URL'); } // Start with required/overridden environment variables @@ -590,14 +588,12 @@ export function generateDockerCompose( if (process.env.XDG_CONFIG_HOME) environment.XDG_CONFIG_HOME = process.env.XDG_CONFIG_HOME; // Enterprise environment variables — needed for GHEC/GHES Copilot authentication if (process.env.GITHUB_SERVER_URL) environment.GITHUB_SERVER_URL = process.env.GITHUB_SERVER_URL; - // GITHUB_API_URL — only pass when api-proxy is NOT enabled. - // On GHES, workflows set GITHUB_API_URL to the GHES API endpoint (e.g., https://api.ghes-host). - // When api-proxy is enabled, Copilot CLI must use COPILOT_API_URL (pointing to the proxy) - // instead of GITHUB_API_URL, because the proxy correctly routes Copilot API requests to - // api.enterprise.githubcopilot.com (not the GHES API which lacks Copilot endpoints). - // GITHUB_API_URL is also excluded via EXCLUDED_ENV_VARS for the --env-all path. - // See: github/gh-aw#20875 - if (process.env.GITHUB_API_URL && !config.enableApiProxy) environment.GITHUB_API_URL = process.env.GITHUB_API_URL; + // GITHUB_API_URL — always pass when set. The Copilot CLI needs it to locate the GitHub API + // (especially on GHES/GHEC where the URL differs from api.github.com). + // Copilot-specific API calls (inference and token exchange) always route through + // COPILOT_API_URL → api-proxy when api-proxy is enabled, so GITHUB_API_URL does not + // interfere with credential isolation. + if (process.env.GITHUB_API_URL) environment.GITHUB_API_URL = process.env.GITHUB_API_URL; // Auto-inject GH_HOST when GITHUB_SERVER_URL points to a GHES/GHEC instance // This ensures gh CLI inside the agent container targets the correct GitHub instance