Skip to content

fix: broaden GHES detection for Copilot auth prefix#5076

Merged
lpcox merged 2 commits into
mainfrom
fix/ghes-copilot-auth-prefix
Jun 16, 2026
Merged

fix: broaden GHES detection for Copilot auth prefix#5076
lpcox merged 2 commits into
mainfrom
fix/ghes-copilot-auth-prefix

Conversation

@lpcox

@lpcox lpcox commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Problem

The api-proxy only detects GHES when the resolved Copilot API target is exactly api.enterprise.githubcopilot.com. However, when COPILOT_API_TARGET is set to a custom hostname (e.g. by older gh-aw versions or internal routing configurations), the check fails and the auth header uses Bearer prefix instead of token — causing 400 errors from GHES Copilot endpoints.

Fix

Add isGhesInstance(resolvedTarget, env) function in copilot-auth.js that uses a two-signal approach:

  1. Primary: Check if resolved target is api.enterprise.githubcopilot.com (existing behavior)
  2. Secondary: Check GITHUB_SERVER_URL — if it's not github.com or *.ghe.com, treat as GHES

This covers environments where the API target hostname differs from the standard enterprise endpoint.

Tests

Added 10 new test cases:

  • isGhesInstance() unit tests (6 cases covering all detection paths)
  • Integration tests for custom COPILOT_API_TARGET + GHES GITHUB_SERVER_URL (4 cases)

All 105 auth tests pass.

Fixes #4793
Related: github/gh-aw#38575

Copilot AI review requested due to automatic review settings June 16, 2026 00:27
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 96.89% 96.93% 📈 +0.04%
Statements 96.75% 96.79% 📈 +0.04%
Functions 98.81% 98.81% ➡️ +0.00%
Branches 91.26% 91.26% ➡️ +0.00%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/workdir-setup.ts 92.6% → 94.4% (+1.85%) 92.6% → 94.4% (+1.85%)

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

This PR fixes Copilot auth header formatting for GitHub Enterprise Server (GHES) when COPILOT_API_TARGET is overridden to a custom hostname, ensuring the Authorization header uses the required token <value> prefix (instead of Bearer <value>) to avoid 400 errors from GHES Copilot endpoints.

Changes:

  • Introduces isGhesInstance(resolvedTarget, env) in copilot-auth.js to detect GHES using both resolved target and GITHUB_SERVER_URL.
  • Updates Copilot adapter auth-header selection to rely on isGhesInstance(...) instead of a single hostname equality check.
  • Adds/extends unit + integration-style tests covering custom targets combined with GHES vs github.com/GHEC server URLs.
Show a summary per file
File Description
containers/api-proxy/server.auth.test.js Adds test coverage for GHES detection and auth prefix behavior when COPILOT_API_TARGET is custom.
containers/api-proxy/providers/copilot.js Switches enterprise/GHES auth prefix decision to isGhesInstance(...).
containers/api-proxy/providers/copilot-auth.js Adds isGhesInstance(...) helper and exports it for use and testing.

Copilot's findings

Tip

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

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

The api-proxy previously only detected GHES when the resolved target was
exactly 'api.enterprise.githubcopilot.com'. When COPILOT_API_TARGET is
set to a custom hostname (e.g. by older gh-aw versions or custom
configurations), the check failed and Bearer was sent instead of token.

Add isGhesInstance() that checks multiple signals with clear priority:
  1. AWF_PLATFORM_TYPE=ghes (explicit config, highest priority)
  2. Resolved target === api.enterprise.githubcopilot.com
  3. GITHUB_SERVER_URL not github.com / *.ghe.com

Add 'platform' section to the AWF stdin config spec and JSON schema with
a 'type' field that explicitly declares the deployment environment
(github.com, ghes, ghec, ghec-self-hosted). This is forwarded as
AWF_PLATFORM_TYPE to the api-proxy container, giving users a definitive
way to control auth behavior without relying on heuristic detection.

Fixes #4793

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox force-pushed the fix/ghes-copilot-auth-prefix branch from dca6cdd to b0e3c61 Compare June 16, 2026 00:39
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Documentation Preview

Documentation build failed for this PR. View logs.

Built from commit 212d330

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

Smoke test completed with partial failures. Results reported via PR comment.

@github-actions

github-actions Bot commented Jun 16, 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 Jun 16, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Contribution Check failed. Please review the logs for details.

@github-actions

github-actions Bot commented Jun 16, 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 16, 2026

Copy link
Copy Markdown
Contributor

Security Guard failed. Please review the logs for details.

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude failed

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

Smoke test completed. Results: MCP ✅, Connectivity ❌, File Write ✅, Bash ✅. Comment added to PR #5076.

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

@github-actions

Copy link
Copy Markdown
Contributor

@lpcox

fix: broaden GHES detection for Copilot auth prefix

✅ MCP connectivity
✅ GitHub.com connectivity
✅ File I/O test
✅ 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 Results

PR: fix: broaden GHES detection for Copilot auth prefix
Author: @lpcox

Test Status
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

@lpcox Smoke Test Results:

  • MCP PR API: ✅
  • GitHub.com HTTP: ✅
  • File I/O: ✅
  • BYOK inference: ✅

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

🔭 Smoke Test: API Proxy OpenTelemetry Tracing

