Skip to content

Refactor API proxy providers to share OIDC/static auth adapter scaffold - #6608

Merged
lpcox merged 2 commits into
mainfrom
copilot/fix-duplicate-code-auth-scaffolding
Jul 26, 2026
Merged

Refactor API proxy providers to share OIDC/static auth adapter scaffold#6608
lpcox merged 2 commits into
mainfrom
copilot/fix-duplicate-code-auth-scaffolding

Conversation

Copilot AI commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

OpenAI, Anthropic, and Copilot adapters were independently rebuilding the same OIDC/static-auth bootstrap path (auth scaffold, OIDC header strategy wiring, adapter method composition, and provider adapter assembly). This duplicated security-sensitive credential-selection behavior across three modules and increased drift risk.

  • Problem surface reduced

    • Consolidated repeated auth/bootstrap orchestration into a single shared factory path.
    • Kept provider-specific behavior (headers, validation/model-fetch semantics, unconfigured responses, reflection metadata) in provider modules.
  • Shared scaffold extraction

    • Added createOidcAwareProviderAdapter(...) in containers/api-proxy/adapter-factory.js.
    • The helper now owns:
      • OIDC strategy initialization (createProviderOidcHeaderStrategy)
      • Runtime method propagation (isEnabled, OIDC provider accessors)
      • default/custom auth-header resolution wiring
      • createAdapterMethods(...) + buildProviderAdapter(...) composition
  • Provider migrations

    • Updated:
      • providers/openai.js
      • providers/anthropic.js
      • providers/copilot.js
    • Each adapter now supplies only provider-specific hooks/options to the shared helper, preserving existing behavior while removing duplicated scaffold code.
  • Focused coverage for new shared path

    • Extended containers/api-proxy/adapter-factory.test.js with targeted tests for:
      • static-auth wiring via shared helper
      • OIDC-mode custom getAuthHeaders path and runtime method exposure
return createOidcAwareProviderAdapter({
  env,
  oidcAuthOptions: { staticAuthToken: apiKey },
  buildOidcHeaders: buildTokenAuthHeaders,
  buildStaticHeaders: buildStaticAuthHeaders,
  createAdapterMethodsOptions: ({ authProvider, oidcConfigured, validationSkip, skipModelsFetch }) => ({ ... }),
  buildAdapterOptions: ({ oidcConfigured }) => ({ ... }),
});

Copilot AI changed the title [WIP] Fix duplicate code in auth scaffolding across provider adapters Refactor API proxy providers to share OIDC/static auth adapter scaffold Jul 26, 2026
Copilot finished work on behalf of lpcox July 26, 2026 16:11
Copilot AI requested a review from lpcox July 26, 2026 16:11
@lpcox
lpcox marked this pull request as ready for review July 26, 2026 16:13
Copilot AI review requested due to automatic review settings July 26, 2026 16:13

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

Centralizes duplicated OIDC/static-auth adapter construction while preserving provider-specific behavior.

Changes:

  • Adds a shared OIDC-aware adapter factory.
  • Migrates OpenAI, Anthropic, and Copilot providers.
  • Adds focused factory tests for static and OIDC authentication paths.
Show a summary per file
File Description
containers/api-proxy/adapter-factory.js Adds the shared adapter scaffold.
containers/api-proxy/adapter-factory.test.js Tests static and OIDC factory behavior.
containers/api-proxy/providers/openai.js Migrates OpenAI to the shared factory.
containers/api-proxy/providers/anthropic.js Migrates Anthropic while retaining custom headers and responses.
containers/api-proxy/providers/copilot.js Migrates Copilot while retaining dual-auth behavior.

Review details

Tip

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

  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Medium

@github-actions

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

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 99.12% 99.15% 📈 +0.03%
Statements 99.03% 99.06% 📈 +0.03%
Functions 99.52% 99.52% ➡️ +0.00%
Branches 95.60% 95.60% ➡️ +0.00%
📁 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 Jul 26, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude passed

@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Contribution Check completed successfully!

Contribution check complete — PR #6608 appears to follow the applicable guidelines in CONTRIBUTING.md. It includes targeted tests for the new shared adapter path, references related issue #6598, and keeps new code in the correct containers/api-proxy location. No comment needed.

@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Security Guard failed. Please review the logs for details.

@github-actions

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

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

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

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Smoke Test Results

Test Status
GitHub MCP connectivity ⚠️ PR data filtered by secrecy policy
GitHub.com connectivity ✅ (pre-step passed)
File write/read smoke-test-copilot-30211745516.txt verified

