Skip to content

fix: Copilot Business 'token' prefix not overridable by AWF_PLATFORM_TYPE#5872

Merged
lpcox merged 2 commits into
mainfrom
copilot/ghes-400-bad-request-fix
Jul 3, 2026
Merged

fix: Copilot Business 'token' prefix not overridable by AWF_PLATFORM_TYPE#5872
lpcox merged 2 commits into
mainfrom
copilot/ghes-400-bad-request-fix

Conversation

Copilot AI commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

On *.ghe.com (GHEC) runners, gh-aw automatically injects AWF_PLATFORM_TYPE=ghec into the api-proxy environment. The previous ordering in copilotTargetRequiresGitHubTokenPrefix() checked this guard first, short-circuiting to false before ever reaching the GITHUB_TOKEN_PREFIX_COPILOT_TARGETS catalog check — causing Copilot Business customers with COPILOT_API_TARGET=api.business.githubcopilot.com to receive Bearer instead of the required token prefix, yielding 400 bad request: Authorization header is badly formatted.

Changes

  • containers/api-proxy/providers/copilot-auth.js — Reorder copilotTargetRequiresGitHubTokenPrefix() so catalog endpoints (api.enterprise.githubcopilot.com, api.business.githubcopilot.com) are checked first. These endpoints always require token prefix for GitHub OAuth credentials and must not be overridable by AWF_PLATFORM_TYPE. The platform-type guard is retained but now only affects the GHES heuristic for custom/unknown proxy targets.

    // Before (buggy): AWF_PLATFORM_TYPE guard fires first
    if (env.AWF_PLATFORM_TYPE && env.AWF_PLATFORM_TYPE !== 'ghes') return false; // ← short-circuits
    if (isGhesInstance(...)) return true;
    return GITHUB_TOKEN_PREFIX_COPILOT_TARGETS.has(target);                       // ← never reached
    
    // After: catalog endpoints checked first, immune to platform override
    if (GITHUB_TOKEN_PREFIX_COPILOT_TARGETS.has(target)) return true;             // ← wins always
    if (env.AWF_PLATFORM_TYPE && env.AWF_PLATFORM_TYPE !== 'ghes') return false; // ← only for heuristic
    if (isGhesInstance(...)) return true;
  • containers/api-proxy/copilot-auth.test.js — Correct the previously wrong test that expected false for api.business.githubcopilot.com + AWF_PLATFORM_TYPE=ghec; add regression tests for the full production scenario (Business + GHEC + AWF_PLATFORM_TYPE=ghec).

  • containers/api-proxy/copilot-adapter-enterprise.test.js — Fix adapter test that expected Bearer when AWF_PLATFORM_TYPE=github.com with a GHES GITHUB_SERVER_URL auto-derives the target to api.enterprise.githubcopilot.com (a catalog endpoint — correctly expects token); add a dedicated test preserving the custom-proxy override behavior; add the full GHES 400 bad request: Authorization header is badly formatted #5871 regression integration test.

Copilot AI changed the title [WIP] Fix authorization header formatting issue for GHES 400 error fix: Copilot Business 'token' prefix not overridable by AWF_PLATFORM_TYPE Jul 3, 2026
Copilot finished work on behalf of lpcox July 3, 2026 13:51
Copilot AI requested a review from lpcox July 3, 2026 13:51
@lpcox
lpcox marked this pull request as ready for review July 3, 2026 14:48
@lpcox
lpcox requested review from Copilot July 3, 2026 14:48

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 a Copilot authentication regression where AWF_PLATFORM_TYPE (auto-injected as ghec on *.ghe.com runners by gh-aw) could incorrectly force Bearer auth, even for Copilot Business/Enterprise catalog endpoints that require the token <oauth> Authorization prefix.

Changes:

  • Reorders copilotTargetRequiresGitHubTokenPrefix() to prioritize catalog endpoint detection (api.business.githubcopilot.com, api.enterprise.githubcopilot.com) ahead of the AWF_PLATFORM_TYPE override.
  • Updates and expands unit tests to cover the full production scenario (Copilot Business target + *.ghe.com + AWF_PLATFORM_TYPE=ghec) and preserve the intended override behavior for custom/unknown targets.
  • Adjusts adapter-level tests to match the corrected semantics (catalog endpoints always use token, custom targets may still be forced to Bearer via platform override).
Show a summary per file
File Description
containers/api-proxy/providers/copilot-auth.js Fixes auth-prefix decision ordering so catalog endpoints always require token, independent of AWF_PLATFORM_TYPE.
containers/api-proxy/copilot-auth.test.js Corrects prior expectation and adds regression coverage for the GHEC + Business endpoint scenario.
containers/api-proxy/copilot-adapter-enterprise.test.js Aligns adapter behavior tests with the new ordering and adds a #5871 regression test at the adapter level.

Review details

Tip

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

  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Low

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

✅ Copilot review passed with no inline comments.

@copilot Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 98.59% 98.63% 📈 +0.04%
Statements 98.52% 98.55% 📈 +0.03%
Functions 99.43% 99.43% ➡️ +0.00%
Branches 94.33% 94.33% ➡️ +0.00%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/workdir-setup.ts 93.0% → 94.8% (+1.74%) 93.0% → 94.8% (+1.74%)

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

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Contribution Check completed successfully!

PR #5872 follows the applicable CONTRIBUTING.md guidelines: clear description referencing #5871, tests included for the bug fix, changes are in the appropriate containers/api-proxy files, and no documentation update appears required for this regression fix.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Chroot tests failed Smoke Chroot failed - See logs for details.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

