Create a managed identity and give it a role

Azure Portal, Hands On10 minutesFreeSteps checked 23 October 2026By Cloud Hands On

In this task you'll create a user-assigned managed identity.

A managed identity is an account in Entra ID that belongs to an Azure resource, not a person. Your web app, function or VM signs in with it to reach other services, such as Key Vault or storage, and Azure looks after its credentials. There's no password for anyone to leak.

There are two kinds. A system-assigned identity is switched on inside one resource and is deleted with it. A user-assigned identity is a resource of its own that you can attach to several resources.

Example. SS Kaiser's web app and its nightly function both need to read the same storage account. The team creates one user-assigned identity, id-sskaiser-shop, gives it a storage role once, and attaches it to both.

Before you start

You need: Contributor on the resource group, plus Owner or User Access Administrator to give it a role. Time: 10 minutes.

Where to look

  1. Home
  2. Managed Identities
  3. + Create

Steps

  1. Search Managed Identities and select + Create.
  2. Choose rg-portal-practice and the name id-portal-practice. Change Region to one near you: it may start on East US. Leave Isolation Scope on None, then select Review + create and Create.
  3. Open the identity. On Overview, note the Client ID and the Object (principal) ID.Apps use the client ID to say which identity they want. Role assignments use the principal ID.
  4. Select Azure role assignments, then + Add role assignment (Preview). Set Scope to Resource group, pick rg-portal-practice, choose the Role Reader and select Save.The new assignment can take a minute to appear in the list: select Refresh. Give the smallest role that does the job, on the smallest scope.
  5. To see the other kind, open any resource that supports it, such as a web app or VM, and select Identity. The System assigned tab has an On and Off switch; the User assigned tab is where you'd attach id-portal-practice. Don't save anything.
  6. In Microsoft Entra ID, open Enterprise applications, set the Application type filter to Managed Identities and find id-portal-practice in the list.This is the same identity, seen from Entra ID.

Commands

# Create a user-assigned managed identity
az identity create --resource-group rg-portal-practice --name id-portal-practice

# Give it Reader on the resource group
PRINCIPAL=$(az identity show --resource-group rg-portal-practice --name id-portal-practice --query principalId --output tsv)
az role assignment create --assignee-object-id $PRINCIPAL --assignee-principal-type ServicePrincipal \
  --role Reader --resource-group rg-portal-practice

# Turn on a system-assigned identity for a web app
az webapp identity assign --resource-group rg-portal-practice --name <app name>

Watch out for

Cost
Managed identities are free.
Security
Anything that can use the identity gets its roles, so attach it only where it's needed and keep its roles small. Prefer managed identities to secrets in app settings.
Common mistakes
Giving Contributor on the whole subscription because it's quicker. Using the client ID where a principal ID is asked for. Forgetting that a system-assigned identity (and its roles) disappears when its resource is deleted.

Clean up

  1. Managed Identities
  2. id-portal-practice
  3. Delete

Delete id-portal-practice, or delete the resource group. Its role assignment is removed with it.

Words to know

Managed identity
An identity for an Azure resource. Azure creates and rotates its credentials for you.
System-assigned
Turned on inside one resource and deleted with it.
User-assigned
A separate resource you can attach to many resources. It stays until you delete it.
Object (principal) ID
The identity's ID in Entra ID. Role assignments use it.

Tick off each step and track your progress in the guide.

Open this task in Azure Portal, Hands On

Keep going