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.

BUG In Azure Function Trigger with Managed Identity

See original GitHub issue

I think there is a bug in the use of Azure Function Trigger Bindings on the Connection value when a Managed Identity is used.

We are using Managed Identity with Consumption based Function App to receive events from the EventHub. As per the Microsoft documentation: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-trigger?tabs=csharp#identity-based-connections we are using the following connection string in the EventHub trigger:

EhubSaaSSecConnection__fullyQualifiedNamespace: [[ REDACTED ]].servicebus.windows.net

Here’s the Function App signature:

[FunctionName("EventHub-To-EventHubFunction")]
public static async Task Run(
// SaaS EH Trigger - Receives events from source EH
[EventHubTrigger(Constants.SaasEHName, Connection = Constants.SaasEHConnectionName)] EventData[] events,
// QRadar EH Output binding - Sends events to dest EH
[EventHub(Constants.QRadarEHName, Connection = Constants.QRadarEHConnectionName)] IAsyncCollector<string> outputEvents, ILogger log)

Here are the constants:

public const string SaasEHConnectionName = "EhubSaaSSecConnection";
public const string QRadarEHConnectionName = "EhubQRadarConnection";

The function EventHub-To-EventHubFunction is getting triggered without any exception when the Azure portal is open, but the trigger gets hibernated afterward and does not activate even if events queued up in the Event Hub. Upon the troubleshooting, we found the following errors in Scale Controller which is preventing the function to scale up when there’s an event. After you enable the logging of the Scale Controller Logs you can use the Kusto query: traces
| extend CustomDimensions = todynamic(tostring(customDimensions))
| where CustomDimensions.Category == “ScaleControllerLogs”
| order by timestamp desc

You’ll see logs as the following: Specified connection string is null or empty for connection: EhubSaaSSecConnection. Invalid connection.

More Information below from a different thread: https://github.com/Azure/azure-sdk-for-net/issues/12657#issuecomment-1011820099 All credits to @Swing0601 https://github.com/Swing0601: I got the same error message, and looked into the source code, finally figured it out. Hope it will be helpful.

here is the source code, there is condition whether get the connection with Identity or Shared Access https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/src/Config/EventHubClientFactory.cs image

Identity-based connections require “<CONNECTION_NAME_PREFIX>__fullyQualifiedNamespace” property. https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-trigger?tabs=csharp#identity-based-connections

My issue is caused by CONNECTION_NAME_PREFIX is not correct, the format is AzureWebJobs + connectionName, here is an example, CONNECTION_NAME_PREFIX is “AzureWebJobsmyEventHubConnectionString”, then “<CONNECTION_NAME_PREFIX>__fullyQualifiedNamespace” value is “AzureWebJobsmyEventHubConnectionString___fullyQualifiedNamespace”

function.json: image

BTW, my develop language is Python,

CONNECTION_NAME_PREFIX source code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/extensions/Microsoft.Azure.WebJobs.Extensions.Clients/src/Shared/WebJobsConfigurationExtensions.cs

image

Good Luck!!!

_Originally posted by @Swing0601 in https://github.com/Azure/azure-sdk-for-net/issues/12657#issuecomment-1011820099_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
karshinlincommented, Jun 1, 2022

Bumping. This issue is getting in the way of our IaC workflow.

Sorry for the delay, we are in the process of rolling out a fix and should have another update in about a week or so. Thanks for the patience on this one.

1reaction
LRomano72commented, Feb 2, 2022

Just to update everyone on this. The fix of adding “AzureWebJobs” to the connection variable name in AppSettings did not fix the issue. MSFT is reaching out to the Scale Controller team as they must be an issue there when working with Managed Identity.

As a work around that removes the Scale Controller but will cost you more, is to create an App Service Plan - Standard (min) and then deploy your Function App into that and enable the “Always On” setting so you don’t have cold starts issues and the FApp is warm.

Someone else was doing the IaC and we had thing up and running in less then an hours, no changes to any resource names and we had to whitelist all the new IPs to the Event Hub Namespace for security reasons. In general, this scenario will cost you CAD $100/month if you don’t have a spare App Service Plan.

MSFT will continue to work on the issue as FApp Consumption plan tier was designed for this scenario so they will make it work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using User Managed Identity in Azure function Service Bus ...
I have a .net 6 Azure Function that is connecting to Service Bus without issue with just that setting. Within your code you...
Read more >
Use identity-based connections with Azure Functions ...
This tutorial shows you how to configure Azure Functions to connect to Azure Service Bus queues using managed identities instead of secrets ...
Read more >
Error when using managed identity for ...
Hello. We are trying to deploy a functionApp by using a managed identity for AzureWebJobsStorage, as described here: ...
Read more >
Azure Service Bus trigger for Azure Functions
When hosted in the Azure Functions service, identity-based connections use a managed identity. The system-assigned identity is used by ...
Read more >
Azure Functions and Managed Identity: More Secrets
The blob trigger handles failures using a queue, for this reason, when using the blob trigger the queue endpoint needs to be specified...
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