Skip to content

Refactor: extract createProviderOidcAuth to unify OIDC setup across provider adapters#5206

Merged
lpcox merged 4 commits into
mainfrom
copilot/fix-duplicate-oidc-credential-flow
Jun 18, 2026
Merged

Refactor: extract createProviderOidcAuth to unify OIDC setup across provider adapters#5206
lpcox merged 4 commits into
mainfrom
copilot/fix-duplicate-oidc-credential-flow

Conversation

Copilot AI commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

All three API proxy provider adapters repeated the same OIDC credential-resolution lifecycle — provider resolution, runtime method creation, and auth-header branching — with Anthropic using a hand-rolled variant that could diverge silently from the others.

New helper: createProviderOidcAuth(env, options)

Added to providers/cloud-oidc-init.js. Bundles the previously scattered three-step pattern into a single call returning:

  • authProvider, oidcProvider, awsOidcProvider, oidcConfigured
  • runtimeMethods — spread directly into the adapter return object
  • validationSkip(), skipModelsFetch() — standard defaults
  • resolveAuthHeaders(buildOidcHeaders, staticHeaders) — OIDC-or-fallback closure (no need to thread providers through)

Accepts an optional oidcProviderFactory(env) for adapters that use a custom token class:

// Before — three separate steps in openai.js and copilot.js
const { authProvider, oidcProvider, awsOidcProvider, oidcConfigured } = resolveCloudOidcProviders(env);
const oidcRuntimeMethods = createOidcRuntimeAdapterMethods({ staticAuthToken: apiKey, oidcProvider, awsOidcProvider });
// ... later in getAuthHeaders():
const oidcHeaders = resolveOidcAuthHeaders({ oidcProvider, awsOidcProvider, buildOidcHeaders: ... });
if (oidcHeaders !== null) return oidcHeaders;
return buildStaticAuthHeaders(apiKey);

// After — one call, resolveAuthHeaders closes over the resolved providers
const { authProvider, oidcConfigured, runtimeMethods: oidcRuntimeMethods, validationSkip, skipModelsFetch, resolveAuthHeaders } =
  createProviderOidcAuth(env, { staticAuthToken: apiKey });
// ... in getAuthHeaders():
return resolveAuthHeaders((token) => ({ Authorization: 'Bearer ' + token }), buildStaticAuthHeaders(apiKey));

Per-adapter changes

  • openai.js: replaces the 2-step setup; getAuthHeaders() uses resolveAuthHeaders(); validationSkip/skipModelsFetch consumed directly from bundle
  • copilot.js: replaces the 2-step setup; getAuthHeaders() retains direct resolveOidcAuthHeaders call (complex multi-path static fallback)
  • anthropic.js: hand-rolled OIDC init replaced with createProviderOidcAuth + oidcProviderFactory; manual isEnabled()/getOidcProvider() replaced by spreading runtimeMethods; hand-rolled auth-header branch replaced with resolveOidcAuthHeaders

Tests

9 new tests for createProviderOidcAuth in cloud-oidc-init.test.js covering: no-OIDC bundle, static-token enablement, Azure provider creation, skipWhen, resolveAuthHeaders (token ready / not ready / unconfigured), custom factory, and factory returning null.

…ication

Closes #5196

Three provider adapters (openai.js, copilot.js, anthropic.js) repeated the
same three-step OIDC credential-resolution pattern:
1. resolveCloudOidcProviders (or hand-rolled equivalent)
2. createOidcRuntimeAdapterMethods
3. resolveOidcAuthHeaders + static fallback in getAuthHeaders()

This commit extracts that pattern into createProviderOidcAuth() in
providers/cloud-oidc-init.js, which bundles all three steps and also exposes
validationSkip(), skipModelsFetch(), and resolveAuthHeaders() defaults.

- openai.js and copilot.js: replace two-step resolveCloudOidcProviders +
  createOidcRuntimeAdapterMethods with a single createProviderOidcAuth() call
