Managed Identities
Workload identity types · system-assigned vs user-assigned · create · assign to a resource · access other resources · gMSA/sMSA, service principal, user account
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
Choosing an identity for a workload
In Microsoft Entra, workload identities are applications, service principals, and managed identities. A managed identity is a special type of service principal that eliminates the need for developers to manage credentials.
| Identity | What the pages say | Pick it when |
|---|---|---|
| Managed identity | Azure manages the credentials. Best for communication among services that support Microsoft Entra authentication. Can be used at no extra cost. | The workload runs on an Azure resource and the target supports Microsoft Entra authentication. |
| Service principal (application) | Authenticates with a client certificate or a client secret. Certificates are recommended because they can't be embedded in code by accident. | You can't use a managed identity (for example the code runs outside Azure). Grant only the permissions and scope the task needs. |
| Microsoft Entra user account | Evaluate moving from a user account to a managed identity or a service principal. | Avoid it as a service identity. |
| gMSA (on-premises) | Use whenever possible for on-premises services. One identity for a server farm or services behind a network load balancer; also fine for one server. | On-premises Windows service, several servers or a load balancer. |
| sMSA (on-premises) | Use if you can't use a gMSA. Runs on only one server; can serve several services on that server. Needs at least Windows Server 2008 R2. | On-premises service tied to one server. |
| Computer or user account (on-premises) | Only if you can't use an MSA. With a computer account you can't tell which service on the computer uses it. | Last resort; keep service accounts out of privileged groups. |
A managed identity has only a service principal object. It has no application object, so Microsoft Graph permissions for a managed identity are granted directly to the service principal.
System-assigned vs user-assigned
| Property | System-assigned | User-assigned |
|---|---|---|
| Creation | Created as part of an Azure resource (for example a VM or App Service). | Created as a stand-alone Azure resource. |
| Life cycle | Shared with the resource; deleted when the resource is deleted. | Independent; must be explicitly deleted. |
| Sharing | Can be associated with a single Azure resource only. | Can be associated with more than one Azure resource. |
| Use cases | One workload on one resource; independent identity per resource. | Several resources share one identity; access needed before the resource is deployed; resources recycled often but permissions stay. |
- A resource can have both a system-assigned identity and one or more user-assigned identities.
- Role assignments can't be created in advance for a system-assigned identity, because it is created with the resource. A user-assigned identity and its role assignments can be set up in advance.
- Deploying many resources that each have a system-assigned identity can hit the Microsoft Entra object-creation rate limit (HTTP 429). One user-assigned identity needs one service principal.
- Choose system-assigned when you must log which specific resource acted, or when permissions should be removed together with the resource.
- User-assigned managed identities are the recommended managed identity type for Microsoft services.
Create and assign
| Task | Role the account needs |
|---|---|
| Create or delete a user-assigned identity | Managed Identity Contributor |
| List or read a user-assigned identity | Managed Identity Operator or Managed Identity Contributor |
| Enable a system-assigned identity on a VM | Virtual Machine Contributor (write permission on the resource); no other Microsoft Entra directory role |
| Assign a user-assigned identity to a VM | Virtual Machine Contributor and Managed Identity Operator (the Microsoft.ManagedIdentity/userAssignedIdentities/*/assign/action action) |
| Grant the identity access to a target resource | Owner or User Access Administrator on the target resource |
- Portal, create a user-assigned identity: search Managed Identities, select Add, choose subscription, resource group, region and name.
- Portal, system-assigned on an existing VM: VM > Security > Identity > System assigned > Status On > Save.
- Portal, user-assigned on an existing VM: VM > Security > Identity > User assigned > +Add. The portal can't assign a user-assigned identity while the VM is being created.
Identity names: start with a letter or number; alphanumerics, hyphens and underscores; limited to 24 characters for assignment to a VM or scale set to work. Deleting a user-assigned identity doesn't remove it from the resource it was assigned to.
Use the identity to reach other resources
- Create the managed identity (system-assigned or user-assigned).
- For a user-assigned identity, assign it to the source resource.
- Authorize the identity on the target service (for example an Azure role assignment).
- Get a token with the Azure.Identity library or MSAL, or from the Azure Instance Metadata Service (IMDS) endpoint on the VM.
- IMDS token requests need the header
Metadata: true(a mitigation against server-side request forgery). Theresourceparameter is the App ID URI of the target and appears in theaudclaim. - With no identity named in the request, IMDS defaults to the system-assigned identity. If there is no system-assigned identity and several user-assigned identities, you must name one with
client_id,object_idormsi_res_id. - The security boundary is the resource: any code on the VM can request tokens for any managed identity on it.
- Tokens are cached by Azure for around 24 hours per resource URI. Group or role changes can take several hours to take effect and a refresh can't be forced.
- Role assignments are not deleted when the identity is deleted; they show as "Identity not found".
- A managed identity can't be used to reach a resource in a different directory (tenant).
Limits and lifecycle
| Item | Value |
|---|---|
| Credential | Certificate-based; expires after 90 days and is rolled after 45 days (an implementation detail that can change without notice) |
| Soft delete | 30 days; you can view the service principal but can't restore or purge it |
| Directory quota guard | Creation is blocked if the new service principal would take directory usage to 98% or more of the tenant quota; existing identities keep working |
| Moving a subscription to another directory | Not recreated automatically: disable and re-enable system-assigned; delete, re-create and re-attach user-assigned; grant roles again |
| Moving a user-assigned identity to another resource group | Not supported |
Use Azure Policy with effect deny on type Microsoft.ManagedIdentity/userAssignedIdentities to stop people creating user-assigned identities in a scope.
CLI and PowerShell
| Task | Azure CLI | PowerShell |
|---|---|---|
| Create a user-assigned managed identity | az identity create -g myResourceGroup -n myUserAssignedIdentity | New-AzUserAssignedIdentity -ResourceGroupName <RESOURCEGROUP> -Name <USER ASSIGNED IDENTITY NAME> |
| Enable system-assigned identity on an existing VM | az vm identity assign -g myResourceGroup -n myVm | Update-AzVM -ResourceGroupName myResourceGroup -VM $vm -IdentityType SystemAssigned |
| Assign a user-assigned identity to a VM | az vm identity assign -g <RESOURCE GROUP> -n <VM NAME> --identities <USER ASSIGNED IDENTITY> | Update-AzVM -ResourceGroupName <RESOURCE GROUP> -VM $vm -IdentityType UserAssigned -IdentityID $uid |
| Remove a user-assigned identity from a VM | az vm identity remove -g <RESOURCE GROUP> -n <VM NAME> --identities <USER ASSIGNED IDENTITY> | - |
| List a tenant's managed identity permissions (app roles) | - | Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId <String> |
Exam Tips
Tick each tip once you can answer it without looking.
“Azure VM must read a storage account, no secrets in code” → Managed identity, then an Azure role on the storage account.. Trap: A service principal with a secret works but you must store and rotate the secret.
“Four VMs need identical access, permissions set before the VMs exist” → One user-assigned managed identity.. Trap: System-assigned identities are created with the resource, so roles can't be assigned in advance.
“Permissions must disappear when the resource is deleted; audit must show which resource acted” → System-assigned managed identity.. Trap: A user-assigned identity must be deleted explicitly.
“Who can create or delete a user-assigned identity?” → Managed Identity Contributor.. Trap: Managed Identity Operator can list/read and assign, not create or delete.
“Assign a user-assigned identity to a VM” → Virtual Machine Contributor plus Managed Identity Operator.. Trap: Virtual Machine Contributor alone covers system-assigned only.
“Portal: user-assigned identity during VM creation” → Not supported; create the VM, then add it under Security > Identity > User assigned.. Trap: System-assigned can be enabled on the Management tab at creation.
“Grant a managed identity a role on a storage account” → Owner or User Access Administrator on the target resource.. Trap: Granting access on the target needs Owner or User Access Administrator there.
“Permissions added to a group the identity belongs to still fail for hours” → Token cache (about 24 hours); assign roles directly to a user-assigned identity.. Trap: You can't force a managed identity token refresh.
“VM has several user-assigned identities; IMDS call fails” → Pass client_id, object_id or msi_res_id.. Trap: IMDS defaults only to the system-assigned identity, or to a single user-assigned one.
“Grant Microsoft Graph permission to a managed identity” → Assign the app role to its service principal.. Trap: There is no application object to configure on a managed identity.
“On-premises service on a server farm or behind a load balancer” → gMSA.. Trap: An sMSA runs on one server only.
“Script uses an Azure user account to call Azure” → Move to a managed identity; else a service principal with least permissions.. Trap: A user account as service identity is what the guidance tells you to replace.
“Subscription moved to another directory” → Re-create identities and role assignments.. Trap: They are not recreated automatically.
“New managed identity creation is blocked in the tenant” → Directory object quota at 98%; delete objects or ask Support for more.. Trap: Soft-deleted objects count, and existing identities keep working.
Sources
- Managed identities for Azure resources overview
- Managed identities FAQ
- Manage user-assigned managed identities
- Best practice recommendations for managed identities
- Configure managed identities on Azure VMs
- Use managed identities on a VM to acquire an access token
- Workload identities
- Apps and service principals
- Securing managed identities
- Securing service principals
- Introduction to Active Directory service accounts
Checked against Microsoft Learn on November 13, 2026.