, Mark Joseph Colibao, home

What a managed identity is

An identity Azure creates for your app, so the app can sign in to other services without a secret to store or rotate.

Written 2 min read

When one program calls another service, it has to prove who it is. Usually that means a password, a key or a connection string, saved somewhere the program can read it. Whoever else can read it can use it too.

A managed identity is an identity in Microsoft Entra ID that Azure creates for your app and manages for you. The app never sees a password. When it needs to call a service, it asks the Azure platform it runs on for a token, and Azure answers only that app.

The same storage client, with a key and without one

With a key

appsettings.json
"Storage": {
  "ConnectionString":
    "DefaultEndpointsProtocol=https;
     AccountName=<account>;
     AccountKey=<key>"
}
  • A secret sits in the settings.
  • Anyone who can read it can use it.

With a managed identity

Program.cs
var credential = new DefaultAzureCredential();
var blobs = new BlobServiceClient(
    new Uri(builder.Configuration["Storage:BlobServiceUri"]!),
    credential);
  • The settings hold only the endpoint.
  • The app gets a token from its host's local endpoint.
  • Tokens expire, and the SDK fetches new ones.

How it works, step by step

  1. You turn on the identity for the app (a Container App, App Service, Function, VM, and others).
  2. Entra ID creates a service principal for it. That's the "user" other services will see.
  3. You give that identity roles on the resources it needs, like "read and write blobs in this storage account".
  4. At runtime the app asks a local endpoint on its host for a token for a given service.
  5. The app sends the token with its request. The service checks it, looks up the identity's roles, and allows or refuses the call.

The app never sees or stores the identity's credentials; Azure keeps them. Tokens expire, and the Azure SDKs fetch new ones for you through DefaultAzureCredential.

Two kinds

  • System-assigned: belongs to one resource, can't be shared, and is deleted with it. Simple, and a good default for one app.
  • User-assigned: a separate resource with its own life cycle that you can attach to several apps. Useful when you need the identity to exist before the app, or when several apps really need the same access.

What it doesn't do

  • It doesn't decide what the app may do. Roles do. An identity with Owner rights is just as dangerous as a leaked key, so give it only what it needs.
  • It only works for code running on Azure. On your laptop, DefaultAzureCredential uses your own sign-in (az login) instead, so the same code runs in both places.
  • Not every service accepts it. A few still need a key. Check the service's docs before you plan around it.

Sources