Scenario Result Notes
1. Module Loading otel.js loads; exports: startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled + internals
2. Test Suite 59 tests passed, 0 failed (2 suites: otel.test.js, otel-fanout.test.js)
3. Env Var Forwarding src/services/api-proxy-service-config.ts forwards GH_AW_OTLP_ENDPOINTS, OTEL_EXPORTER_OTLP_ENDPOINT/HEADERS, GITHUB_AW_OTEL_TRACE_ID/PARENT_SPAN_ID; observability-environment.ts auto-passes all OTEL_* vars
4. Token Tracker Integration onUsage callback present in token-tracker-http.js (line 283) — OTEL hook point confirmed
5. OTEL Diagnostics No live OTLP endpoint configured in this run (expected); file fallback exporter (/var/log/api-proxy/otel.jsonl) available for local diagnostics

All scenarios pass. OTEL tracing integration is fully functional.

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct) Mode ✅ PASS

  • ✅ GitHub MCP connectivity verified
  • ✅ GitHub.com connectivity: HTTP 200 OK
  • ✅ BYOK inference path active (agent → api-proxy → api.githubcopilot.com)

Running in direct BYOK mode via COPILOT_PROVIDER_API_KEY. All smoke tests pass.

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

Copy link
Copy Markdown
Contributor

🔬 Smoke Test — Auth mode: PAT (COPILOT_GITHUB_TOKEN)

Test Result
GitHub MCP connectivity
GitHub.com HTTP ⚠️ pre-step data unavailable (template unresolved)
File write/read ⚠️ pre-step data unavailable (template unresolved)

Overall: FAIL — pre-computed step outputs were not injected (smoke-data step may not have run).

cc @lpcox

🔑 PAT report filed by Smoke Copilot PAT

@github-actions

Copy link
Copy Markdown
Contributor

Chroot Version Comparison — Smoke Test 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

Result: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot environments. The smoke-chroot label was not applied.

Tested by Smoke Chroot

@github-actions

Copy link
Copy Markdown
Contributor

ECOSYSTEM: Deno
CLONE: SUCCESS
PROJECT: oak
TESTS: 1 passed, 0 failed
STATUS: PASS
ERRORS: none
PROJECT: std
TESTS: 1 passed, 0 failed
STATUS: PASS
ERRORS: none

Generated by Build Test Suite for issue #5076 ·

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results

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

@github-actions

Copy link
Copy Markdown
Contributor

refactor: decompose finalizeHttpTracking into focused helper functions
fix: recognize copilot-pull-request-reviewer in ci-gate
✅ GitHub reads
✅ Playwright title
✅ File write/readback
✅ Discussion comment
✅ Build
PASS

🔮 The oracle has spoken through Smoke Codex

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Services: FAIL ❌

Check Result
Redis PING ❌ Timeout (port 6379 unreachable)
PostgreSQL pg_isready ❌ No response (port 5432 unreachable)
PostgreSQL SELECT 1 ❌ No response

Root cause: No GitHub Actions services: containers are defined for Redis/PostgreSQL, and --allow-host-ports only includes 80,443,8080 — ports 6379 and 5432 are not whitelisted in the AWF sandbox.

🔌 Service connectivity validated by Smoke Services

@lpcox lpcox force-pushed the fix/ghes-copilot-auth-prefix branch from 2296264 to 51f2778 Compare June 16, 2026 04:19
GITHUB_TOKEN-added labels don't trigger other workflows (GitHub's
anti-cascade protection). Instead of auto-labeling, ci-gate now posts a
comment instructing the PR owner to manually add the 'ready-for-aw'
label to trigger agentic CI smoke tests.

Changes:
- Rename label from 'ready-for-ci' to 'ready-for-aw' across all workflows
- ci-gate posts/updates a comment instead of calling issues.addLabels
- Add 'opened' to pull_request trigger types
- Add copilot-pull-request-reviewer[bot] to reviewer Set
- Rename test file to match new label name

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox force-pushed the fix/ghes-copilot-auth-prefix branch from 51f2778 to 246028c Compare June 16, 2026 04:20
@lpcox lpcox merged commit 7684ab6 into main Jun 16, 2026
24 checks passed
@lpcox lpcox deleted the fix/ghes-copilot-auth-prefix branch June 16, 2026 04:21
github-actions Bot added a commit that referenced this pull request Jun 16, 2026
PR #5076 (broaden GHES detection for Copilot auth prefix) introduced
the platform.type config field but omitted it from the Section 5 CLI
mapping table in docs/awf-config-spec.md.

The field is config-only (no CLI flag equivalent) and maps to the
AWF_PLATFORM_TYPE environment variable passed to the api-proxy container.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lpcox pushed a commit that referenced this pull request Jun 16, 2026
…5110)

PR #5076 (broaden GHES detection for Copilot auth prefix) introduced
the platform.type config field but omitted it from the Section 5 CLI
mapping table in docs/awf-config-spec.md.

The field is config-only (no CLI flag equivalent) and maps to the
AWF_PLATFORM_TYPE environment variable passed to the api-proxy container.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot mentioned this pull request Jun 17, 2026
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.

Auth Matrix: Complete coverage map of all provider × auth-type × instance combinations

2 participants