Domain 1 β€” Module 4 of 6 67%
4 of 28 overall
Domain 1: Manage identity, access, and governance Free ⏱ ~12 min read

Managed Identities: Why You Should Never See a Connection String Again

How managed identities let Azure-hosted workloads authenticate to other Azure services without secrets β€” system-assigned vs user-assigned, when to use which, and the pattern that quietly defines half the right answers on SC-500.

The pattern that defines half the right answers on SC-500

Simple explanation

A managed identity is an Azure-managed service principal β€” an identity that exists for an Azure resource, with secrets that Azure creates, stores, and rotates for you. You never see a client secret, never put a connection string in code, never have a secret to leak.

When your code on Azure App Service (or Container Apps, or a Function, or a VM, or an AKS pod, or a Logic App…) wants to read from Key Vault, write to Cosmos DB, pull an image from ACR, or send a message to Service Bus, it just asks for a token from a local managed identity endpoint and presents that token to the target service. The target service trusts Microsoft Entra and authorises the request based on the RBAC role you assigned.

Two flavours exist:

  • System-assigned β€” tied to the lifecycle of one Azure resource. Created when you enable it on the resource; deleted when the resource is deleted. Cannot be shared.
  • User-assigned β€” a standalone Azure resource you create. Multiple Azure resources can use it. Survives the deletion of any one consumer.

The SC-500 pattern: any scenario where the proposed answer involves a connection string, a stored client secret, or β€œrotate the key every 90 days” β€” there is almost always a better answer involving a managed identity. Read every Azure-to-Azure auth question for this cue.

System-assigned vs user-assigned

System-assigned vs user-assigned managed identity β€” pick based on lifecycle and sharing
FeatureSystem-assignedUser-assigned
LifecycleBorn and dies with the parent Azure resourceIndependent β€” survives deletion of any consumer
Sharing across resourcesNo β€” exactly one consumerYes β€” many resources can attach the same identity
RBAC and permissions on recreationA new system-assigned identity has a new object ID β€” all role assignments and Graph consents must be re-appliedObject ID is stable β€” recreate consumers freely without re-granting
How to createToggle 'Identity' on the resource (portal, CLI, Bicep)Create a standalone `userAssignedIdentities` resource, then attach
Best forA single Azure resource with a small, well-scoped set of permissions and no need to shareMultiple instances of the same workload (e.g. an AKS workload across pods), or any case where identity must outlive a consumer
Per-consumer limitOne per resource (system-assigned)Per-service limit (e.g. multiple user-assigned on a single VM is supported)
Federated credentialsNot supportedSupported (workload identity federation for AKS, GitHub Actions, etc.)

When to pick which

  • One Azure resource, dedicated permissions, fine to lose-and-recreate β†’ system-assigned. Simplest model. Most App Service / Function / Logic App scenarios start here.
  • Multiple resources sharing the same access pattern (a fleet of VMs accessing the same Key Vault, an AKS workload across many pods) β†’ user-assigned. One identity, many consumers.
  • Need to grant role assignments BEFORE the consumer is created (so the workload comes up with access already in place) β†’ user-assigned. You can create the identity, grant the role, then create the consumer.
  • Federated workload identity (AKS pods using workload identity, GitHub Actions OIDC, external workloads) β†’ user-assigned. Only user-assigned supports federated credentials.

How Azure services consume managed identities

The general pattern for SC-500 questions:

  1. Enable managed identity on the Azure resource (system-assigned toggle, or attach a user-assigned).
  2. The Azure resource gets a service principal in Entra ID with an object ID.
  3. Grant that service principal an RBAC role on the target Azure resource (or grant Microsoft Graph application permissions for Graph calls).
  4. The workload, running in the Azure resource, requests a token from the local IMDS endpoint using the Azure Identity SDK (DefaultAzureCredential in .NET / Python / Java / JavaScript).
  5. The token is presented to the target service; the target service authorises based on the granted role.

This pattern replaces a long list of antipatterns:

Common 'connection string' antipatterns and their managed-identity replacements
FeatureAntipattern (wrong answer)Managed identity (right answer)
Auth to Key VaultBake `--client-secret` into App Service app settingsEnable system-assigned MI on App Service, grant `Key Vault Secrets User` role
Auth to StorageStore storage account key in code or in a config fileMI on the workload, grant `Storage Blob Data Contributor` role
Auth to Service BusUse a connection string with SAS keyMI on the workload, grant `Azure Service Bus Data Sender` role
Auth to Cosmos DBEmbed master key in code or configMI on the workload, grant `Cosmos DB Built-in Data Contributor`
Auth to ACR for image pullUse admin user (`acrAdmin` enabled) with username/passwordMI on the compute (App Service / Container Apps / AKS), grant `AcrPull`
Auth to SQLSQL auth user with password in a connection stringMI on the workload, create contained user mapped to MI in SQL, grant minimum DB rights
Auth to Microsoft GraphApp registration with client secret in Key Vault, rotate every 90 daysMI on the workload, grant required Graph application permission with admin consent
Exam pattern: 'remove the connection string'

When an SC-500 scenario sounds like:

β€œRavi at Maple Genomics has an Azure Function that calls Key Vault using a client secret stored in App Settings. The security team wants to eliminate stored secrets. What should Ravi do?”

The right answer almost always includes:

  1. Enable a system-assigned (or attach a user-assigned) managed identity on the Function App.
  2. Grant the managed identity the appropriate RBAC role on the target resource β€” for Key Vault Secrets, that’s Key Vault Secrets User (read) or Key Vault Secrets Officer (read/write).
  3. Update the application code to use DefaultAzureCredential from the Azure Identity SDK β€” which will automatically pick up the managed identity in Azure-hosted environments.

