Workload Identities: Managed Identities & Service Principals
Choose the right identity for your workloads β managed identities, service principals, and when to use each one to securely connect Azure resources without storing credentials.
What are workload identities?
Workload identities are ID badges for your apps and services β not for people.
Imagine a hotel. Guests (users) check in at the front desk and get a room key. But the housekeeping robot that delivers towels also needs a key to move between floors. You wouldnβt give the robot a guest room β youβd give it a special staff pass that only opens the doors it needs.
Workload identities are those staff passes. They let your applications, scripts, and automation prove who they are and access only the resources theyβre allowed to touch β without anyone typing in a password.
Types of workload identities
Not every workload needs the same type of identity. Hereβs the decision framework:
| Identity Type | Best For | Credentials |
|---|---|---|
| Managed identity | Azure resources talking to other Azure resources | None β Azure handles it automatically |
| Service principal | Non-Azure apps, multi-tenant apps, CI/CD pipelines | Certificate or client secret |
| User account | Never recommended for workloads (but sometimes inherited) | Password β risky for automation |
| Managed service account | On-premises services (Active Directory) | Password managed by AD automatically |
| Feature | Managed Identity | Service Principal | User Account |
|---|---|---|---|
| Credential management | Automatic (Azure) | Manual (you rotate) | Manual (you rotate) |
| Works outside Azure | No | Yes | Yes |
| Can be shared across resources | User-assigned: Yes | Yes | Yes (bad practice) |
| Appears in Entra ID | As enterprise app | As enterprise app | As user object |
| Supports Conditional Access | Limited | Yes | Yes |
| Risk of credential leak | None | Medium | High |
| Exam recommendation | Preferred for Azure | When managed identity isn't possible | Never for workloads |
Exam tip: The golden rule
The SC-300 exam strongly favours managed identities whenever the workload runs on Azure. If a question asks about an Azure VM, Azure Function, or App Service accessing a Key Vault or Storage Account, the answer is almost always βuse a managed identity.β Service principals are the fallback for non-Azure scenarios or multi-tenant apps.
Managed service accounts β the on-prem option
Managed service accounts (MSAs) and group managed service accounts (gMSAs) are Active Directory objects for on-premises services. Theyβre NOT Entra ID objects β they live in on-prem AD only.
| Type | Scope | Managed By |
|---|---|---|
| Managed service account (MSA) | Single server | AD auto-rotates the password |
| Group managed service account (gMSA) | Multiple servers (clustered services) | AD auto-rotates, all servers in the group use it |
When the exam mentions managed service accounts: Itβs testing whether you know these are on-premises AD identities, not cloud identities. If the workload runs in Azure β managed identity. If the workload is an on-prem Windows service β gMSA. Donβt confuse the two.
Managed identities β deep dive
A managed identity is a special type of service principal that Azure manages for you. You never see or handle its credentials β Azure rotates them automatically behind the scenes.
System-assigned vs user-assigned
| Feature | System-Assigned | User-Assigned |
|---|---|---|
| Created with | The Azure resource (e.g., VM) | Independently as a standalone resource |
| Lifecycle | Tied to the resource β deleted when resource is deleted | Independent β persists until you delete it |
| Sharing | One identity per resource | One identity across multiple resources |
| Use case | Single resource needs access to one or two services | Multiple resources need the same permissions |
| Management overhead | Lower β automatic cleanup | Higher β you manage the lifecycle |
Scenario: Ravi chooses the right identity
π» Ravi Patel at NovaTech Solutions is deploying a new patient-data API on Azure App Service. The API needs to:
- Read secrets from Azure Key Vault
- Write logs to Azure Storage
Ravi considers his options:
- User account? No β passwords would be in config files, violating compliance.
- Service principal with a secret? Possible, but heβd need to rotate the secret every 6 months and store it somewhere secure (chicken-and-egg problem).
- Managed identity? Yes β Azure handles credentials automatically, no secrets in code, no rotation headaches.
Ravi enables a system-assigned managed identity on the App Service because only this one API needs access. He then assigns the Key Vault Secrets User role and the Storage Blob Data Contributor role to the managed identity.
Result: Zero credentials in code. Zero rotation burden. Full audit trail in Entra ID.
Creating and assigning managed identities
Enable a system-assigned managed identity:
- Go to the Azure resource (e.g., App Service) β Identity blade
- Under System assigned, toggle Status to On
- Click Save β Azure creates the identity and shows you the Object ID
Create a user-assigned managed identity:
- Go to Entra admin center β Managed identities (or Azure portal β search βManaged identitiesβ)
- Click Create β choose subscription, resource group, region, and name
- After creation, go to the Azure resource β Identity β User assigned tab
- Click Add β select the managed identity
Grant access to a target resource (RBAC):
- Go to the target resource (e.g., Key Vault)
- Access control (IAM) β Add role assignment
- Select the role (e.g.,
Key Vault Secrets User) - Under Members, choose Managed identity β select your identity
- Save
Scenario: Priya uses user-assigned for shared access
π Priya Sharma at Meridian Health has 12 Azure Functions that all need to read from the same Storage Account containing medical imaging data. Instead of enabling 12 separate system-assigned identities and granting each one access, Priya:
- Creates one user-assigned managed identity called
mi-imaging-reader - Assigns the
Storage Blob Data Readerrole tomi-imaging-readeron the Storage Account - Attaches
mi-imaging-readerto all 12 Azure Functions
Result: One identity, one role assignment, 12 functions. When a new function is added, Priya just attaches the same identity β no new role assignments needed.
Using a managed identity in code
When your app runs on an Azure resource with a managed identity enabled, it can request tokens from the Azure Instance Metadata Service (IMDS) without any credentials:
# Python example using Azure SDK
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
credential = DefaultAzureCredential()
client = SecretClient(vault_url="https://my-vault.vault.azure.net", credential=credential)
secret = client.get_secret("api-key")
The DefaultAzureCredential class automatically detects the managed identity β no connection strings, no passwords, no environment variables with secrets.
Exam tip: DefaultAzureCredential chain
DefaultAzureCredential tries multiple authentication methods in order: environment variables β managed identity β Visual Studio β Azure CLI β interactive browser. On an Azure resource, it picks up the managed identity automatically. This is the recommended approach in Microsoft documentation and likely appears in exam scenarios.
Service principals β when managed identity isnβt enough
A service principal is the local representation of an application in your tenant. When you register an app in Entra ID or consent to a third-party app, a service principal is created automatically.
When you need a service principal instead of a managed identity:
- Your workload runs outside Azure (on-premises server, AWS, GCP)
- You need a multi-tenant application identity
- Your CI/CD pipeline (GitHub Actions, Azure DevOps) needs to deploy Azure resources
- You need workload identity federation (trust a token from an external identity provider without secrets)
Scenario: Ravi sets up CI/CD with workload identity federation
π» Ravi needs GitHub Actions to deploy code to Azure. Instead of storing a client secret in GitHub:
- He creates an app registration in Entra ID
- Adds a federated credential that trusts tokens from GitHubβs OIDC provider
- Configures the GitHub Actions workflow to request a token and exchange it for an Azure access token
Result: No secrets stored in GitHub. The federation trust means GitHub proves its identity via OIDC, and Entra ID issues a short-lived token. This is Microsoftβs recommended approach for CI/CD pipelines.
Workload identity security
Workload identities are increasingly targeted by attackers because they often have broad permissions and are less monitored than user identities.
Best practices:
- Use managed identities wherever possible (zero credential risk)
- Apply least-privilege RBAC β donβt give a managed identity
ContributorwhenReadersuffices - Set short expiry on service principal secrets and certificates (Microsoft recommends certificates over secrets)
- Use Conditional Access for workload identities (requires Workload Identities Premium licence) to restrict sign-ins by location or risk
- Monitor with Entra ID Protection β it can detect anomalous sign-in behaviour for service principals
π¬ Video walkthrough
π¬ Video coming soon
Workload Identities β SC-300 Module 16
Workload Identities β SC-300 Module 16
~12 minFlashcards
Knowledge Check
Ravi at NovaTech is deploying an Azure Function that needs to read secrets from Azure Key Vault. The function runs entirely in Azure. What identity type should Ravi use?
Priya has 8 Azure Web Apps that all need read access to the same Azure SQL Database. She wants to minimise the number of role assignments. What should she do?
Ravi needs GitHub Actions to deploy infrastructure to Azure. His security team prohibits storing any long-lived secrets in GitHub. What should Ravi configure?
Next up: Enterprise Apps: SSO, App Proxy & Integration β how to connect SaaS applications and on-premises apps to Entra ID for single sign-on and secure remote access.