Smoke test complete. GitHub MCP, File Writing, and Bash tools passed. GitHub.com connectivity failed. Overall status: FAIL.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jul 3, 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 Jul 3, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (api-key) completed. Copilot AOAI BYOK (api-key) mode operational. 🔓

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude passed

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

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

FAIL: merged PR checks ✅, file/build ✅, discussion ✅, Playwright unavailable ❌, no PR context for PR comment/label.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Security Guard completed successfully!

PR #5872 security review complete: no security-weakening changes detected. Changes only reorder authorization prefix logic to prioritize catalog endpoints (api.business.githubcopilot.com, api.enterprise.githubcopilot.com), making authentication checks MORE restrictive, not less. No firewall, egress, capability, or input validation changes.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine Validation

Check Result
API Status ✅ PASS
GH Check ✅ PASS
File Status ✅ PASS

Overall Result: PASS

Warning

Firewall blocked 1 domain

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

  • awmgmcpg

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

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Smoke Claude for #5872 · 55.6 AIC · ⊞ 3.3K ·
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct) Mode

✅ GitHub MCP Connectivity
✅ GitHub.com HTTP 200
✅ File Write/Read Test
✅ BYOK Inference via api-proxy → api.githubcopilot.com

Result: PASS — Running in direct BYOK mode with placeholder credentials isolated in agent.

Warning

Firewall blocked 1 domain

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

  • awmgmcpg

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

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🔑 BYOK report filed by Smoke Copilot BYOK
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🔥 Smoke Test Results — Copilot Engine Validation

Test Result
GitHub MCP Connectivity
GitHub.com HTTP ✅ (200)
File Write/Read

Overall: PASS

@lpcox All smoke tests passed.

Warning

Firewall blocked 1 domain

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

  • awmgmcpg

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

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

📰 BREAKING: Report filed by Smoke Copilot
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🔬 Smoke Test: Copilot PAT Auth — PASS

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

Overall: PASS · Auth mode: PAT (COPILOT_GITHUB_TOKEN)

cc @lpcox

Warning

Firewall blocked 1 domain

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

  • awmgmcpg

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

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🔑 PAT report filed by Smoke Copilot PAT
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Smoke Test Results

  • Redis PING: ❌ Network unreachable
  • PostgreSQL pg_isready: ❌ No response
  • PostgreSQL SELECT 1: ❌ Network unreachable

Overall: FAILhost.docker.internal (172.17.0.1) is not reachable from this sandbox. Services containers are not accessible.

Warning

Firewall blocked 1 domain

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

  • awmgmcpg

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

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🔌 Service connectivity validated by Smoke Services
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct) Mode — Azure OpenAI

  • ✅ GitHub MCP connectivity (pre-fetched data)
  • ✅ GitHub.com HTTP connectivity
  • ✅ File write/read test
  • ✅ Direct BYOK inference via Azure Entra
    Mode: AWF_AUTH_TYPE=github-oidc + AWF_AUTH_AZURE_* + COPILOT_PROVIDER_BASE_URL via api-proxy → Azure OpenAI (Foundry, o4-mini-aw)
    Overall: PASS
    cc @lpcox

Warning

Firewall blocked 1 domain

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

  • awmgmcpg

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

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🪪 BYOK (AOAI Entra) report filed by Smoke Copilot BYOK AOAI (Entra)
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

@lpcox

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

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

Overall status: PASS

Warning

Firewall blocked 1 domain

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

  • awmgmcpg

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

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🔑 BYOK (AOAI api-key) report filed by Smoke Copilot BYOK AOAI (api-key)
Add label ready-for-aw to run again

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: API Proxy OpenTelemetry Tracing

Scenario Status Notes
1. Module Loading otel.js loads; exports startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled; isEnabled() returns true
2. Test Suite 59 tests passed, 0 failed across otel.test.js + otel-fanout.test.js
3. Env Var Forwarding api-proxy-env-config.ts forwards GH_AW_OTLP_ENDPOINTS, OTEL_EXPORTER_OTLP_ENDPOINT/HEADERS, GITHUB_AW_OTEL_TRACE_ID/PARENT_SPAN_ID, OTEL_SERVICE_NAME; verified by agent-environment-credentials.test.ts
4. Token Tracker Integration onUsage callback present in token-tracker-http.js (lines 283, 324) — OTEL hook point confirmed
5. OTEL Diagnostics FileSpanExporter fallback writes to /var/log/api-proxy/otel.jsonl when no OTLP endpoint configured — graceful degradation confirmed

All 5 scenarios passed. OTEL tracing integration is correctly implemented.

Warning

Firewall blocked 1 domain

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

  • awmgmcpg

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

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

📡 OTel tracing validated by Smoke OTel Tracing
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Gemini Engine Validation

  • GitHub MCP Testing: ✅
    • refactor: extract shared credential-isolation scaffold for API proxy providers
    • refactor: eliminate duplicate provider env-var constants via JSON single source of truth
  • GitHub.com Connectivity: ❌ (HTTP 000/Connect Failure)
  • 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
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 3, 2026

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 passed ✅ PASS
Go env passed ✅ PASS
Go uuid passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx passed ✅ PASS
Node.js execa passed ✅ PASS
Node.js p-limit passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Warning

Firewall blocked 1 domain

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

  • awmgmcpg

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

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Build Test Suite for #5872 · 42.3 AIC · ⊞ 6.9K ·
Add label ready-for-aw to run again

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.

GHES 400 bad request: Authorization header is badly formatted

3 participants