| name | azure-identity-msi |
| description | Time Saved: 1-2 hours debugging identity and RBAC |
| lastReviewed | 2026-04-30T00:00:00.000Z |
Azure Managed Identity (MSI) Concepts
Category: Azure
Time Saved: 1-2 hours debugging identity and RBAC
Battle-tested: Yes — multiple Azure deployments
The Problem
You're configuring RBAC for an Azure resource's managed identity. You see principalId in one place, servicePrincipal in another, and objectId elsewhere. Documentation uses these terms interchangeably and you're not sure if they're the same thing.
Why It's Confusing
A Managed Identity is a Service Principal — they're the same object viewed from different angles:
- Managed Identity: The Azure resource perspective ("my VM has an identity")
- Service Principal: The Entra ID perspective ("there's an app registration")
- Principal ID / Object ID: The unique identifier (same value, different names)
The Rule
A Managed Identity IS a Service Principal in Entra ID. The principalId from the resource matches the Service Principal's Object ID in role assignments.
Identity Flow
Azure Resource (VM, Function, Container App)
│
▼ creates
Managed Identity
│
▼ which IS
Service Principal in Entra ID
│
▼ gets assigned
RBAC Role on Target Resource
Verification Pattern
When debugging RBAC issues, verify the chain:
Step 1: Get principalId from Source Resource
az containerapp show \
--name myapp \
--resource-group myrg \
--query identity.principalId
az functionapp show \
--name myfunc \
--resource-group myrg \
--query identity.principalId
az vm show \
--name myvm \
--resource-group myrg \
--query identity.principalId
Step 2: Verify Service Principal Exists
az ad sp show --id <principalId> --query objectId
Step 3: Check Role Assignments on Target
az role assignment list \
--scope /subscriptions/{sub}/resourceGroups/{rg}/providers/{provider}/{resource} \
--query "[].{principal:principalId,role:roleDefinitionName}"
Step 4: Confirm Match
Common RBAC Roles
| Role | When to Use |
|---|
| Reader | Read-only access to resources |
| Contributor | Full access except RBAC management |
| Owner | Full access including RBAC |
| Storage Blob Data Reader | Read blobs (not just management) |
| Key Vault Secrets User | Read secrets from Key Vault |
Note: Management roles (Reader, Contributor) don't grant data plane access. For blob storage, you need "Storage Blob Data *" roles.
Assignment Script
PRINCIPAL_ID=$(az containerapp show \
--name myapp \
--resource-group myrg \
--query identity.principalId -o tsv)
az role assignment create \
--assignee-object-id $PRINCIPAL_ID \
--assignee-principal-type ServicePrincipal \
--role "Storage Blob Data Reader" \
--scope /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Storage/storageAccounts/{account}
System vs User Assigned
| Type | Creation | Lifecycle | Use Case |
|---|
| System-assigned | With resource | Deleted with resource | Single-resource identity |
| User-assigned | Separately | Independent | Shared across resources |
az containerapp identity assign \
--name myapp \
--resource-group myrg \
--system-assigned
az identity create \
--name myidentity \
--resource-group myrg
az containerapp identity assign \
--name myapp \
--resource-group myrg \
--user-assigned myidentity
Verification Checklist
Common Symptoms
- "Authorization failed" after enabling managed identity
- Role assignment exists but access denied
- "Principal does not exist" in role assignment
- Works with Contributor, fails with custom role
Related Skills
azure-subscription-context — Subscription issues
azure-swa-gotchas — SWA-specific identity issues