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:
- Deploy function app in Azure China with a LogsQueryClient to access a Log Analytics workspace also in Azure China
- Use client as described above
- Trigger Function App and check if the call was successful
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 10 months ago
- Comments:9 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
Thanks @KarishmaGhiya for your support!
I suspect this is an issue with the wrong endpoint. Let me get back to you on this