Identities for applications and Azure workloads
Choosing between managed identities, service principals, user accounts and managed service accounts, then creating, assigning and using managed identities.
- 14 min
- 4 concepts
- Try it yourself
- 4-question check
Learn
Apps and scripts need to sign in too. The aim is to give each one its own identity with only the access it needs, and ideally no secret that someone has to store or rotate.
- 1
Select appropriate identities for applications and Azure workloads, including managed identities, service principals, user accounts, and managed service accounts
Managed identity: for code running on Azure resources that support it; no credentials to manage. Service principal (from an app registration): for apps outside Azure or multi-tenant apps; uses a certificate (preferred), secret or workload identity federation (trust a GitHub Actions or Kubernetes token, no secret). User accounts shouldn't be used as service accounts. Group managed service accounts (gMSA) are for on-premises Windows services.
Remember: Running in Azure? Managed identity. Outside Azure? Service principal, ideally with federation.
- 2
Create managed identities
System-assigned: switched on for one resource, created and deleted with it. User-assigned: a standalone Azure resource (Microsoft.ManagedIdentity/userAssignedIdentities) that can be attached to several resources and survives them. Create user-assigned identities in the portal, CLI (
az identity create), PowerShell or templates.Remember: Shared across resources or pre-provisioned access? User-assigned.
- 3
Assign a managed identity to an Azure resource
Turn on system-assigned identity on the resource's Identity page, or add a user-assigned identity there. Supported resources include VMs, scale sets, App Service, Functions, Logic Apps, Container Apps, AKS and many more. You need the Managed Identity Operator role to assign a user-assigned identity.
Remember: Identity page → System assigned: On.
- 4
Use a managed identity assigned to an Azure resource to access other Azure resources
Grant the identity a role on the target, for example Key Vault Secrets User on a vault or Storage Blob Data Reader on a storage account. In code, use the Azure Identity library's
DefaultAzureCredentialorManagedIdentityCredential; it gets tokens from the local identity endpoint. For a user-assigned identity, specify its client ID.Remember: No role assignment, no access, even with an identity.
System-assigned or user-assigned?
- Tied to one resource
- Deleted with the resource
- Simple for single workloads
- Separate Azure resource
- Shared by many resources
- Grant access before the resource exists
Try it
Pick the right identity for the workload.
This interactive part needs JavaScript.
In the portal
- Turn on a managed identityAzure portal: your resource > Settings > Identity
- Create a user-assigned identityAzure portal: Managed Identities > Create
- Federated credentialsEntra admin center: Entra ID > App registrations > your app > Certificates & secrets > Federated credentials
Key terms
Click a card to see the definition.
Check your understanding
4 questions. Score 80% or more and these skills are marked as confident in your SC-300 study plan.
Which identity is deleted when its VM is deleted?
System-assigned identities share the resource's lifecycle.
A GitHub Actions workflow deploys to Azure. How do you avoid storing a secret?
Federation trusts GitHub's OIDC token.
A web app's managed identity can't read Key Vault secrets. What's missing?
Identities need access granted on the target.
Which is a standalone Azure resource?
User-assigned identities are their own resource.
Sources
- Microsoft Learn: What are managed identities for Azure resources?
- Microsoft Learn: Managed identity best practice recommendations
- Microsoft Learn: Workload identity federation
- Microsoft Learn: Securing service accounts
Facts in this lesson are from Microsoft Learn. This site isn't affiliated with Microsoft.