Overall: PASS (core engine functional)

@lpcox — smoke test complete on PR #6608.

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

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct) Mode ✅

Test Results:

  • ✅ MCP Connectivity: GitHub API responding
  • ✅ BYOK Inference Path: Agent operational via api-proxy → api.githubcopilot.com
  • ✅ Direct BYOK Mode: COPILOT_PROVIDER_API_KEY forwarded to sidecar

Status: PASS — Direct BYOK mode confirmed working

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

@github-actions

Copy link
Copy Markdown
Contributor

Smoke test: Copilot Network Isolation Egress Enforcement — @lpcox

EGRESS_RESULT allow=pass deny=pass

  • ✅ Allowed domain (api.github.com): HTTP 200
  • ✅ Blocked domain (example.com): connection denied (403 from proxy)

Overall: PASS

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 added the smoke-copilot-network-isolation Copilot network-isolation egress smoke test label Jul 26, 2026
@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 #6608 · haiku45 · 31 AIC · ⊞ 6.3K ·
Add label ready-for-aw to run again

@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.13 ✅ YES
Node.js v24.18.0 v22.23.1 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

Overall: ❌ FAILED — Node.js version mismatch (host: v24.18.0, chroot: v22.23.1).

Tested by Smoke Chroot
Add label ready-for-aw to run again

@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
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: API Proxy OpenTelemetry Tracing

Scenario Status Detail
S1: Module Loading otel.js loads successfully; exports: startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled + internal helpers
S2: Test Suite 59 tests passed, 0 failed across otel.test.js and otel-fanout.test.js
S3: Env Var Forwarding src/services/api-proxy-env-config.test.ts confirms OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, GITHUB_AW_OTEL_TRACE_ID, GITHUB_AW_OTEL_PARENT_SPAN_ID, OTEL_SERVICE_NAME are all forwarded to the api-proxy container
S4: Token Tracker Integration onUsage callback exists in token-tracker-http.js (line 348/406) as the OTEL hook point
S5: OTEL Diagnostics ⏭️ No OTEL endpoint configured in this run; graceful degradation path exercised (no errors)

Result: All scenarios pass. OTEL tracing integration is functional — module loads, spans are created with correct attributes (GenAI semantic conventions), env vars are forwarded, onUsage hook is in place, and graceful degradation works when unconfigured.

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

@github-actions

Copy link
Copy Markdown
Contributor

✅ [Test Coverage] src/upstream-proxy.ts – port-out-of-range branch
✅ test: drop stale smoke-copilot-pat references
✅ GitHub reads
✅ GitHub homepage title
✅ Smoke file
✅ Build
❌ Discussion comment unavailable

Overall: FAIL

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
Add label ready-for-aw to run again

@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 #6608 · sonnet46 · 47.8 AIC · ⊞ 8.3K ·
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

@lpcox

Smoke Test Results for Direct BYOK Mode (Azure OpenAI, Foundry):

  • GitHub MCP connectivity: ❌ (MCP error)
  • GitHub.com connectivity: ✅
  • File I/O: ✅
  • Direct 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

@github-actions

Copy link
Copy Markdown
Contributor

@lpcox Smoke test results:

  • GitHub MCP connectivity: ✅
  • 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)
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smoke Test: Docker Sbx Validation

Test Result
GitHub MCP connectivity ✅ (MCP reachable, PR data filtered by secrecy policy)
GitHub.com HTTP ⚠️ Pre-step data not interpolated
File write/read ⚠️ Pre-step data not interpolated

Note: Template variables (${{ steps.smoke-data.outputs.* }}) were not interpolated — pre-computed step outputs were not passed to the agent. MCP connectivity confirmed.

Overall status: PARTIAL / INCONCLUSIVE

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

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results — Services Connectivity

Check Result
Redis PING host.docker.internal name resolution failed
PostgreSQL pg_isready ❌ No response
PostgreSQL SELECT 1 ❌ Name resolution failed

Overall: FAILhost.docker.internal is not resolvable in this environment. Service containers are unreachable.

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

@lpcox
lpcox merged commit 3dd7d19 into main Jul 26, 2026
136 of 140 checks passed
@lpcox
lpcox deleted the copilot/fix-duplicate-code-auth-scaffolding branch July 26, 2026 21:12
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] OIDC/static auth scaffolding repeats across provider adapters

3 participants