Skip to content

fix(aas): honor HTTP_PROXY/HTTPS_PROXY during API key validation#2405

Merged
nina9753 merged 2 commits into
masterfrom
nina.rei/aas-proxy-fix
Jul 15, 2026
Merged

fix(aas): honor HTTP_PROXY/HTTPS_PROXY during API key validation#2405
nina9753 merged 2 commits into
masterfrom
nina.rei/aas-proxy-fix

Conversation

@nina9753

@nina9753 nina9753 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Root cause: validateApiKey() in packages/base/src/helpers/apikey.ts called httpRequest without a dispatcher, so undici's fetch ignored HTTP_PROXY/HTTPS_PROXY. Behind a corporate proxy this caused an ECONNRESET, which was then caught by a blanket catch in instrument.ts and mislabeled as "Invalid API Key".
  • Fix: Pass getProxyDispatcher('') (which returns an EnvHttpProxyAgent reading proxy env vars) into the validateApiKey httpRequest call — the same pattern already used by getRequestBuilder elsewhere in the codebase.
  • Better error message: Split the instrument.ts catch block so a network/proxy failure reports a clear "network error" message with a hint to check HTTP_PROXY/HTTPS_PROXY, instead of the misleading "Invalid API Key" message.

Fixes: SLES-2940

Test plan

  • yarn build — clean
  • yarn test packages/plugin-aas/src/__tests__/instrument.test.ts — passes, including new test for the network-error path
  • Manual: HTTP_PROXY=http://localhost:9 DD_API_KEY=<valid> DD_SITE=datadoghq.com yarn launch aas instrument --resource-id ... → shows "network error" (proxy used, localhost:9 not listening)
  • Manual: DD_API_KEY=<valid> DD_SITE=datadoghq.com yarn launch aas instrument --resource-id ... → passes API key validation, proceeds to Azure auth (no regression)

🤖 Generated with Claude Code

@nina9753 nina9753 requested review from a team as code owners July 14, 2026 14:37
@nina9753 nina9753 requested a review from ava-silver July 14, 2026 14:37
@datadog-official

datadog-official Bot commented Jul 14, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 1caeef5 | Docs | Datadog PR Page | Give us feedback!

@nina9753 nina9753 added serverless Related to [aas, cloud-run, lambda, stepfunctions] bug Something isn't working labels Jul 14, 2026

@ava-silver ava-silver 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.

two quick things before i approve!

Comment thread packages/base/src/helpers/apikey.ts Outdated

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.

Could we add a base helper test that calls the real validateApiKey() and asserts that its httpRequest receives an EnvHttpProxyAgent dispatcher? The existing AAS test should remain because it covers the user-facing network error, but it mocks validateApiKey() and therefore does not verify the proxy wiring itself.

for example:

   test('API key validation uses the environment proxy dispatcher', async () => {
     const httpRequest = jest.spyOn(request, 'httpRequest').mockResolvedValue({
       config: {},
       data: {valid: true},
       headers: {},
       status: 200,
       statusText: 'OK',
     })

     const validator = newApiKeyValidator({
       apiKey: 'api-key',
       datadogSite: 'datadoghq.com',
     })

     await expect(validator.validateApiKey()).resolves.toBe(true)

     expect(httpRequest).toHaveBeenCalledWith(
       expect.objectContaining({
         baseURL: 'https://api.datadoghq.com',
         dispatcher: expect.any(EnvHttpProxyAgent),
       })
     )
   })

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call added packages/base/src/helpers/__tests__/apikey.test.ts which spies on httpRequest directly and asserts an EnvHttpProxyAgent is passed, plus covers the 403, network error, and empty key cases.

@nina9753 nina9753 force-pushed the nina.rei/aas-proxy-fix branch 3 times, most recently from 87778ed to 7b8c796 Compare July 14, 2026 18:34
- Pass getProxyDispatcher('') (EnvHttpProxyAgent) into validateApiKey's
  httpRequest call so undici routes through proxy env vars
- Split instrument.ts catch block to distinguish network/proxy failures
  from a genuinely invalid key, with a clearer error message for each

Rationale: Behind a corporate proxy (e.g. Saint-Gobain), Node's fetch
ignores HTTP_PROXY/HTTPS_PROXY, causing ECONNRESET which was mislabeled
as "Invalid API Key". The fix wires in the existing getProxyDispatcher
helper (already used elsewhere in base) and improves the error message.

This commit made by [/dd:git:commit:quick](https://github.com/DataDog/claude-marketplace/tree/main/dd/commands/git/commit/quick.md)
@nina9753 nina9753 force-pushed the nina.rei/aas-proxy-fix branch from 7b8c796 to 9430d0a Compare July 14, 2026 19:10
@nina9753 nina9753 requested a review from ava-silver July 14, 2026 19:24

@ava-silver ava-silver 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.

one nit on wording but overall lgtm

Comment thread packages/plugin-aas/src/commands/instrument.ts Outdated
Co-authored-by: Ava Silver <ava.silver@datadoghq.com>
@nina9753 nina9753 merged commit c8fc9f4 into master Jul 15, 2026
34 checks passed
@nina9753 nina9753 deleted the nina.rei/aas-proxy-fix branch July 15, 2026 17:25
@nina9753 nina9753 restored the nina.rei/aas-proxy-fix branch July 15, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working serverless Related to [aas, cloud-run, lambda, stepfunctions]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants