feat(api-proxy): harden Copilot BYOK resolution and add Azure provider routing#4162
feat(api-proxy): harden Copilot BYOK resolution and add Azure provider routing#4162Copilot wants to merge 6 commits into
Conversation
COPILOT_API_KEY as a BYOK upstream credential
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (2 files)
Coverage comparison generated by |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR updates AWF’s Copilot BYOK credential resolution so that resolveCopilotApiKey() no longer treats COPILOT_API_KEY (Copilot CLI session auth / sentinel-prone) as an upstream BYOK credential, aligning BYOK key lookup to COPILOT_PROVIDER_API_KEY and adding deprecation signaling when legacy-only env is detected.
Changes:
- Updated
resolveCopilotApiKey()to read onlyCOPILOT_PROVIDER_API_KEYand ignoreCOPILOT_API_KEY(with a one-time warning). - Added a process-local “warn once” latch plus a reset helper for tests.
- Updated unit tests and CLI env-resolution tests to reflect provider-only BYOK semantics and warning behavior.
Show a summary per file
| File | Description |
|---|---|
src/copilot-api-resolver.ts |
Switches BYOK key resolution to provider-only and adds one-time deprecation warning behavior. |
src/copilot-api-resolver.test.ts |
Updates resolver tests for new precedence/ignore rules and warning latch behavior. |
src/cli.test.ts |
Updates CLI env-resolution expectations to match provider-only BYOK key semantics. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 2
| let copilotApiKeyDeprecationWarned = false; | ||
|
|
||
| export function __resetCopilotApiKeyDeprecationLatchForTesting(): void { | ||
| copilotApiKeyDeprecationWarned = false; | ||
| } |
| if (env.COPILOT_API_KEY !== undefined && !copilotApiKeyDeprecationWarned) { | ||
| logger.warn( | ||
| 'COPILOT_API_KEY is deprecated for BYOK and will be ignored; use COPILOT_PROVIDER_API_KEY and COPILOT_PROVIDER_BASE_URL instead.' | ||
| ); | ||
| copilotApiKeyDeprecationWarned = true; | ||
| } |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
COPILOT_API_KEY as a BYOK upstream credentialCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
When resolveCopilotApiKey() returns undefined (no COPILOT_PROVIDER_API_KEY on host), the copilotGithubToken path still needs COPILOT_OFFLINE=true, COPILOT_PROVIDER_BASE_URL, and COPILOT_PROVIDER_API_KEY placeholder to be set in the agent container. Without these, the Copilot CLI runs in online mode, enforcing MCP server policies and using stream_options — both of which cause failures in the AWF sandbox. The offline+BYOK block now fires when either copilotApiKey OR copilotGithubToken is present, matching the pre-existing behavior where the old resolver returned the dummy sentinel as a truthy value. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@copilot update the pr summary to reflect all commits and their motivations |
Updated summary to reflect all commits and motivations:
If you want, I can also condense this into a shorter 2–3 bullet PR description format. |
|
@copilot address review feedback unless it undoes subsequent commits #4162 (review) |
Addressed in
|
Smoke Test: Claude Engine
Result: PASS (3/3)
|
🔭 Smoke Test: API Proxy OpenTelemetry Tracing
All scenarios pass. OTEL tracing integration is complete and working.
|
🔍 Smoke Test Results
Overall: PARTIAL — MCP confirmed working; pre-step outputs not injected (template vars unexpanded). PR: feat(api-proxy): harden Copilot BYOK resolution and add Azure provider routing
|
🔥 Smoke Test: Copilot BYOK (Offline) Mode
Running in BYOK offline mode ( PR: feat(api-proxy): harden Copilot BYOK resolution and add Azure provider routing — author Overall: PARTIAL (2/2 verifiable tests pass; 2 tests had unresolved CI template variables)
|
|
Smoke test results:\n- Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
|
Smoke test FAIL: GitHub MCP missing. Connectivity PASS (via proxy). File/Bash PASS. Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "localhost"See Network Configuration for more information.
|
Chroot Version Comparison
Result: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Smoke Test Results
Overall: FAIL —
|
|
@zarenner can you take a look at this? based on your pr + updated to avoid the cli mcp check |
resolveCopilotApiKey()no longer treatsCOPILOT_API_KEYas an upstream BYOK credential, aligning BYOK key lookup with the documented provider path (COPILOT_PROVIDER_API_KEY/COPILOT_PROVIDER_BASE_URL).This PR also includes follow-up fixes needed to preserve offline behavior and adds Azure OpenAI BYOK routing support in the API proxy.
What changed
BYOK resolver behavior
resolveCopilotApiKey()now reads onlyCOPILOT_PROVIDER_API_KEY.COPILOT_PROVIDER_API_KEYis unset andCOPILOT_API_KEYis set, the resolver returnsundefined(legacy key is not forwarded).Offline + BYOK compatibility fix
copilotGithubTokenpath when host-side provider key is absent.Azure OpenAI/Cognitive Services BYOK routing
api-keyheader auth for Azure targets (instead of Bearer).api-versionquery param (default2024-10-21, configurable).copilotProviderTargetoptions (includingbasePathandazureApiVersion), plus related docs updates.Security maintenance
Test updates