Skip to content

Extract shared auth-header builder for OpenAI and Copilot provider adapters - #8226

Merged
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-provider-auth-setup
Sep 7, 2026
Merged

Extract shared auth-header builder for OpenAI and Copilot provider adapters#8226
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-provider-auth-setup

Conversation

Copilot AI commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

copilot.js and openai.js each reimplemented the same "custom header name vs. Authorization prefix" branching for credential injection, making security-sensitive auth logic harder to keep consistent across providers.

Shared helper

  • Added buildAuthHeaderFn({ headerName, prefix }) to containers/api-proxy/providers/auth-headers.js. Given a headerName it builds a providerKeyHeaders-style header (e.g. Azure BYOK's api-key); otherwise it falls back to tokenAuthHeaders with a configurable prefix (default Bearer), covering Copilot's token/Bearer split.

Adapter updates

  • openai.js: replaced the inline customAuthHeader ? providerKeyHeaders(...) : bearerAuthHeaders(...) branch with buildAuthHeaderFn({ headerName: customAuthHeader || undefined }).
  • copilot.js: replaced the tokenAuthHeaders(authPrefix, authToken, ...) call in buildStaticHeaders with buildAuthHeaderFn({ prefix: authPrefix })(...).

Tests

  • Added unit tests in auth-headers.test.js covering default prefix, custom prefix, header-name mode, and extra-header merging for both modes.
// before (openai.js)
function buildTokenAuthHeaders(key) {
  if (customAuthHeader) return providerKeyHeaders(customAuthHeader, key);
  return bearerAuthHeaders(key);
}

// after
const buildTokenAuthHeaders = buildAuthHeaderFn({ headerName: customAuthHeader || undefined });

No behavior change intended — this is a pure extraction of existing branching into one reusable, testable helper.

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor provider auth setup to eliminate duplicate code Extract shared auth-header builder for OpenAI and Copilot provider adapters Sep 6, 2026
Copilot AI requested a review from lpcox September 6, 2026 22:17
@lpcox
lpcox marked this pull request as ready for review September 6, 2026 22:17
Copilot AI balanced review requested due to automatic review settings September 6, 2026 22:17

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Note

This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.

@lpcox
lpcox requested a balanced review from Copilot September 6, 2026 23:16

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Note

This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.

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.

🟡 Changes recommended

Remove the accidental temporary file and correct the helper’s misleading prefix documentation.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 4/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread containers/api-proxy/providers/auth-headers.js Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

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

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 93.97% 93.98% 📈 +0.01%
Statements 92.62% 92.63% ➡️ +0.01%
Functions 93.25% 93.25% ➡️ +0.00%
Branches 86.45% 86.47% 📈 +0.02%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/log-directory-setup.ts 96.2% → 100.0% (+3.78%) 96.3% → 100.0% (+3.71%)

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

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

📰 DEVELOPING STORY: Smoke Docker Sbx reports failed. Our correspondents are investigating the incident...

📰 BREAKING: Report filed by Smoke Docker Sbx

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

🔌 Service connectivity validated by Smoke Services

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude failed

Warning

Firewall blocked 1 domain

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

  • api.anthropic.com

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

network:
  allowed:
    - defaults
    - "api.anthropic.com"

See Network Configuration for more information.

Generated by Smoke Claude for #8226

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

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

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Contribution Check completed successfully!

PR #8226 follows the applicable contribution guidelines in CONTRIBUTING.md. The change adds focused tests for the new helper, keeps files in the correct directories, and the PR description clearly explains the extraction and links the related issue.

Generated by Contribution Check for #8226

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

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

Tested by Smoke Chroot

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

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

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

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini reports failed. Facets need polishing...

💎 Faceted by Smoke Gemini

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

Generated by Build Test Suite for #8226

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

🌑 The shadows whisper... Smoke Codex failed. The oracle requires further meditation...

🔮 The oracle has spoken through Smoke Codex

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

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

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

@lpcox
lpcox deployed to aoai-model September 7, 2026 14:42 — with GitHub Actions Active
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

🛡️ Smoke Copilot Network Isolation confirmed the egress allowlist is enforced. ✅

Warning

Firewall blocked 1 domain

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

  • example.com

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

network:
  allowed:
    - defaults
    - "example.com"

See Network Configuration for more information.

🛡️ Egress verdict from Smoke Copilot Network Isolation

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

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

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Security Guard completed successfully!

Security review of PR #8226 complete: Extract shared auth-header builder for OpenAI and Copilot provider adapters. Changes are refactoring-only (consolidating duplicated auth header logic into buildAuthHeaderFn). No security-weakening changes detected: no expanded ACLs, no weakened validation, no secrets exposure, no capability additions, no firewall chain changes. Passes security review.

Generated by Security Guard for #8226

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Services Connectivity

  • Redis PING: ❌ (Temporary failure in name resolution)
  • pg_isready: ❌ (no response)
  • PostgreSQL SELECT 1: ❌ (could not translate host name)

Overall: FAILhost.docker.internal did not resolve; AWF sandbox cannot reach host service containers.

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

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: API Proxy OTEL Tracing — Results

  • Scenario 1 (Module loading): ✅ otel.js loads cleanly, exports startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled, plus exporter/serialization internals.
  • Scenario 2 (Test suite): ✅ 3 suites / 68 tests passed (otel.test.js, otel-fanout.test.js, otel-workload-identity.test.js).
  • Scenario 3 (Env var forwarding): ✅ env-passthrough.ts forwards GITHUB_AW_OTEL_TRACE_ID/GITHUB_AW_OTEL_PARENT_SPAN_ID (+ COPILOT_OTEL_FILE_EXPORTER_PATH) into the agent; api-proxy-env-config.ts buildOtelEnv() forwards OTLP endpoint/headers, service name, and parent trace context into api-proxy.
  • Scenario 4 (Token tracker integration): ✅ onUsage callback present in token-tracker-http.js (invoked after normalized usage extraction) as the OTEL hook point.
  • Scenario 5 (OTEL diagnostics): ✅ /tmp/gh-aw/otel.jsonl contains 1 exported span with service.name=gh-aw.smoke-otel-tracing, workflow/run resource attributes — confirms OTLP export path is functioning for this run.

Overall: All 5 scenarios pass. No unexpected failures detected.

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

@github-actions github-actions Bot added the smoke-copilot-network-isolation Copilot network-isolation egress smoke test label Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

EGRESS_RESULT allow=pass deny=pass

✅ allowed domain (api.github.com) reachable — HTTP 200
✅ non-allowed domain (example.com) blocked — CONNECT tunnel failed 403

Overall status: PASS

@lpcox

Warning

Firewall blocked 1 domain

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

  • example.com

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

network:
  allowed:
    - defaults
    - "example.com"

See Network Configuration for more information.

🛡️ Egress verdict from Smoke Copilot Network Isolation
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct) Mode

