L12. Managed Identities and Workload Identity Federation
Video generating
Check back soon for the video lesson on Managed Identities and Workload Identity Federation
Implement managed identities and workload identity federation for the SC-300: understand system-assigned vs user-assigned managed identities, configure workload identity federation for external services like GitHub Actions, and eliminate credential management overhead.
Managed Identities Overview
Managed identities provide an automatically managed identity in Entra ID for Azure resources. They eliminate the need to store credentials in code, configuration files, or key vaults. The identity lifecycle is managed by Azure.
System-Assigned vs User-Assigned
| Feature | System-Assigned | User-Assigned |
|---|---|---|
| Lifecycle | Tied to the resource | Independent of any resource |
| Sharing | Cannot be shared | Can be assigned to multiple resources |
| Creation | Enabled on the resource | Created as a standalone Azure resource |
| Deletion | Deleted when resource is deleted | Deleted only when explicitly removed |
When to Use Each
System-assigned: Best for workloads that run on a single resource and need independent identities. Example: a single VM that needs to read from Azure Key Vault. User-assigned: Best for workloads that run on multiple resources and need a shared identity. Example: multiple VMs in a scale set that all need the same permissions to access a storage account. Exam tip: If a question describes multiple resources needing the same set of permissions, the answer is user-assigned managed identity. If the question describes a single resource with its own identity lifecycle, the answer is system-assigned.How Managed Identities Work
- Azure Resource Manager creates a service principal in Entra ID for the managed identity
- The resource is configured with the identity (certificate credential is provisioned automatically)
- The code running on the resource requests a token from the Azure Instance Metadata Service (IMDS) endpoint:
http://169.254.169.254/metadata/identity/oauth2/token - Entra ID returns an access token
- The code uses the token to access the target Azure service
169.254.169.254) is a link-local address only accessible from within the Azure resource. It cannot be reached from outside the VM, which prevents token theft from the network.
Assigning Permissions
Managed identities are granted access through Azure RBAC, just like user accounts:
az role assignment create \
--assignee <managed-identity-object-id> \
--role "Storage Blob Data Reader" \
--scope /subscriptions/<sub-id>/resourceGroups/<rg>/providers/Microsoft.Storage/storageAccounts/<account>
Workload Identity Federation
Workload identity federation enables external workloads (outside Azure) to access Azure resources without storing secrets. Instead of a client secret or certificate, the external workload presents a token from its own identity provider, and Entra ID trusts that token based on a configured trust relationship.
Common Scenarios
- GitHub Actions: A GitHub workflow accesses Azure resources using a federated credential instead of storing an Azure secret in GitHub
- Kubernetes (non-AKS): Pods in external Kubernetes clusters authenticate to Azure
- Google Cloud/AWS: Workloads in other clouds access Azure resources
Configuration Steps
- Create an app registration in Entra ID
- Add a federated credential specifying the external IdP (issuer URL), subject, and audience
- Grant the app registration RBAC permissions on Azure resources
- Configure the external workload to request tokens from its IdP and exchange them for Entra ID tokens
Managed Identity for Azure Services
Common Azure services that support managed identities: Virtual Machines, App Service, Functions, Logic Apps, Container Instances, AKS, Data Factory, and many more. Not all services support user-assigned identities, so check compatibility for specific scenarios.
- ✓System-assigned identities are tied to a single resource; user-assigned identities can be shared across multiple resources
- ✓The IMDS endpoint (169.254.169.254) is link-local and only accessible from within the Azure resource
- ✓Workload identity federation eliminates stored secrets by trusting tokens from external identity providers
- ✓Managed identities receive Azure RBAC permissions the same way user accounts do
- ✓User-assigned managed identities persist independently: they are not deleted when the resource is deleted
1. Multiple VMs in a scale set need the same permissions to access Azure Key Vault. Which managed identity type should you use?
2. A GitHub Actions workflow needs to deploy to Azure without storing any secrets in GitHub. What should you configure?
3. What happens to a system-assigned managed identity when the Azure resource it belongs to is deleted?