Skip to content

refactor(api-proxy): dedupe Azure OIDC helpers via shared github-oidc module#2887

Merged
lpcox merged 3 commits into
mainfrom
copilot/refactor-oidc-token-provider
May 11, 2026
Merged

refactor(api-proxy): dedupe Azure OIDC helpers via shared github-oidc module#2887
lpcox merged 3 commits into
mainfrom
copilot/refactor-oidc-token-provider

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

Bug Fix

OidcTokenProvider in the Azure path was maintaining a second copy of GitHub OIDC minting/HTTP/proxy helper logic already centralized in github-oidc.js. This change removes that duplicate security-critical implementation so Azure, AWS, and GCP all share the same canonical helper behavior.

What was the bug?

Duplicate helper implementations in containers/api-proxy/oidc-token-provider.js (_mintGitHubOidcToken, _httpGet, _httpPost, _getProxyAgent) created drift risk in OIDC token minting and transport handling.

How did you fix it?

  • Shared helper consolidation

    • Imported shared helpers from containers/api-proxy/github-oidc.js.
    • Replaced Azure-specific reimplementations with shared calls for GitHub OIDC minting and HTTP POST transport.
  • Preserved Azure-specific timeout context

    • Wrapped shared httpPost timeout errors in _exchangeForAzureToken so Azure paths continue to emit Azure token exchange timeout for actionable logs/errors.
  • Dead code removal

    • Removed now-unused class-level _httpGet and _getProxyAgent wrappers after delegating GitHub minting to shared helpers.
  • Regression guards

    • Added focused coverage in oidc-token-provider.test.js asserting Azure mint flow sends:
      • configured audience query param
      • expected Authorization: Bearer <request token> header
    • Added a timeout-context test to ensure Azure timeout messaging is preserved.
    • Hardened the mint-contract server test with try/finally cleanup to always shut down server/provider.
const { mintGitHubOidcToken, httpPost } = require('./github-oidc');

async _mintGitHubOidcToken() {
  return mintGitHubOidcToken({
    requestUrl: this._requestUrl,
    requestToken: this._requestToken,
    audience: this._oidcAudience,
  });
}

Copilot AI changed the title [WIP] Refactor OidcTokenProvider to use existing http helpers refactor(api-proxy): dedupe Azure OIDC helper logic via shared github-oidc module May 11, 2026
Copilot AI requested a review from lpcox May 11, 2026 13:55
Copilot finished work on behalf of lpcox May 11, 2026 13:55
@lpcox lpcox marked this pull request as ready for review May 11, 2026 14:57
@lpcox lpcox requested a review from Mossaka as a code owner May 11, 2026 14:57
Copilot AI review requested due to automatic review settings May 11, 2026 14:57
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 87.84% 87.91% 📈 +0.07%
Statements 87.77% 87.85% 📈 +0.08%
Functions 82.78% 82.78% ➡️ +0.00%
Branches 79.72% 79.76% 📈 +0.04%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/container-lifecycle.ts 87.1% → 88.2% (+1.14%) 87.5% → 88.6% (+1.11%)

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

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

This was referenced May 11, 2026
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 Azure OidcTokenProvider in containers/api-proxy to eliminate duplicated GitHub Actions OIDC minting / HTTP / proxy logic by delegating to the shared github-oidc helper module, aligning Azure with the existing AWS/GCP paths.

Changes:

  • Replaced Azure’s in-file GitHub OIDC mint + HTTP/proxy helper implementations with calls into containers/api-proxy/github-oidc.js.
  • Kept the Azure provider’s public/class method surface while switching implementation to shared helpers.
  • Added a regression test asserting the GitHub OIDC mint request includes the configured audience query parameter and the expected Authorization header.
Show a summary per file
File Description
containers/api-proxy/oidc-token-provider.js Refactors Azure OIDC minting + HTTP/proxy helpers to delegate to the shared github-oidc module.
containers/api-proxy/oidc-token-provider.test.js Adds a focused regression test to validate the GitHub OIDC mint request contract (audience + auth header).

