Skip to content

refactor: extract shared auth header resolution helper for provider adapters#5641

Merged
lpcox merged 2 commits into
mainfrom
refactor/dry-provider-auth-headers-5620
Jun 28, 2026
Merged

refactor: extract shared auth header resolution helper for provider adapters#5641
lpcox merged 2 commits into
mainfrom
refactor/dry-provider-auth-headers-5620

Conversation

@lpcox

@lpcox lpcox commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add resolveAuthHeadersWithFallback() to oidc-adapter-utils.js, encapsulating the repeated OIDC-check-then-static-fallback pattern used across provider adapters.

New helper

resolveAuthHeadersWithFallback({ oidcProvider, awsOidcProvider, buildOidcHeaders, staticHeaders })
  1. OIDC token available → use buildOidcHeaders(token)
  2. OIDC configured but no token → return {} (fail-safe)
  3. No OIDC → return staticHeaders

Changes

  • oidc-adapter-utils.js: Added resolveAuthHeadersWithFallback helper
  • providers/anthropic.js: Simplified validationHeaders and modelsFetchHeaders using the new helper (eliminated 2 instances of duplicated OIDC/static branching)

Benefits

  • Auth header construction patterns now have a single reusable abstraction
  • Provider adapters can be simplified to one-liner calls for standard auth
  • Security audit surface reduced: OIDC/static fallback semantics in one place

Testing

  • Manual unit assertions pass for all three code paths
  • Dockerfile copy coverage passes

Closes #5620

…dapters

Add resolveAuthHeadersWithFallback() to oidc-adapter-utils.js, which
encapsulates the repeated OIDC-check-then-static-fallback pattern used
across provider adapters.

Updated Anthropic adapter to use the new helper for validationHeaders
and modelsFetchHeaders, eliminating duplicated OIDC/static branching.

The new helper combines resolveOidcAuthHeaders() with static-key fallback
into a single call:
1. OIDC token available → use buildOidcHeaders(token)
2. OIDC configured but no token → return {} (fail-safe)
3. No OIDC → return staticHeaders

Closes #5620

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 28, 2026 16:32
@github-actions

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 98.25% 98.28% 📈 +0.03%
Statements 98.17% 98.21% 📈 +0.04%
Functions 99.53% 99.53% ➡️ +0.00%
Branches 94.00% 94.00% ➡️ +0.00%
📁 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

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 auth header construction by adding a shared helper for the “OIDC headers when available, otherwise safe fallback” resolution pattern, and then using it to simplify Anthropic’s startup-time header builders.

Changes:

  • Added resolveAuthHeadersWithFallback() to containers/api-proxy/oidc-adapter-utils.js to encapsulate OIDC vs static header selection (including the “OIDC configured but token not ready → {}” fail-safe).
  • Updated containers/api-proxy/providers/anthropic.js to use the new helper for validationHeaders and modelsFetchHeaders, reducing duplicated branching.
Show a summary per file
File Description
containers/api-proxy/oidc-adapter-utils.js Introduces resolveAuthHeadersWithFallback() and exports it for provider adapters.
containers/api-proxy/providers/anthropic.js Refactors validation/model-fetch header construction to call the shared helper and then layer Anthropic-specific headers.

Review details

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment on lines +107 to +113
function resolveAuthHeadersWithFallback({ oidcProvider, awsOidcProvider, buildOidcHeaders, staticHeaders }) {
const oidcHeaders = resolveOidcAuthHeaders({ oidcProvider, awsOidcProvider, buildOidcHeaders });
if (oidcHeaders !== null) {
return oidcHeaders;
}
return staticHeaders;
}
@lpcox

lpcox commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot run pr-finisher skill

@github-actions

Copy link
Copy Markdown
Contributor

⏳ Copilot review left inline comments.

@lpcox To proceed:

  1. Ask @copilot to address the review feedback (reply to this comment or the review thread)
  2. Once the fix is pushed, add the ready-for-aw label to trigger agentic CI smoke tests

@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

@github-actions

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

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Contribution Check completed successfully!

Contribution guidelines review complete for PR #5641: no important gaps found. The PR includes tests for the new helper, has a clear description referencing #5620, and keeps changes in appropriate container/API proxy files.

@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude passed

@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

Smoke test completed with partial failures. File writing and bash tools passed, but GitHub connectivity and MCP reads failed.

@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

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

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Security Guard completed successfully!

Security review complete: PR #5641 describes OIDC adapter refactoring (oidc-adapter-utils.js, providers/anthropic.js). These are not firewall security-critical files (host-iptables.ts, setup-iptables.sh, squid-config.ts, docker-manager.ts, entrypoint.sh, domain-patterns.ts). No security weakening detected in firewall components.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smoke Test Results

PR: refactor: extract shared auth header resolution helper for provider adapters
Author: @lpcox | Assignees: none

Test Result
GitHub MCP connectivity
GitHub.com HTTP ✅ (200)
File write/read ❌ (pre-step data unresolved)

Overall: FAIL — pre-step template variables were not substituted (${{ steps.smoke-data.outputs.* }}), so file test could not be verified.

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct) Mode — PASS ✅

  • ✅ GitHub MCP: MCP connectivity verified (merged PRs fetched)
  • ✅ GitHub.com: HTTP 200 from github.com
  • ✅ File I/O: Write/read in agent directory works
  • ✅ BYOK Inference: Running in direct mode (COPILOT_PROVIDER_API_KEY)

Mode: Direct BYOK via api-proxy sidecar → api.githubcopilot.com
Author: @lpcox

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

Copy link
Copy Markdown
Contributor

@lpcox

  • PR: ✅
  • GitHub MCP PR lookup ✅
  • GitHub.com HTTP reachability ✅
  • File I/O test ✅
  • Direct BYOK inference ✅

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

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

@github-actions

Copy link
Copy Markdown
Contributor
  • fix: only count inference calls against maxRuns limit
  • chore: upgrade gh-aw to v0.81.6 and recompile all workflows
  • refactor: extract shared auth header resolution helper for provider adapters
  • refactor: deduplicate OIDC auth env var mappings via shared constant
  • 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

@lpcox Smoke test results:\n- GitHub MCP Testing: ✅\n- GitHub.com Connectivity: ✅\n- File Write/Read Test: ✅\n- BYOK Inference Test: ✅\nRunning 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\nOverall: 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 cleanly; exports: startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled + test helpers
2. Test Suite 59/59 passedotel.test.js 39/39, otel-fanout.test.js 20/20
3. Env Var Forwarding api-proxy-env-config.ts forwards GH_AW_OTLP_ENDPOINTS, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, GITHUB_AW_OTEL_TRACE_ID, GITHUB_AW_OTEL_PARENT_SPAN_ID, OTEL_SERVICE_NAME
4. Token Tracker Integration onUsage callback present in token-tracker-http.js (line 283, invoked at line 324)
5. OTEL Diagnostics isEnabled() returns true; falls back to FileSpanExporter/var/log/api-proxy/otel.jsonl when no OTLP endpoint configured

All scenarios pass. OTEL tracing is always-on with graceful file-based fallback when no collector endpoint is set.

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine Validation

  • API status: ✅ PASS
  • gh check: ✅ PASS
  • File status: ✅ PASS

Overall result: PASS

Generated by Smoke Claude for #5641 · 36.1 AIC · ⊞ 3.3K ·

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

Overall: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot environments.

Tested by Smoke Chroot

@github-actions

Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results — Auth mode: PAT (COPILOT_GITHUB_TOKEN)

PR by @lpcox

Test Result
GitHub MCP connectivity ✅ PASS
GitHub.com HTTP connectivity ❌ Data unavailable (template vars not expanded)
File write/read ❌ Data unavailable (template vars not expanded)

Overall: FAIL — workflow template variables (${{ steps.smoke-data.outputs.* }}) were not substituted before agent execution.

🔑 PAT report filed by Smoke Copilot PAT

@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 unreachable from this runner environment. Service containers are not accessible.

🔌 Service connectivity validated by Smoke Services

@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 #5641 · 64.5 AIC · ⊞ 7.8K ·

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results: Gemini Engine

  • GitHub MCP Testing: ❌ (Tools not found/Server unreachable)
  • GitHub.com Connectivity: ❌ (Squid 400 Bad Request / SSL 35)
  • File Writing Testing: ✅ (File created successfully)
  • Bash Tool Testing: ✅ (Command execution verified)

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

@lpcox lpcox merged commit 2d61e91 into main Jun 28, 2026
88 checks passed
@lpcox lpcox deleted the refactor/dry-provider-auth-headers-5620 branch June 28, 2026 17:09
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] Provider auth header construction is repeated across API proxy adapters

3 participants