Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.25k stars 4.6k forks source link

[QUERY][ServiceBus][ManagedIdentity] #45875

Open loGit123 opened 1 week ago

loGit123 commented 1 week ago

Library name and version

Microsoft.Azure.WebJobs.Extensions.ServiceBus - 5.2.0 ,Azure.Messaging.ServiceBus - 7.8.0

Query/Question

I am trying to Use ServiceBus Trigeer with Managed Identity but it not able to run as it is giving below error The listener for function 'ProcessSubscriptions' was unable to start. The connection string used for an Service Bus client must specify the Service Bus namespace host and either a Shared Access Key (both the name and value) OR a Shared Access Signature to be valid. (Parameter 'connectionString')

My template.json appsetting - json(concat('{\"name\":\"ServiceBusConnection__fullyQualifiedNamespace\",\"value\":\"Endpoint=sb://', variables('servicebus_name'), '.servicebus.windows.net\"}'))),

Environment

dotnet - 6.0

github-actions[bot] commented 1 week ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

jsquire commented 1 week ago

@loGit123 : Thanks for reaching out and we regret that you're experiencing difficulties. The error message indicates that Functions believes that you're using a connection string rather than an identity-based connection. Unfortunately, there's not enough context available here to offer additional thoughts.

Please be aware that the version of the extensions package that you're using is ~3 years old. Please update to the latest packages and confirm that you're able to reproduce.

If so, please share a code snippet demonstrating your function with its trigger attribute, the relevant section of your host.json, and the relevant section of your configuration settings - with any sensitive information redacted.

github-actions[bot] commented 1 week ago

Hi @loGit123. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

loGit123 commented 1 week ago

Can you please point me to the latest stable version to use for this ? This tutorail I followed - https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-managed-service-identity

jsquire commented 6 days ago

The Microsoft.Azure.WebJobs.Extensions.ServiceBus package is currently at v5.16.4. The Azure.Messaging.ServiceBus package is currently at v7.18.1. The versions that you've detailed using are 2-3 years old.

github-actions[bot] commented 6 days ago

Hi @loGit123. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

loGit123 commented 6 days ago

I have changed the version to 5.16.4 and 7.18.1 but still at listener I am getting this error

The listener for function 'ProcessSubscriptions' was unable to start. The connection string used for an Service Bus client must specify the Service Bus namespace host and either a Shared Access Key (both the name and value) OR a Shared Access Signature to be valid. (Parameter 'connectionString')

''Microsoft.Azure.WebJobs.Host.Listeners.FunctionListenerException: System.ArgumentException: at Azure.Messaging.ServiceBus.ServiceBusConnection.ValidateConnectionStringProperties (Azure.Messaging.ServiceBus, Version=7.18.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8) at Azure.Messaging.ServiceBus.ServiceBusConnection..ctor (Azure.Messaging.ServiceBus, Version=7.18.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8) at Azure.Messaging.ServiceBus.ServiceBusClient..ctor (Azure.Messaging.ServiceBus, Version=7.18.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8) at Microsoft.Azure.WebJobs.ServiceBus.MessagingProvider+<>cDisplayClass19_0.b0 (Microsoft.Azure.WebJobs.Extensions.ServiceBus, Version=5.16.4.0, Culture=neutral, PublicKeyToken=92742159e12e44c8) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd (System.Collections.Concurrent, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a) at System.Lazy1.ViaFactory (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Lazy1.ExecutionAndPublication (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Lazy1.CreateValue (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.Azure.WebJobs.ServiceBus.Listeners.ServiceBusListener+<>cDisplayClass36_0.<.ctor>b2 (Microsoft.Azure.WebJobs.Extensions.ServiceBus, Version=5.16.4.0, Culture=neutral, PublicKeyToken=92742159e12e44c8) at System.Lazy1.ViaFactory (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Lazy1.ExecutionAndPublication (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Lazy`1.CreateValue (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.Azure.WebJobs.ServiceBus.Listeners.ServiceBusListener+d37.MoveNext (Microsoft.Azure.WebJobs.Extensions.ServiceBus, Version=5.16.4.0, Culture=neutral, PublicKeyToken=92742159e12e44c8) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.Azure.WebJobs.Host.Listeners.FunctionListener+d13.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.41.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: D:\a_work\1\s\src\Microsoft.Azure.WebJobs.Host\Listeners\FunctionListener.cs:68)''

in arm template, I have added servicebusconnection__fullyQualifiedNamespace. and added roleAssignments for Data Owner and Receiver, Example is like below ....

and for the listener below is the code...

this.QueueClient = client ?? new ServiceBusClient("testservicebus.servicebus.windows.net", new DefaultAzureCredential()).CreateSender(QueueNAme);

Is there anything else has to added to resolve this error?

jsquire commented 6 days ago

@loGit123 : Please share your Function signature with the trigger attribute and your config. The listener is part of the trigger infrastructure and has nothing to do with the snippet below. That snippet is creating a sender. That said, you are also leaking the ServiceBusClient which you need to ensure gets disposed or you'll end up orphaning the connection.

github-actions[bot] commented 6 days ago

Hi @loGit123. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

loGit123 commented 6 days ago

public async Task Run( [ServiceBusTrigger(ServiceBusSubscriptionQueue.SUBSCRIPTIONQUEUE, Connection = "ServiceBusConnection")] Subscription subscription, ILogger logger)

Config

appsetting - json(concat('{\"name\":\"ServiceBusConnection__fullyQualifiedNamespace\",\"value\":\"Endpoint=sb://', variables('servicebus_name'), '.servicebus.windows.net\"}'))),

loGit123 commented 5 days ago

Sometimes this error also I am getting - The listener for function 'ProcessGroups' listener was unable to start. The connection string could not be parsed; either it was malformed or contains no well-known tokens.

jsquire commented 5 days ago

A fully qualified namespace name should be something like: your-namespace.servicebus.windows.net. The value that you're setting is not a valid namespace and is interpreted as a connection string. It is also not a valid connection string, as it's missing the shared key or SAS, so it fails validation. (see: docs).

A couple of other notes:

github-actions[bot] commented 5 days ago

Hi @loGit123. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

loGit123 commented 5 days ago

/unresolve BUT i AM USING MANAGED IDENITY then why sas is required? and how it is not a valid namespace, I didnt get your point?

this app config is array and the converted to a string thats why it is concatenated like this

jsquire commented 5 days ago

/unresolve BUT i AM USING MANAGED IDENITY then why sas is required?

It's not. You're malforming the fully qualified namespace name, as discussed.

and how it is not a valid namespace

Because a valid fully qualified namespace does not have Endpoint= in it. Remove all but the URI. Please see linked docs for examples and details.

github-actions[bot] commented 5 days ago

Hi @loGit123. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

loGit123 commented 5 days ago

/unresolve BUT i AM USING MANAGED IDENITY then why sas is required?

It's not. You're malforming the fully qualified namespace name, as discussed.

and how it is not a valid namespace

Because a valid fully qualified namespace does not have Endpoint= in it. Remove all but the URI. Please see linked docs for examples and details.

Actually I have tried that too, removing the Endpoint= and sb:// but still I got the same issue I am getting. I am not sure what else I am missing.

jsquire commented 4 days ago

So long as you're using the raw form, then things should be well. At this point, I think it would be helpful if you shared a small, stand-alone app that reproduces your issue. There's a lot of this discussion that are environmental, and I'm not sure that all of the relevant context is clear.

github-actions[bot] commented 4 days ago

Hi @loGit123. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.