Wrong answers will typically suggest: rotating the secret, using Key Vault references (still uses a secret under the hood at the policy level β€” managed identity is preferred), or storing the secret in a separate Key Vault (still a secret). The pattern is: when the question contains β€œstored secret” + β€œAzure-to-Azure auth”, the answer is managed identity.

Where managed identities are supported

The list of Azure services that support managed identities is long and grows. Key services on SC-500 scope:

  • Compute β€” App Service, Azure Functions, Logic Apps (standard plan), Azure Container Apps, AKS (via workload identity federation with user-assigned), Virtual Machines, Virtual Machine Scale Sets, Azure Container Instances, Service Fabric, Azure Batch.
  • Data / messaging targets (as the target of MI-based auth) β€” Key Vault, Storage (Blob, Queue, Table, Files via REST), Azure SQL, Cosmos DB, Service Bus, Event Grid, Event Hubs, Azure Managed Redis, Container Registry.
  • APIs β€” Microsoft Graph (application permissions), Azure Resource Manager, Defender for Cloud APIs.

Notably, App Service and Container Apps support both system-assigned and user-assigned. AKS uses workload identity federation with a user-assigned MI to bind a Kubernetes service account to an Entra identity β€” no secrets in the cluster.

Scenario: Esme rebuilds a legacy app pattern

Esme at Northwind Bank inherits a legacy App Service Web App that reads from Azure SQL and writes audit events to Service Bus. It uses two SQL connection strings (read replica + primary) with passwords, and a Service Bus connection string β€” all stored in App Settings. The auditor wants secrets eliminated.

Her remediation:

  1. Enable system-assigned MI on the App Service. One toggle, one minute.
  2. Configure SQL. In Azure SQL, set a Microsoft Entra admin. Connect with the admin and run CREATE USER [northwind-payments-app] FROM EXTERNAL PROVIDER (where northwind-payments-app matches the App Service name β€” the system-assigned MI is named after the resource). Grant db_datareader and db_datawriter. Replace the SQL connection string with an Entra-authenticated one (Authentication=Active Directory Default;...).
  3. Configure Service Bus. Assign the App Service’s MI the Azure Service Bus Data Sender role on the target Service Bus namespace (or queue/topic). Update code from ServiceBusClient(connectionString) to ServiceBusClient(fullyQualifiedNamespace, new DefaultAzureCredential()).
  4. Delete the app settings holding the old connection strings. Rotate the SQL admin password and Service Bus SAS key out of memory of any operator who knew them.

The App Service now holds no secrets. Auditor closes the finding. If the App Service is deleted and recreated, Esme rebinds the new MI’s object ID in SQL and re-assigns the Service Bus role β€” a 10-line script. (Alternatively, she could have used a user-assigned MI to make recreation trivial; for a single long-lived web app, system-assigned was the right call.)

Key terms

Question

What is a managed identity in Microsoft Entra ID?

Click or press Enter to reveal answer

Answer

An automatically-managed service principal for an Azure resource, with credentials created, stored, and rotated by Azure. The Azure-hosted workload obtains tokens via the local Instance Metadata Service (IMDS) endpoint. Two flavours: system-assigned (lifecycle tied to the resource) and user-assigned (standalone resource, shareable).

Click to flip back

Question

When should you use a user-assigned managed identity instead of system-assigned?

Click or press Enter to reveal answer

Answer

When multiple Azure resources need the same identity (a fleet of VMs, multiple AKS workloads), when the identity must outlive any individual consumer, when you need to grant permissions before the consumer exists, or when you need federated credentials (workload identity for AKS, OIDC from GitHub Actions).

Click to flip back

Question

What is `DefaultAzureCredential` in the Azure Identity SDK?

Click or press Enter to reveal answer

Answer

A credential chain in the Azure Identity SDK that tries multiple authentication methods in order β€” including environment variables, managed identity (in Azure-hosted environments), Azure CLI/PowerShell signed-in user, and others. Lets the same code authenticate as a developer locally and as a managed identity in production with no code change.

Click to flip back

Question

What happens to RBAC role assignments when you disable and re-enable a system-assigned managed identity?

Click or press Enter to reveal answer

Answer

The system-assigned MI gets a new object ID on re-enable, so all RBAC role assignments and Microsoft Graph application permission grants must be re-applied to the new object ID. This is a key reason to choose user-assigned MI when consumers might be recreated β€” user-assigned has a stable object ID across consumer recreations.

Click to flip back

Question

What is workload identity federation, and how does it relate to managed identities?

Click or press Enter to reveal answer

Answer

A way for external workloads (AKS pods via Kubernetes service accounts, GitHub Actions via OIDC, other clouds) to obtain Entra tokens by presenting their native identity assertion to a federated credential configured on a user-assigned managed identity. Eliminates client secrets for external-to-Azure auth.

Click to flip back

Knowledge check

Knowledge Check

Ravi at Maple Genomics has an Azure Function that reads secrets from Key Vault using a stored client ID and client secret of an app registration. He wants to eliminate the stored secret. What is the most direct change?

Knowledge Check

Asha at Aurora Health Service is deploying a 12-VM scale set where every VM needs the same access to a shared Storage account. She wants the role assignment to outlive any individual VM. Which managed identity should she use?

Knowledge Check

Esme at Northwind Bank deletes an App Service and recreates it with the same name. The new App Service has system-assigned MI re-enabled. The application now gets `Forbidden` errors when reading Key Vault secrets. What is the most likely cause?

What’s next

Next module: Azure Key Vault itself β€” how to deploy it securely, configure firewall and access (the RBAC vs access-policy decision), enable Defender for Key Vault, and use Defender CSPM secret scanning to find rogue secrets across your subscriptions.