Copilot's findings

Tip

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

Comments suppressed due to low confidence (1)

containers/api-proxy/oidc-token-provider.js:273

  • Similar to _httpGet(), _getProxyAgent() is now unused within this class/repo after moving proxy handling into github-oidc.js. If it’s not meant as a supported override point, consider removing it to avoid dead code.
  /**
   * Build proxy agent from env vars when configured.
   * @param {URL} parsedUrl
   * @returns {import('http').Agent|undefined}
   */
  _getProxyAgent(parsedUrl) {
    return getProxyAgent(parsedUrl);
  }
  • Files reviewed: 2/2 changed files
  • Comments generated: 3

Comment on lines 262 to 264
_httpPost(url, body, headers) {
return new Promise((resolve, reject) => {
const parsedUrl = new URL(url);
const options = {
method: 'POST',
hostname: parsedUrl.hostname,
port: parsedUrl.port || (parsedUrl.protocol === 'https:' ? 443 : 80),
path: parsedUrl.pathname + parsedUrl.search,
headers: { ...headers, 'Content-Length': Buffer.byteLength(body) },
agent: this._getProxyAgent(parsedUrl),
};

const mod = parsedUrl.protocol === 'https:' ? https : http;
const req = mod.request(options, (res) => {
let responseBody = '';
res.on('data', (chunk) => { responseBody += chunk; });
res.on('end', () => resolve({ statusCode: res.statusCode, body: responseBody }));
});
req.on('error', reject);
req.setTimeout(10_000, () => { req.destroy(new Error('Azure token exchange timeout')); });
req.write(body);
req.end();
});
return httpPost(url, body, headers);
}
Comment on lines 245 to 253
req.setTimeout(10_000, () => { req.destroy(new Error('OIDC request timeout')); });
});
return httpGet(url, headers);
}
Comment on lines +125 to +141

await new Promise(resolve => oidcServer.listen(0, '127.0.0.1', resolve));
const oidcPort = oidcServer.address().port;

const provider = new OidcTokenProvider({
requestUrl: `http://127.0.0.1:${oidcPort}/token`,
requestToken: 'custom-request-token',
tenantId: 'test',
clientId: 'test',
oidcAudience: 'api://custom-audience',
});

const token = await provider._mintGitHubOidcToken();
expect(token).toBe('jwt-from-github');

provider.shutdown();
await new Promise(resolve => oidcServer.close(resolve));
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 11, 2026

@copilot address review feedback

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 11, 2026

@copilot address review feedback

Addressed in commit ce97001.

  • Restored Azure-specific timeout context by mapping shared httpPost timeout errors to Azure token exchange timeout in _exchangeForAzureToken.
  • Removed dead _httpGet and _getProxyAgent wrappers from OidcTokenProvider.
  • Hardened the audience/header regression test with try/finally cleanup and added a focused timeout-context test.

Copilot AI changed the title refactor(api-proxy): dedupe Azure OIDC helper logic via shared github-oidc module refactor(api-proxy): dedupe Azure OIDC helpers via shared github-oidc module May 11, 2026
Copilot finished work on behalf of lpcox May 11, 2026 15:18
@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

  • ❌ GitHub MCP (gh CLI auth error)
  • ✅ Playwright (GitHub page verified)
  • ✅ File Writing (test file created)
  • ✅ Bash Tool (file verification passed)

Status: FAIL (gh CLI authentication issue)

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Offline) Mode

Test Result
1. GitHub MCP ❌ 401 Bad credentials (MCP auth unavailable in this runner)
2. GitHub.com connectivity ⚠️ Pre-step data not substituted (template vars unexpanded)
3. File write/read ⚠️ Pre-step data not substituted (template vars unexpanded)
4. BYOK inference ✅ Agent responded via api-proxy → api.githubcopilot.com

Running in BYOK offline mode (COPILOT_OFFLINE=true) via api-proxy → api.githubcopilot.com.

