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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay