9.2 Create, Assign & Use Managed Identities
Key Takeaways
- System-assigned managed identities are created with a single Azure resource, share its lifecycle, and cannot be shared with other resources.
- User-assigned managed identities are independent Azure resources you create first, then assign to one or more supported Azure resources.
- Workloads obtain tokens from the Azure Instance Metadata Service (or platform equivalent); applications use those tokens as bearer tokens to Azure Resource Manager or data-plane APIs.
- Authorize managed identities with Azure RBAC (and Key Vault RBAC or access policies) on target resources—there is no password to place in configuration for the identity itself.
- The core security benefit is elimination of developer-managed credentials for Azure-to-Azure authentication; you still apply least privilege and monitor workload sign-ins.
Managed identities in operational depth
Section 9.1 chose managed identity as the default for many Azure workloads. Section 9.2 is the how: create, assign, grant data access, and understand what “no credentials to manage” really means on SC-300.
A managed identity is an Entra service principal that Azure provisions and rotates. Your resource gets an identity; Azure RBAC (and similar) decide what that identity can do. Code asks Azure for a token; Azure hands back an access token for a resource audience such as Key Vault or Storage.
System-assigned versus user-assigned
| Attribute | System-assigned | User-assigned |
|---|---|---|
| Creation | Enabled on a specific Azure resource | Created as its own Azure resource first |
| Lifecycle | Deleted when the host resource is deleted | Independent; survives host deletion until you delete it |
| Sharing | One-to-one with the host | Many hosts can share one identity |
| Portal mental model | “Identity blade on the VM/App Service” | “Managed Identity resource in a resource group” |
| Typical use | Single app with its own permissions | Common permissions for a fleet; pre-stage identity before compute |
| RBAC assignments | On the system-assigned principal of that resource | On the user-assigned principal; shared by all assignees |
Exam cue: if the stem says the identity must remain when a VM is rebuilt, or must be shared by several web apps, choose user-assigned. If the stem says a single Logic App needs its own identity that should disappear with the app, system-assigned is enough.
Both types appear in Microsoft Entra ID as service principals (enterprise applications / managed identities views). You still manage authorization the same way: role assignments on target resources.
Create a system-assigned managed identity
High-level admin steps (UI labels evolve; exam cares about the model):
- Open the Azure resource (for example Virtual machine, App Service, Function App, Azure Automation account).
- Open Identity (or equivalent).
- Under System assigned, set Status to On, save.
- Azure creates an Entra identity tied to that resource and shows an Object (principal) ID.
- Use that principal when assigning Azure roles on targets.
CLI conceptual pattern (know the intent, not trivia flags):
- Enable system-assigned identity on the resource.
- Note
principalId. role assignment createfor that principal on the scope of Storage, Key Vault, SQL, etc.
ARM/Bicep/Terraform can set identity: { type: 'SystemAssigned' } so identity is part of infrastructure as code—a common enterprise pattern SC-300 recognizes as good operations hygiene.
Create and assign a user-assigned managed identity
- Create a user-assigned managed identity in a resource group (name, region).
- Note its client ID, principal ID, and resource ID.
- On each compute resource, open Identity > User assigned > Add, select the managed identity.
- Grant Azure RBAC on target resources to the user-assigned principal (once), not once per app unless scopes differ.
- In application configuration, when multiple identities exist on one host, specify which user-assigned identity to use (client ID) so token requests are unambiguous.
| Step | System-assigned | User-assigned |
|---|---|---|
| Create identity object | Implicit when enabled | Explicit resource create |
| Attach to compute | Same step as create | Separate assign step |
| Choose identity in code | Default system identity | Often pass client ID |
| Delete compute | Identity removed | Identity remains |
Multiple identities on one resource: an App Service can have system-assigned and several user-assigned identities. Default token requests may use system-assigned; libraries accept a managed identity client ID for user-assigned selection. Misconfiguration here is a frequent “token works in portal test but app gets 401” troubleshooting story.
Use managed identity to access Azure resources
Token acquisition (conceptual)
Supported Azure hosts expose a local endpoint (for VMs, the Instance Metadata Service at a link-local address) that issues access tokens for the managed identity after Azure validates the caller is that resource. Application code typically uses Azure Identity SDK classes such as DefaultAzureCredential / ManagedIdentityCredential rather than raw HTTP, but SC-300 wants the security model:
- No client secret in
appsettings.jsonfor the MI itself. - Token is short-lived; Azure rotates underlying credentials.
- Token audience must match the target API (for example Key Vault, Storage, Arm).
Azure RBAC on the target
Authentication (who you are) is the managed identity. Authorization is still required:
| Target | Example roles / controls |
|---|---|
| Azure Storage (data plane) | Storage Blob Data Reader / Contributor; Storage Queue Data *; not only “Reader” on the control plane |
| Key Vault | Key Vault Secrets User (RBAC model) or get/list secret permissions (access policy model) |
| Azure SQL | Entra admin set; create contained user for the MI; grant DB roles |
| Microsoft Graph | Application permissions on the MI’s service principal + admin consent where supported |
| Azure Resource Manager | Contributor/Reader on resource group or finer custom roles |
Classic exam trap: assigning Reader on the Storage account resource allows seeing the account in Azure Resource Manager but does not grant permission to read blob bytes. Data-plane roles are required for many Storage and Key Vault scenarios.
Key Vault pattern (high yield)
- Enable MI on App Service / Function / VM.
- On Key Vault, enable Azure RBAC authorization (modern) or access policies (legacy).
- Assign Key Vault Secrets User (or narrower custom role) to the MI principal at vault or secret scope.
- App uses Azure SDK with managed identity to call
GetSecret. - Network rules / private endpoints may still block access even with correct RBAC—identity and network are both required in locked-down designs.
Storage pattern (high yield)
- Enable MI on the compute resource.
- Assign Storage Blob Data Contributor (or Reader) to the MI on the storage account or container scope.
- Use Azure.Storage libraries with token credential from managed identity.
- Avoid connection strings with account keys when Entra auth is available—keys are secrets you must rotate and protect; MI removes that class of secret for Azure-native access.
“No credential management” — what it does and does not mean
Does mean:
- You do not create a client secret for the managed identity.
- You do not put MI passwords in Key Vault (there is no MI password for you to store).
- Azure handles credential issuance and rotation for the identity.
Does not mean:
- You skip RBAC—without roles, tokens still fail authorization.
- Third-party APIs stop needing their API keys—store those in Key Vault and let MI read Key Vault.
- Every language host auto-authenticates without code changes—you still use SDKs/endpoints correctly.
- Compromise is impossible—if an attacker runs code on the resource, they can request tokens as the MI. Harden the host, use least privilege, and monitor.
| Benefit | Residual duty |
|---|---|
| No client secret for Azure auth | Least-privilege RBAC |
| Auto rotation | Monitor sign-in logs for the SP |
| Lifecycle with resource (system-assigned) | Clean up user-assigned identities you no longer need |
| Cleaner secret scanning results | Still secure app config for non-Azure secrets |
Administration, governance, and troubleshooting cues
Where to look in portals:
- Azure resource Identity blade — enable/assign.
- Subscriptions / resource groups / resources → Access control (IAM) — role assignments for the MI.
- Microsoft Entra admin center — enterprise applications / managed identities list for the service principal object.
- Sign-in logs filtered to service principal / managed identity activity when diagnosing auth failures.
Common failure modes:
| Symptom | Likely cause |
|---|---|
| 401/403 from Storage/Key Vault | Missing data-plane RBAC or wrong scope |
| Works for user in portal, fails for app | App not using MI credential; still using expired secret |
| Wrong permissions after sharing identity | User-assigned MI over-privileged for some of the apps sharing it |
| Token for wrong identity | Multiple MIs on host; client ID not specified |
| MI missing after recreate | System-assigned deleted with resource; role assignments orphaned |
Infrastructure as code tip: when using system-assigned, role assignments often depend on the principal ID emitted after deployment—order modules so identity exists before RBAC. User-assigned can be created in a platform landing zone first, simplifying app team deployments.
SC-300 scenario drill
- “Enable the web app to read secrets without storing secrets in config” → system- or user-assigned MI + Key Vault Secrets User.
- “Rebuild VMs monthly but keep the same role assignments” → user-assigned MI attached to each new VM.
- “Developer wants to paste a client secret into Function app settings for Azure SQL” → prefer MI + Entra auth to SQL instead.
- “Security asks who can create user-assigned identities” → control with Azure RBAC on the subscription/resource group (Managed Identity Contributor patterns) and landing-zone policy.
What is the primary credential-management benefit of using a managed identity for an Azure Function that calls Azure Key Vault?
A team assigns the Azure RBAC Reader role on a storage account to a web app’s managed identity. The app still cannot download blobs. What is the most likely issue?
Which statement correctly contrasts system-assigned and user-assigned managed identities?
An App Service has both a system-assigned managed identity and two user-assigned managed identities. The app must call Key Vault as one specific user-assigned identity. What should the developers ensure?