Overall: FAIL — GitHub MCP returned 401; pre-step template variables were not expanded (smoke-data step outputs missing).

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results — PR #2887

Test Result
GitHub MCP connectivity ❌ 401 (unauthenticated in agent env)
GitHub.com HTTP ⚠️ pre-step data not injected
File write/read /tmp/gh-aw/agent/smoke-test-copilot-25679124276.txt confirmed

Overall: PARTIAL — pre-step template variables were not substituted into the agent prompt, so HTTP code and PR data could not be validated. File test passed. MCP auth unavailable in this context.

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

🧪 Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python 3.12.13 3.12.3 ❌ No
Node.js v24.14.1 v20.20.2 ❌ No
Go go1.22.12 go1.22.12 ✅ Yes

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

Tested by Smoke Chroot

@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 ok ✅ PASS
Go env ok ✅ PASS
Go uuid ok ✅ 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

Note (Java): The default Maven local repository path /home/runner/.m2/repository was not writable (owned by root). Tests were run successfully using -Dmaven.repo.local=/tmp/gh-aw/agent/m2-repo as a workaround.

Generated by Build Test Suite for issue #2887 · ● 419K ·

@github-actions
Copy link
Copy Markdown
Contributor

Smoke test: FAIL
PRs: refactor(stats-formatter): make format-specific functions module-private; refactor: split src/cli.ts into focused modules
❌ GitHub MCP / safeinputs-gh checks unavailable
✅ Playwright title contains GitHub
❌ Tavily unavailable
✅ File write + bash readback
❌ Discussion query unavailable, skipped
✅ npm ci && npm run build

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

Smoke Test Results

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

Overall: FAILhost.docker.internal is unreachable from this runner environment. Service containers may not be configured or the host alias is not resolvable.

🔌 Service connectivity validated by Smoke Services

@lpcox lpcox merged commit 7c25298 into main May 11, 2026
66 of 70 checks passed
@lpcox lpcox deleted the copilot/refactor-oidc-token-provider branch May 11, 2026 15:45
lpcox added a commit that referenced this pull request May 11, 2026
The OIDC refactoring PRs (#2811, #2772, #2887) added new JS modules
(github-oidc.js, aws-oidc-token-provider.js, gcp-oidc-token-provider.js,
oidc-refresh-utils.js) but did not update the Dockerfile COPY command.
This caused the api-proxy container to crash immediately on startup
with exit code 1 (Cannot find module './github-oidc'), breaking all
integration tests since commit 7c25298.

Fixes the api-proxy container startup crash that has been failing all
integration test runs on main since 2026-05-11T15:45Z.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lpcox added a commit that referenced this pull request May 11, 2026
… retry handling (#2895)

* Initial plan

* fix: reduce pid-tracker public API surface

* docs: fix stale pid tracker jsdoc

* fix: retry api-proxy startup when compose reports exited (1)

Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/fcf2b573-5256-4c69-8f65-0a79431bd838

* fix(api-proxy): add missing JS modules to Dockerfile COPY

The OIDC refactoring PRs (#2811, #2772, #2887) added new JS modules
(github-oidc.js, aws-oidc-token-provider.js, gcp-oidc-token-provider.js,
oidc-refresh-utils.js) but did not update the Dockerfile COPY command.
This caused the api-proxy container to crash immediately on startup
with exit code 1 (Cannot find module './github-oidc'), breaking all
integration tests since commit 7c25298.

Fixes the api-proxy container startup crash that has been failing all
integration test runs on main since 2026-05-11T15:45Z.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test: restore missing pid-tracker test cases for coverage

Add back tests for malformed /proc/net/tcp rows and non-symlink file
descriptors that were removed when the async trackPidForPort was dropped.
These paths are still exercised in production via trackPidForPortSync
and need coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Landon Cox <landon.cox@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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] OidcTokenProvider reimplements http helpers already exported by github-oidc.js

3 participants