- openai.js getAuthHeaders(): simplified using resolveAuthHeaders()
- anthropic.js: replace hand-rolled OIDC setup with createProviderOidcAuth()
  + oidcProviderFactory; replace manual isEnabled()/getOidcProvider() with
  spread runtimeMethods; replace hand-rolled auth header logic with
  resolveOidcAuthHeaders()
- cloud-oidc-init.test.js: 9 new tests for createProviderOidcAuth()
Copilot AI changed the title [WIP] Fix duplicate OIDC credential-resolution flow in API proxy adapters Refactor: extract createProviderOidcAuth to unify OIDC setup across provider adapters Jun 18, 2026
Copilot finished work on behalf of lpcox June 18, 2026 00:46
Copilot AI requested a review from lpcox June 18, 2026 00:46
@lpcox lpcox marked this pull request as ready for review June 18, 2026 00:46
Copilot AI review requested due to automatic review settings June 18, 2026 00:46
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 97.57% 97.61% 📈 +0.04%
Statements 97.50% 97.53% 📈 +0.03%
Functions 98.84% 98.84% ➡️ +0.00%
Branches 92.95% 92.98% 📈 +0.03%
📁 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

Comment thread containers/api-proxy/providers/openai.js Fixed
Comment thread containers/api-proxy/providers/openai.js Fixed

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 refactors the API proxy provider adapters (OpenAI, Copilot, Anthropic) to share a unified cloud OIDC initialization/auth-header resolution flow by introducing a new helper, createProviderOidcAuth, in cloud-oidc-init.js. The goal is to eliminate duplicated OIDC lifecycle code across adapters and standardize behaviors like validation/model-fetch skipping and auth header selection.

Changes:

  • Added createProviderOidcAuth(env, options) helper to bundle provider resolution, runtime adapter methods, and auth-header resolution.
  • Updated openai.js, copilot.js, and anthropic.js to use the helper (Anthropic via a custom oidcProviderFactory).
  • Added Jest coverage for the new helper in cloud-oidc-init.test.js.
Show a summary per file
File Description
containers/api-proxy/providers/cloud-oidc-init.js Introduces createProviderOidcAuth helper that centralizes OIDC setup + header resolution.
containers/api-proxy/providers/openai.js Switches OpenAI adapter OIDC setup/auth headers to use createProviderOidcAuth.
containers/api-proxy/providers/copilot.js Switches Copilot adapter OIDC setup to use createProviderOidcAuth while keeping custom header branching.
containers/api-proxy/providers/anthropic.js Replaces Anthropic’s bespoke OIDC init with createProviderOidcAuth + factory and standard header resolution.
containers/api-proxy/providers/cloud-oidc-init.test.js Adds focused tests for createProviderOidcAuth behavior across configured/unconfigured/factory paths.

Copilot's findings

Tip

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

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

Comment thread containers/api-proxy/providers/cloud-oidc-init.js Outdated
Comment on lines +96 to +100
* @param {((env: Record<string, string|undefined>) => any)|null} [options.oidcProviderFactory]
* Optional factory for providers that use a custom OIDC token class (e.g.
* Anthropic). When provided, takes precedence over `resolveCloudOidcProviders`.
* The factory receives `env` and should return a provider instance or
* `null`/`undefined` when not configured.
Comment thread containers/api-proxy/providers/openai.js
@lpcox

lpcox commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

@github-actions

github-actions Bot commented Jun 18, 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.

Copilot AI commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address review feedback

Addressed in da47e54.

  • Removed unused oidcProvider/awsOidcProvider bindings in openai.js
  • Hardened createProviderOidcAuth to only use oidcProviderFactory when it is a function
  • Tightened oidcProviderFactory JSDoc contract (isReady() + getToken())
  • Added coverage for non-function oidcProviderFactory fallback behavior

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude failed

No user request was provided in this turn — only system reminders listing available skills and project context were received. No action taken.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Contribution Check completed successfully!

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

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

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

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

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

@github-actions

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

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

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

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

Smoke test completed with partial success. Connectivity and MCP failed.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude failed

Smoke test complete - Claude agent initialized successfully with access to project context (gh-aw-firewall / awf CLI) and all expected skills/tools. No task was specified in the prompt, so no action was taken.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

@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 | Auth mode: PAT (COPILOT_GITHUB_TOKEN)

cc @lpcox @Copilot

🔑 PAT report filed by Smoke Copilot PAT

@github-actions

Copy link
Copy Markdown
Contributor

@lpcox Smoke Test Results:

  • MCP connectivity via GitHub MCP tool: ✅
  • GitHub.com connectivity: ✅
  • File write/read in sandbox: ✅
  • Direct BYOK inference (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL): ✅

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

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

@github-actions

Copy link
Copy Markdown
Contributor

@lpcox Smoke test results:

  • MCP PR listing: ✅
  • github.com connectivity: ✅
  • File write/read: ✅
  • BYOK inference path: ✅

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 Results — PASS

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

PR: Refactor: extract createProviderOidcAuth to unify OIDC setup across provider adapters
Author: @CopilotAssignees: @lpcox @Copilot

Overall: ✅ PASS

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

Copy link
Copy Markdown
Contributor

Reviewed merged PRs:

  • ✅ Centralize provider adapter assembly with buildProviderAdapter and enforce isEnabled contract
  • ✅ fix: normalizeUsage maps OpenAI prompt_tokens_details.cached_tokens to cache_read_tokens
  • ✅ Playwright title check
  • ✅ File write/read check
  • ✅ Build check
    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

🏗️ 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 #5206 ·

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: API Proxy OpenTelemetry Tracing

Scenario Result Notes
1. Module Loading ✅ Pass otel.js loads cleanly; exports: startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled + private helpers
2. Test Suite ✅ Pass 59 tests passed, 0 failed across 2 suites (otel.test.js, otel-fanout.test.js)
3. Env Var Forwarding ✅ Pass src/services/api-proxy-service-config.ts forwards OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, GITHUB_AW_OTEL_TRACE_ID, GITHUB_AW_OTEL_PARENT_SPAN_ID, OTEL_SERVICE_NAME to api-proxy container
4. Token Tracker Integration ✅ Pass onUsage callback present in token-tracker-http.js (line 283); invoked after normalized usage extraction as the OTEL hook point
5. OTEL Diagnostics ✅ Pass Graceful degradation confirmed: when OTEL_EXPORTER_OTLP_ENDPOINT is unset, spans fall back to /var/log/api-proxy/otel.jsonl; no errors on unconfigured runs

All 5 scenarios pass. OTEL integration is functioning correctly.

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Gemini Engine Validation. Results: MCP: ❌, Connectivity: ❌, File: ✅, Bash: ✅. 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

Chroot Version Comparison Results

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

Overall: ❌ FAILED — Python and Node.js versions differ between host and chroot environments.

Tested by Smoke Chroot

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: GitHub Actions Services Connectivity

Check Result
Redis PING ❌ timeout (no response)
PostgreSQL pg_isready ❌ no response
PostgreSQL SELECT 1 ❌ timeout (no response)

Overall: FAILhost.docker.internal is not reachable from this runner; service containers appear unavailable.

🔌 Service connectivity validated by Smoke Services

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct) Mode ✅ PASS

  • ✅ GitHub MCP connectivity (PR list verified)
  • ✅ GitHub.com connectivity (HTTP 200)
  • ✅ File write/read test (temp file)
  • ✅ BYOK inference test (running in direct BYOK mode)

Mode: Direct BYOK (COPILOT_DUMMY_BYOK) via api-proxy sidecar → api.githubcopilot.com

@lpcox @Copilot

🔑 BYOK report filed by Smoke Copilot BYOK

@lpcox lpcox merged commit 069d5e1 into main Jun 18, 2026
82 of 85 checks passed
@lpcox lpcox deleted the copilot/fix-duplicate-oidc-credential-flow branch June 18, 2026 02:29
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.

4 participants