question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ManagedIdentityCredential authentication failed in AzureChina when starting from function app

See original GitHub issue
  • Package Name: @azure/identity
  • Package Version: 3.1.1
  • Operating system:
  • nodejs
    • version: azure function app v4

Describe the bug I have a function app that queries data from Log Analytics. For Azure Public everything works fine, but in Azure China I’m getting the error:

Result: Failure
Exception: ManagedIdentityCredential authentication failed. Status code: 500
More details:
undefined Status code: 500
More details:
undefined
Stack: AuthenticationError: ManagedIdentityCredential authentication failed. Status code: 500
More details:
undefined Status code: 500
More details:
undefined
at ManagedIdentityCredential.getToken (/home/site/wwwroot/node_modules/@azure/identity/dist/index.js:2276:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async tryGetAccessToken (/home/site/wwwroot/node_modules/@azure/core-rest-pipeline/dist/index.js:1994:32)
at async beginRefresh (/home/site/wwwroot/node_modules/@azure/core-rest-pipeline/dist/index.js:2002:17)
at async Object.defaultAuthorizeRequest [as authorizeRequest] (/home/site/wwwroot/node_modules/@azure/core-rest-pipeline/dist/index.js:2125:25)
at async Object.sendRequest (/home/site/wwwroot/node_modules/@azure/core-rest-pipeline/dist/index.js:2176:13)
at async AzureLogAnalytics.sendOperationRequest (/home/site/wwwroot/node_modules/@azure/core-client/dist/index.js:1920:33)
at async getRawResponse (/home/site/wwwroot/node_modules/@azure/monitor-query/dist/index.js:2628:26)
at async /home/site/wwwroot/node_modules/@azure/monitor-query/dist/index.js:2570:51
at async Object.withSpan (/home/site/wwwroot/node_modules/@azure/core-tracing/dist/index.js:140:28)

The function app is deployed in Azure China and wants to query a log analytics workspace in Azure china. The app has a principal id, which has the needed rights to access the log analytics workspace. The code for the logs query looks like this:

const credential = new DefaultAzureCredential({ authorityHost: AzureAuthorityHosts.AzureChina });
const logsQueryClient = new LogsQueryClient(credential);
const result = await logsQueryClient.queryWorkspace(...)

Instead of DefaultAzureCredential I also tried ManagedIdentityCredential but with the same 500 error.

To Reproduce Steps to reproduce the behavior:

  1. Deploy function app in Azure China with a LogsQueryClient to access a Log Analytics workspace also in Azure China
  2. Use client as described above
  3. Trigger Function App and check if the call was successful

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
prb1337commented, Dec 7, 2022

I figured it out, the problem is that you have to set the endpoint in the LogsQueryClient as well as the authorityHost in the credential options:

const options: DefaultAzureCredentialClientIdOptions = {
    loggingOptions: { allowLoggingAccountIdentifiers: true },
    authorityHost: AzureAuthorityHosts.AzureChina,
  };

const credential = new DefaultAzureCredential(options);

const client = new LogsQueryClient(credential, {
      endpoint: "https://api.loganalytics.azure.cn/",
 });

Thanks @KarishmaGhiya for your support!

0reactions
KarishmaGhiyacommented, Dec 5, 2022

I suspect this is an issue with the wrong endpoint. Let me get back to you on this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to use 'User-managed identity' with Azure Function App
I have followed the steps listed in the doc here and have also double checked the function app does have IDENTITY_ENDPOINT and IDENTITY_HEADER ......
Read more >
ManagedIdentityCredential authentication failed.
Azure function app : ManagedIdentityCredential authentication failed. While updating the digitaltwin instance using the function app I am ...
Read more >
DefaultAzureCredential authentication failed #13564 - GitHub
Our deployed application wants to call Microsoft. ... AuthenticationFailedException: ManagedIdentityCredential authentication failed.
Read more >
User Assigned Managed Identity in Azure Functions with ...
Exception while executing function: MyFunction ManagedIdentityCredential authentication failed: No MSI found for specified ClientId/ResourceId.
Read more >
Azure Identity 201 - DefaultAzureCredential Options
There's so much context you have to learn about app types, flows, ... When an Azure service authentication fails and the resource is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found