GitHub MCP Testing — Verified connectivity to github/gh-aw-firewall (2 merged PRs listed)
GitHub.com Connectivity — HTTP 200
File Write/Read Test — File exists and readable
BYOK Inference Test — Running in direct BYOK mode via api-proxy → api.githubcopilot.com

Status: PASS

Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY) with inference routed through api-proxy sidecar to api.githubcopilot.com.

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

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot Engine@lpcox

Recent PRs:

Overall: PASS

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

@github-actions

github-actions Bot commented Sep 7, 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 (ran ok) ✅ PASS
.NET json-parse N/A (ran ok) ✅ PASS
Go color pass ✅ PASS
Go env pass ✅ PASS
Go uuid pass ✅ PASS
Java gson pass (quiet) ✅ PASS
Java caffeine pass (quiet) ✅ PASS
Node.js clsx pass ✅ PASS
Node.js execa pass ✅ PASS
Node.js p-limit pass ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — PASS

Notes:

  • Java required setting -Dmaven.repo.local to a writable directory (~/.m2/repository was root-owned/non-writable in this environment); once redirected, mvn compile/mvn test ran cleanly through the Squid proxy (JAVA_TOOL_OPTIONS proxy settings applied correctly).
  • All other ecosystems built/installed and ran their test suites successfully on the first attempt.

Generated by Build Test Suite for #8226 · copilot · auto · 37.9 AIC · ⊞ 12K ·
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

MCP tool connectivity: ❌
GitHub.com connectivity: ✅
File read/write test: ✅
Direct BYOK inference: ✅
Running in direct BYOK mode via api-proxy -> Azure OpenAI (Foundry, o4-mini-aw), authenticated via Microsoft Entra
Overall status: FAIL
@Copilot @lpcox

🪪 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 Sep 7, 2026

Copy link
Copy Markdown
Contributor

@Copilot @lpcox

  • GitHub MCP PRs (docs: add B31 runner-doctor guidance for sudo secure_path PATH shadowing; feat: add dynamic GitHub-MCP-backed enclave repository admission): ❌
  • 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: FAIL

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

@lpcox
lpcox merged commit 12450b5 into main Sep 7, 2026
168 of 175 checks passed
@lpcox
lpcox deleted the copilot/duplicate-code-provider-auth-setup branch September 7, 2026 14:57
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.14 Python 3.12.14 ✅ YES
Node.js v24.20.0 v2.98.0 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

⚠️ Not all versions matched — Node.js reported v2.98.0 in the chroot environment vs v24.20.0 on the host. smoke-chroot label not applied since ALL_TESTS_PASSED=false.

Tested by Smoke Chroot
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.

[Duplicate Code] Copilot and OpenAI provider auth setup repeats branching logic

3 participants