Azure / Azure/azure-functions-dotnet-worker
Exception when running ServiceBusTrigger with managed identity locally
- Dominant language
- C#
- Stars
- 466
- Forks
- 215
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 7
Description
### Description
When we run our functions that use ServiceBus Trigger locally we get an error log, but the function continues to run and connects to ServiceBus.
The error we see is:
```
False MSAL 4.56.0.0 MSAL.NetCore .NET 6.0.26 Microsoft Windows 10.0.22631 [2024-04-04 11:20:59Z - a5b037bc-4ded-4814-93cc-b888ba93c78f] Exception type: Azure.Identity.CredentialUnavailableException
[2024-04-04T11:20:59.554Z] ---> Inner Exception Details
[2024-04-04T11:20:59.554Z] Exception type: System.AggregateException
[2024-04-04T11:20:59.555Z] ---> Inner Exception Details
[2024-04-04T11:20:59.556Z] Exception type: Azure.RequestFailedException
[2024-04-04T11:20:59.557Z] ---> Inner Exception Details
[2024-04-04T11:20:59.558Z] Exception type: System.Net.Http.HttpRequestException
[2024-04-04T11:20:59.558Z] ---> Inner Exception Details
[2024-04-04T11:20:59.559Z] Exception type: System.Net.Sockets.SocketException
[2024-04-04T11:20:59.560Z]
[2024-04-04T11:20:59.560Z] at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
[2024-04-04T11:20:59.561Z] at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
[2024-04-04T11:20:59.562Z] at System.Net.Sockets.Socket.g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
[2024-04-04T11:20:59.562Z] at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
[2024-04-04T11:20:59.563Z] === End of inner exception stack trace ===
[2024-04-04T11:20:59.564Z]
[2024-04-04T11:20:59.564Z] at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
[2024-04-04T11:20:59.565Z] at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
[2024-04-04T11:20:59.566Z] at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
[2024-04-04T11:20:59.566Z] at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage request)
[2024-04-04T11:20:59.567Z] at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
[2024-04-04T11:20:59.568Z] at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
[2024-04-04T11:20:59.568Z] at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
[2024-04-04T11:20:59.569Z] at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
[2024-04-04T11:20:59.570Z] at Azure.Core.Pipeline.HttpClientTransport.ProcessAsync(HttpMessage message, Boolean async)
[2024-04-04T11:20:59.570Z] === End of inner exception stack trace ===
[2024-04-04T11:20:59.571Z]
[2024-04-04T11:20:59.572Z] at Azure.Core.Pipeline.HttpClientTransport.ProcessAsync(HttpMessage message, Boolean async)
[2024-04-04T11:20:59.572Z] at Azure.Core.Pipeline.HttpPipelineTransportPolicy.ProcessAsync(HttpMessage message, ReadOnlyMemory`1 pipeline)
[2024-04-04T11:20:59.573Z] at Azure.Core.Pipeline.ResponseBodyPolicy.ProcessAsync(HttpMessage message, ReadOnlyMemory`1 pipeline, Boolean async)
[2024-04-04T11:20:59.574Z] at Azure.Core.Pipeline.LoggingPolicy.ProcessAsync(HttpMessage message, ReadOnlyMemory`1 pipeline, Boolean async)
[2024-04-04T11:20:59.575Z] at Azure.Core.Pipeline.RedirectPolicy.ProcessAsync(HttpMessage message, ReadOnlyMemory`1 pipeline, Boolean async)
[2024-04-04T11:20:59.575Z] at Azure.Core.Pipeline.RetryPolicy.ProcessAsync(HttpMessage message, ReadOnlyMemory`1 pipeline, Boolean async)
[2024-04-04T11:20:59.576Z] === End of inner exception stack trace ===
[2024-04-04T11:20:59.577Z]
[2024-04-04T11:20:59.577Z] at Azure.Core.Pipeline.RetryPolicy.ProcessAsync(HttpMessage message, ReadOnlyMemory`1 pipeline, Boolean async)
[2024-04-04T11:20:59.578Z] at Azure.Identity.ManagedIdentitySource.AuthenticateAsync(Boolean async, TokenRequestContext context, CancellationToken cancellationToken)
[2024-04-04T11:20:59.579Z] at Azure.Identity.ImdsManagedIdentitySource.AuthenticateAsync(Boolean async, TokenRequestContext context, CancellationToken cancellationToken)
[2024-04-04T11:20:59.579Z] === End of inner exception stack trace ===
[2024-04-04T11:20:59.580Z]
[2024-04-04T11:20:59.580Z] at Azure.Identity.ImdsManagedIdentitySource.AuthenticateAsync(Boolean async, TokenRequestContext context, CancellationToken cancellationToken)
[2024-04-04T11:20:59.581Z] at Azure.Identity.ManagedIdentityClient.AuthenticateCoreAsync(Boolean async, TokenRequestContext context, CancellationToken cancellationToken)
[2024-04-04T11:20:59.582Z] at Azure.Identity.ManagedIdentityClient.AppTokenProviderImpl(AppTokenProviderParameters parameters)
[2024-04-04T11:20:59.583Z] at Microsoft.Identity.Client.Internal.Requests.ClientCredentialRequest.SendTokenRequestToAppTokenProviderAsync(ILoggerAdapter logger, CancellationToken cancellationToken)
[2024-04-04T11:20:59.583Z] at Microsoft.Identity.Client.Internal.Requests.ClientCredentialRequest.GetAccessTokenAsync(CancellationToken cancellationToken, ILoggerAdapter logger)
[2024-04-04T11:20:59.584Z] at Microsoft.Identity.Client.Internal.Requests.ClientCredentialRequest.ExecuteAsync(CancellationToken cancellationToken)
[2024-04-04T11:20:59.585Z] at Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync(CancellationToken cancellationToken)
```
My local config for service bus is:
``` "ServiceBusTriggerConnection__fullyQualifiedNamespace": "xxx-yyy-local.servicebus.windows.net",```
The example function signature where we see this:
```[Function(nameof(DeleteContentFunction))]public async Task Run([ServiceBusTrigger("%DeleteContentTopic%", "%DeleteContentSubscription%", Connection = "ServiceBusTriggerConnection")] string messageString)```
We aren't sure why we get this error, but I confirmed that it's showing up only in case of SB Trigger and managed identity.
### Steps to reproduce
Run function locally.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the ServiceBusTrigger binding and the ServiceBusTriggerConnection__fullyQualifiedNamespace configuration shown in the report, then reproduce the local run with managed identity. Compare the authentication path for the trigger with the reported Azure.Identity exception; done means the local trigger no longer emits this exception while continuing to connect to Service Bus.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- authentication, backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100