Skip to content

fix(api-proxy): use 'token' auth prefix for Copilot Business endpoint#5415

Merged
lpcox merged 1 commit into
mainfrom
fix/copilot-business-auth-prefix
Jun 23, 2026
Merged

fix(api-proxy): use 'token' auth prefix for Copilot Business endpoint#5415
lpcox merged 1 commit into
mainfrom
fix/copilot-business-auth-prefix

Conversation

@lpcox

@lpcox lpcox commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Problem

Copilot Business customers (COPILOT_API_TARGET=api.business.githubcopilot.com, typically on a *.ghe.com GHEC server) get 400 bad request: Authorization header is badly formatted on every Copilot request, and the run exits 1.

The auth-prefix logic in copilot.js#getAuthHeaders only applied the token <oauth> Authorization prefix when isGhesInstance(rawTarget, env) was true. isGhesInstance only matches the enterprise host (api.enterprise.githubcopilot.com) directly, and its GITHUB_SERVER_URL heuristic explicitly treats *.ghe.com as not GHES. So for the business host on a *.ghe.com server it returns false, the GitHub OAuth token goes out as Bearer <oauth>, and the business endpoint rejects it.

api.business.githubcopilot.com did not appear anywhere in the source. The prior fixes (#4755, #5076) covered enterprise/GHES only.

Reported in github/gh-aw#38575 (still reproducing as of 2026-06-19).

Fix

Add copilotTargetRequiresGitHubTokenPrefix(resolvedTarget, env) in copilot-auth.js, and use it in getAuthHeaders for both the /models path and inference requests.

It returns true (→ token prefix for GitHub tokens) when either:

  1. isGhesInstance() is true (unchanged GHES behavior), or
  2. the resolved target is a GitHub-hosted endpoint that authenticates the GitHub token directly — api.enterprise.githubcopilot.com or api.business.githubcopilot.com.

Preserved invariants:

  • An explicit non-GHES AWF_PLATFORM_TYPE still forces Bearer (documented escape hatch, consistent with isGhesInstance).
  • BYOK API keys always use Bearer.
  • Standard api.githubcopilot.com and GHEC (*.ghe.com) Copilot targets keep Bearer.

Tests

  • copilot-auth.test.js: 8 unit tests for copilotTargetRequiresGitHubTokenPrefix (business host, business on *.ghe.com, GHES, standard, GHEC, AWF_PLATFORM_TYPE override).
  • copilot-adapter-enterprise.test.js: 5 adapter-level tests for the Business host (inference + /models use token; BYOK stays Bearer; accidental token prefix stripped).
  • Full api-proxy suite: 1290 passed.

Fixes github/gh-aw#38575

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

The Copilot auth-prefix logic only applied the 'token <oauth>' Authorization
prefix when the resolved target was api.enterprise.githubcopilot.com (via
isGhesInstance). Copilot Business customers set
COPILOT_API_TARGET=api.business.githubcopilot.com, often on a *.ghe.com (GHEC)
server. For that combination isGhesInstance returns false, so the GitHub token
went out as 'Bearer <oauth>' and the business endpoint rejected it with
"400 bad request: Authorization header is badly formatted".

Add copilotTargetRequiresGitHubTokenPrefix(), which applies the 'token' prefix
for both the Enterprise and Business GitHub-hosted Copilot endpoints (in
addition to GHES), while still honoring an explicit non-GHES AWF_PLATFORM_TYPE
override and keeping 'Bearer' for BYOK keys and standard/GHEC targets.

Fixes github/gh-aw#38575

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 22, 2026 21:33
@github-actions

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 98.01% 98.05% 📈 +0.04%
Statements 97.95% 97.98% 📈 +0.03%
Functions 99.51% 99.51% ➡️ +0.00%
Branches 93.68% 93.72% 📈 +0.04%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/workdir-setup.ts 92.7% → 94.5% (+1.82%) 92.7% → 94.5% (+1.82%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Copilot Business requests failing with 400 ... Authorization header is badly formatted by ensuring GitHub OAuth/PAT credentials use the correct token <value> auth scheme when targeting GitHub-hosted Copilot endpoints that require it (Business + Enterprise), including the /models path and inference calls.

Changes:

  • Introduces copilotTargetRequiresGitHubTokenPrefix() to decide when GitHub tokens must be sent as Authorization: token <value>.
  • Updates the Copilot provider adapter to apply token vs Bearer consistently for /models and inference based on the new predicate.
  • Adds unit + adapter-level tests covering Business host scenarios (including Business on *.ghe.com) and AWF_PLATFORM_TYPE override behavior.
Show a summary per file
File Description
containers/api-proxy/providers/copilot.js Switches auth-prefix decision logic to the new predicate for /models and inference requests.
containers/api-proxy/providers/copilot-auth.js Adds copilotTargetRequiresGitHubTokenPrefix() and target allowlist for hosts requiring token prefix for GitHub credentials.
containers/api-proxy/copilot-auth.test.js Adds focused unit tests for the new predicate across Business/Enterprise/GHES/GHEC/override cases.
containers/api-proxy/copilot-adapter-enterprise.test.js Adds adapter-level regression tests ensuring Business target uses token, while BYOK remains Bearer.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 4/4 changed files
  • Comments generated: 0

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded.

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (api-key) reports failed. AOAI BYOK (api-key) mode investigation needed...

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude passed

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

🔑 Smoke Copilot PAT PAT auth validated. All systems operational. ✅

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (Entra) completed. Copilot AOAI BYOK (Entra) mode operational. 🔓

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine Validation

Check Result
API status ✅ PASS
gh check ✅ PASS
File status ✅ PASS

Overall result: PASS

Generated by Smoke Claude for issue #5415 · 60.9 AIC · ⊞ 6.5K ·

@github-actions

Copy link
Copy Markdown
Contributor

🔥 Smoke Test: Copilot PAT — PASS

Test Result
GitHub MCP connectivity
GitHub.com HTTP (200)
File write/read

Overall: PASS@lpcox

Auth mode: PAT (COPILOT_GITHUB_TOKEN)

🔑 PAT report filed by Smoke Copilot PAT

@github-actions

Copy link
Copy Markdown
Contributor

🔥 Smoke Test Results

PR: fix(api-proxy): use 'token' auth prefix for Copilot Business endpoint
Author: @lpcox

Test Result
GitHub MCP connectivity
GitHub.com HTTP connectivity
File write/read

Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct Mode) - PASS

  • ✅ GitHub MCP connectivity (2 merged PRs fetched)
  • ✅ GitHub.com reachable (HTTP 200)
  • ✅ File write/read verified
  • ✅ BYOK inference working (agent → api-proxy → api.githubcopilot.com)

Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY) with api-proxy forwarding.

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

Copy link
Copy Markdown
Contributor

Remove unused ParsedDomainList export from domain-matchers
Remove unused ParsedDomain from domain-patterns
GitHub reads: ✅
Browser: ✅
File write: ✅
Build: ✅
Overall: PASS

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions

Copy link
Copy Markdown
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3 ❌ No
Node.js v24.16.0 v22.22.3 ❌ No
Go go1.22.12 go1.22.12 ✅ Yes

Overall: ❌ Not all tests passed. Python and Node.js versions differ between host and chroot environments.

Tested by Smoke Chroot

@github-actions

Copy link
Copy Markdown
Contributor

@lpcox

  • GitHub MCP Testing: ✅
  • GitHub.com Connectivity: ✅
  • File Write/Read Test: ✅
  • BYOK Inference Test: ✅

Running in direct BYOK mode (AWF_AUTH_TYPE=github-oidc + AWF_AUTH_AZURE_* + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) authenticated via Microsoft Entra
Overall: PASS

🪪 BYOK (AOAI Entra) report filed by Smoke Copilot BYOK AOAI (Entra)

@github-actions

Copy link
Copy Markdown
Contributor

@lpcox

Smoke test results:

  • PR 5422: ✅ refactor: extract buildAgentSecurityConfig from buildAgentService
  • PR 5421: ✅ refactor(api-proxy): decompose handleUpstreamResponse into focused helpers
  • GitHub API: ✅
  • GitHub.com connectivity: ✅
  • File I/O: ✅
  • BYOK inference: ✅

Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw)

Overall: PASS

🔑 BYOK (AOAI api-key) report filed by Smoke Copilot BYOK AOAI (api-key)

@github-actions

Copy link
Copy Markdown
Contributor

🔭 Smoke Test: API Proxy OpenTelemetry Tracing

Scenario Result Notes
1. Module Loading otel.js loads; isEnabled()=true; exports 14 symbols incl. startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled
2. Test Suite otel.test.js: 39 passed · otel-fanout.test.js: 20 passed (59 total, 0 failures)
3. Env Var Forwarding api-proxy-service-config.ts forwards GH_AW_OTLP_ENDPOINTS, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, GITHUB_AW_OTEL_TRACE_ID, GITHUB_AW_OTEL_PARENT_SPAN_ID, OTEL_SERVICE_NAME to the api-proxy container
4. Token Tracker Integration onUsage callback present in token-tracker-http.js (line 283); invoked at line 324 to deliver token data to setTokenAttributes
5. OTEL Diagnostics No OTLP endpoint configured → spans fall back to /var/log/api-proxy/otel.jsonl (expected graceful degradation path)

All scenarios pass. OTEL tracing integration is fully operational.

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx All passed ✅ PASS
Node.js execa All passed ✅ PASS
Node.js p-limit All passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #5415 · 39.8 AIC · ⊞ 7.7K ·

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results: FAIL

Check Result
Redis PING ❌ timeout (no response on host.docker.internal:6379)
PostgreSQL pg_isready ❌ no response on host.docker.internal:5432
PostgreSQL SELECT 1 ❌ timeout

Overall: FAILhost.docker.internal is not reachable from this runner. Service containers may not be running or the hostname is not resolvable in this environment.

🔌 Service connectivity validated by Smoke Services

@github-actions

Copy link
Copy Markdown
Contributor

GitHub MCP Testing: ❌ (MCP tools not available)
GitHub.com Connectivity: ❌ (curl failed, exit code 35)
File Writing Testing: ✅
Bash Tool Testing: ✅
Overall status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • localhost

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini

@lpcox lpcox merged commit acd06ee into main Jun 23, 2026
86 of 89 checks passed
@lpcox lpcox deleted the fix/copilot-business-auth-prefix branch June 23, 2026 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

400 bad request: Authorization header is badly formatted - GHE

2 participants