DEV Community

Christos Matskas for The 425 Show

Posted on

3 1

Configure Managed Identity for Azure Functions using PowerShell

This is going to be a sweet and short blog post on programmatically setting up a System-Assigned Managed Identity on an Azure Function App and assigning the appropriate permissions.

On an authenticated PowerShell session - I love to use Cloud Shell, either on my Windows Terminal or in the Azure Portal, type the following:

Update-AzFunctionApp -Name <YourFunctionAppName> -ResourceGroupName <YourResourceGroup> -IdentityType SystemAssigned
Connect-AzureAD
$managedIdentityId = (Get-AzureADServicePrincipal -SearchString '<yourFunctionAppName>').ObjectId
New-AzRoleAssignment -ObjectId $managedIdentityId -RoleDefinitionName "Contributor" -Scope "/subscriptions/<YourSubscriptionId"

What does this script do? Let's take it step by step
First we configure the Azure Function App to use a Managed Identity
Next, we retrieve the Managed Identity ObjectID. This is required by the next statement so that we can assign the appropriate RBAC role. The last line assigns the Contributor role to the Managed Identity with the Subscription being the scope. You can reduce scope to a resource group or specific resources instead if that's what you need.

Reminder: System-Assigned Managed Identities are tied to the Resource that were created. As such, if that resource gets deleted, the Managed Identity will deleted with it

As promised, short and sweet

Neon image

Serverless Postgres in 300ms. No credit card needed.

10 free databases with autoscaling, scale-to-zero, and read replicas. Start building without infrastructure headaches.

Try for Free →

Top comments (0)

👋 Kindness is contagious

Dive into this informative piece, backed by our vibrant DEV Community

Whether you’re a novice or a pro, your perspective enriches our collective insight.

A simple “thank you” can lift someone’s spirits—share your gratitude in the comments!

On DEV, the power of shared knowledge paves a smoother path and tightens our community ties. Found value here? A quick thanks to the author makes a big impact.

Okay