I have performed the following
- Created a simple azure blob triggered function app in visual studio with default setup
- Publish into Azure portal and the trigger is set to a different azure blob location
Requirement is to Relplace azure blob connection string with function app Managed identity
- I followed this blog which mentions simple setup but in my case the connection string is a different one so I am not sure if this work
Can you please help to identify
- Steps to follow in order to replace with managed identity in Visual studio for this case
- Versions of function app and azure blob supports managed identity
I also found this blog which resonates the requirement however I am not sure how to perform this in VS and sync to azure portal for my current function app
thanks
2
Answers
I successfully ran the Blob trigger function locally and in the Azure Function App using
DefaultAzureCredentials
andManaged Identity
.Below is the complete code for a Blob trigger function in the .NET 8 Isolated model.
Function1.cs :
Program.cs :
local.settings.json :
I have created a Service principle in Azure AD and added the
clientID
,clientSecret
andTenantID
to theSystem Environment Variables
to run the function using DefaultAzureCredentials as shown below.Add below to your System Environment Variables :
I have Enabled the Manged Identity in the Azure Function App as shown below.
I have assigned the Owner role to the
Service Principal
and the Storage Blob Data Contributor role to theFunction App
under Access Control (IAM) in the Storage account, as shown below.Local Output :
I started running the Blob trigger function and upload a file in the Blob storage as shonw below.
The Blob Trigger function ran successfully and retrieved the blob details, as shown below.
I published the Blob trigger function to the Azure Function App, as shown below.
Azure Function App Output :
I successfully ran the Blob Trigger function in the Azure Function App and retrived the blob details after uploading a file to the Blob Storage, as shown below.
DefaultAzureCredential
can obtain credentials of different types, in a number of different ways based on a set of environment variables. But the default options and search order makes it difficult to exclude or enable some of these without requiring code changes.To allow configuration to specify exactly which type of credential should be used, at least for the types that I wanted to support, I came up with the following;