azure-sdk-for-net
azure-sdk-for-net copied to clipboard
[BUG] documentation for managed identity is wrong?
Library name and version
Microsoft.Azure.WebJobs.Extensions.ServiceBus @ 5.2.0
Describe the bug
The documentation for using a managed identity states to use a setting named something like: <connection name>__fullyQualifiedNamespace. However, in my experience this doesn't work. Instead you need to specify the fully qualified namespace as a property of that connection name, e.g.,
{
"ConnectionStrings":
{
"MyServiceBusConnectionName":
{
"fullyQualifiedNamespace": "xyz.servicebus.windows.net"
}
}
}
The code also seems to agree: Grabbing the fullyQualifiedNamespace from a config section
Expected behavior
Using the following config, the trigger should bind to the connection named MyServiceBusConnectionName with a managed identity.
{
"Values":
{
"MyServiceBusConnectionName__fullyQualifiedNamespace": "xyz.servicebus.windows.net"
}
}
Actual behavior
Fails with exception: Service Bus account connection string 'MyServiceBusConnectionName' does not exist. Make sure that it is a defined App Setting.
Reproduction Steps
program.cs
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Azure.WebJobs;
using Azure.Messaging.ServiceBus;
namespace TEST
{
public class Program
{
static void Main()
{
var builder = new HostBuilder();
builder.ConfigureHostConfiguration(config =>
{
// Make sure we pick up the environment variables starting with DOTNET_.
// These include the Environment variable which we use to load supplemental configs.
config.AddEnvironmentVariables(prefix: "DOTNET_");
});
builder.ConfigureAppConfiguration((hostContext, config) =>
{
config.AddJsonFile("appSettings.json");
});
builder.ConfigureWebJobs(b =>
{
b.AddServiceBus();
})
.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<LogicHandler>();
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddConsole();
});
})
.UseConsoleLifetime();
var host = builder.Build();
using (host)
{
host.Run();
}
}
}
public class LogicHandler
{
private ILogger<LogicHandler> _logger;
public LogicHandler(ILogger<LogicHandler> logger)
{
_logger = logger;
}
public void DoStuff(
[ServiceBusTrigger("myQueue", Connection = "MyServiceBusConnectionName")] ServiceBusReceivedMessage message)
{
_logger.LogError($"MESSAGE RECEIVED: {message.MessageId}");
}
}
}
Environment
Azure AppService
Thank you for your feedback. Tagging and routing to the team member best able to assist.
Hi @craigb, I think the issue here is that you are specifying your settings in appsettings.json, rather than local.settings.json, which is what the documentation refers to. Since you are using a different json file and adding it yourself, it doesn't have the same properties as when using local.settings.json. Also see https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference?tabs=blob#local-development-with-identity-based-connections for more information.
Hi @craigb. 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.
Thanks for your reply @JoshLove-msft -- we're updating some old webjobs and didn't see this particular documentation as it's not linked from the docs. Perhaps the Readme with the example should reference this page on identity-based-connections for clarity.
Thanks for your reply @JoshLove-msft -- we're updating some old webjobs and didn't see this particular documentation as it's not linked from the docs. Perhaps the Readme with the example should reference this page on identity-based-connections for clarity.
Sure, I will update the README to link to those docs.