Implementing passwordless access from a .NET 10 app to Key Vault, Azure SQL and Blob Storage with managed identity: Azure.Identity credentials, system vs user-assigned identities, RBAC role assignments in Bicep, contained SQL users, and local development.
Managed identity gives the app an Entra ID identity that Azure manages, so there is no secret to store or rotate. In code, Azure.Identity gets tokens: DefaultAzureCredential tries managed identity in Azure and the developer's az login or Visual Studio sign-in locally. Then:
AddAzureKeyVault.BlobServiceClient with the credential.CREATE USER [app-name] FROM EXTERNAL PROVIDER, add it to database roles, and use Authentication=Active Directory Default in the connection string.Use a user-assigned identity when several apps share access or it must survive redeploys. The trade-off is setup effort in RBAC and SQL users in exchange for no secrets at all.
"Managed identity is an Entra ID service principal tied to an Azure resource. The platform exposes a local token endpoint, and
Azure.Identityasks it for an access token for a specific resource, such ashttps://vault.azure.netorhttps://database.windows.net. Nothing secret is stored in my configuration; only resource URIs. There are two kinds. A system-assigned identity lives and dies with the app. A user-assigned identity is a separate resource I can attach to several apps, so role assignments survive redeploys and slot swaps, and I can create it and grant roles before the app exists. With user-assigned I must tell the credential which one to use by client id.In code I register one credential and pass it to every Azure client.
DefaultAzureCredentialis convenient because it tries environment variables, workload identity, managed identity and then developer tools like the Azure CLI and Visual Studio, so the same code runs locally and in Azure. In production I prefer to be explicit, withManagedIdentityCredentialor by restricting the chain, because probing credentials that don't exist adds startup latency and can hide misconfiguration. Then I grant data-plane roles on each resource: Key Vault Secrets User on the vault, Storage Blob Data Contributor on the container or account. Azure SQL is different: RBAC doesn't grant database access, so I create a contained user withCREATE USER [app-orders-prod] FROM EXTERNAL PROVIDERand add it todb_datareaderanddb_datawriter, and the connection string saysAuthentication=Active Directory Default.Locally, developers
az loginand are members of an Entra group that has the same roles on dev resources only. The mistake I see is granting Contributor at the subscription and wondering why reads still fail, or the opposite, granting Owner to make the 403 go away. Least privilege on the exact resource is the whole point."
| Resource | Role or permission | Scope |
|---|---|---|
| Key Vault (RBAC mode) | Key Vault Secrets User | The vault |
| Blob Storage | Storage Blob Data Reader or Contributor | Container or account |
| Service Bus | Azure Service Bus Data Sender / Receiver | Queue, topic or namespace |
| Azure SQL | Contained database user + db_datareader / db_datawriter |
The database |
| App Configuration | App Configuration Data Reader | The store |
| System-assigned | User-assigned | |
|---|---|---|
| Lifecycle | Deleted with the app | Independent resource |
| Shared across apps | No | Yes |
| Roles before the app exists | No | Yes (good for IaC ordering) |
| Code change | None | Pass client id (AZURE_CLIENT_ID or ManagedIdentityClientId) |
Moving a payments API from four connection strings and two storage keys to a user-assigned identity removed six secrets from Key Vault and the quarterly rotation runbook. Token acquisition added about 20–50 ms on the first call per resource, then nothing, because the SDK caches tokens and refreshes them before expiry.
Checks that the candidate can implement passwordless Azure access end to end, including the parts that are not RBAC.
Green flags
Red flags
App code ─▶ ManagedIdentityCredential.GetTokenAsync(scope = "https://vault.azure.net/.default")
─▶ local identity endpoint (IDENTITY_ENDPOINT + IDENTITY_HEADER on App Service)
─▶ Entra ID issues a JWT (aud = vault, oid = identity's object id)
App code ─▶ Key Vault: GET /secrets/Db-Password Authorization: Bearer <JWT>
Key Vault ─▶ checks RBAC assignments for that oid at that scope ─▶ 200 or 403
The identity endpoint is only reachable from inside the resource, which is why nothing secret has to be configured. Tokens last around an hour or more; the SDK caches them per scope and refreshes them early.
EnvironmentCredential → WorkloadIdentityCredential → ManagedIdentityCredential
→ VisualStudioCredential → AzureCliCredential → AzurePowerShellCredential
→ AzureDeveloperCliCredential → (interactive browser, off by default)
The first credential that returns a token wins. That makes local and cloud code identical, but it has costs: probing can add seconds at startup, and a developer credential may silently win where you expected managed identity. Options: use ManagedIdentityCredential in production and DefaultAzureCredential only in development, set Exclude* options, or use the AZURE_TOKEN_CREDENTIALS environment variable supported by recent Azure.Identity versions to limit the chain to development or production credentials.
Azure RBAC controls the server resource (control plane). Database access is SQL permissions. You set an Entra admin on the server, connect as that admin, and run:
CREATE USER [id-orders-api-prod] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [id-orders-api-prod];
ALTER ROLE db_datawriter ADD MEMBER [id-orders-api-prod];
Microsoft.Data.SqlClient gets the token itself when the connection string has Authentication=Active Directory Default (or Active Directory Managed Identity with User Id=<client id> for a user-assigned identity). Turning on Entra-only authentication on the server then removes SQL logins and passwords entirely.
New role assignments usually apply within a few minutes, but can take up to about 10. Changes made through group membership for a managed identity can take hours, because the identity's tokens are cached by the platform. In IaC, create role assignments before the app's first deployment, or use a user-assigned identity created in an earlier step.
Developers sign in with az login (or Visual Studio). Put developers in an Entra group, for example grp-orders-developers, with data roles on dev resources only. Production stays reachable only by the production identity. For local emulators (Azurite, SQL in a container), use connection strings in user secrets and switch by environment.
ManagedIdentityCredential.GetTokenAsync; decode the token at jwt.ms and find oid and aud.Authentication=Active Directory Default.az login and with AZURE_TOKEN_CREDENTIALS=prod to see the chain change.Program.cs for passwordless access to Key Vault, Blob Storage and Azure SQL (EF Core), then the Bicep that grants the roles.
using Azure.Core;
using Azure.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Azure;
var builder = WebApplication.CreateBuilder(args);
// Explicit in Azure, convenient locally. A user-assigned identity needs its client id.
TokenCredential credential = builder.Environment.IsDevelopment()
? new DefaultAzureCredential()
: new ManagedIdentityCredential(
ManagedIdentityId.FromUserAssignedClientId(builder.Configuration["AZURE_CLIENT_ID"]!));
// Key Vault secrets as configuration, e.g. a third-party API key with no Entra support.
builder.Configuration.AddAzureKeyVault(new Uri(builder.Configuration["KeyVault:Uri"]!), credential);
builder.Services.AddAzureClients(c =>
{
c.AddBlobServiceClient(new Uri(builder.Configuration["Storage:BlobUri"]!));
c.UseCredential(credential);
});
// No password: SqlClient gets an Entra token for database.windows.net.
// Connection string: Server=tcp:sql-orders-prod-aue.database.windows.net,1433;Database=orders;
// Authentication=Active Directory Default;Encrypt=True;
builder.Services.AddDbContext<OrdersDbContext>(o =>
o.UseSqlServer(builder.Configuration.GetConnectionString("Orders")));
var app = builder.Build();
app.MapGet("/healthz", () => Results.Ok());
app.Run();
public sealed class OrdersDbContext(DbContextOptions<OrdersDbContext> options) : DbContext(options);
param location string = 'australiaeast'
resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: 'id-orders-api-prod'
location: location
}
resource vault 'Microsoft.KeyVault/vaults@2023-07-01' existing = { name: 'kv-orders-prod-aue' }
resource storage 'Microsoft.Storage/storageAccounts@2023-05-01' existing = { name: 'stordersprodaue' }
// Built-in role ids
var keyVaultSecretsUser = '4633458b-17de-408a-b874-0445c86b69e6'
var storageBlobDataContributor = 'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
resource kvRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(vault.id, identity.id, keyVaultSecretsUser) // deterministic: re-deploys are idempotent
scope: vault
properties: {
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', keyVaultSecretsUser)
principalId: identity.properties.principalId
principalType: 'ServicePrincipal'
}
}
resource blobRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(storage.id, identity.id, storageBlobDataContributor)
scope: storage
properties: {
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', storageBlobDataContributor)
principalId: identity.properties.principalId
principalType: 'ServicePrincipal'
}
}
-- Run once as the server's Entra admin, in the orders database.
CREATE USER [id-orders-api-prod] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [id-orders-api-prod];
ALTER ROLE db_datawriter ADD MEMBER [id-orders-api-prod];
CREATE USER ... FROM EXTERNAL PROVIDER and add it to the right database roles.AZURE_CLIENT_ID or ManagedIdentityClientId.DefaultAzureCredential chain in production. Why it is wrong: It probes credentials that don't exist, slows startup and can mask a missing identity. Instead: Use ManagedIdentityCredential in Azure or restrict the chain.Microsoft.Data.SqlClient and check its documented Authentication values.The win is not only no secrets; it is that access becomes reviewable. Every permission is a role assignment in Bicep that shows up in a pull request, and Entra sign-in logs show which identity touched which resource. For the few services without Entra support (some third-party APIs), Key Vault stays, read through the same identity.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| System-assigned identity | One app, simple lifecycle | Free, zero config | Roles must exist before deploy; shared access |
| User-assigned identity | Several apps, IaC ordering, slots | One more resource to manage | Tiny single app |
| Workload identity federation | AKS pods, GitHub Actions | Federated credential setup | Code running on App Service (use managed identity) |
| Key Vault secret | Third-party system without Entra | Rotation work | Azure services that support Entra auth |
I measure success by the number of secrets in Key Vault going down and by Entra sign-in logs showing only managed identities hitting production data.
Use Microsoft Entra ID authentication with a managed identity. Steps: 1. set a Microsoft Entra admin on the Azure SQL logical server (optionally enable Microsoft Entra-only authentication to turn off SQL logins); 2. turn on a system- or user-assigned managed identity on the App Service, Container App or AKS workload; 3. connected as the Entra admin, create a contained user for it in the database, CREATE USER [my-api] FROM EXTERNAL PROVIDER;, and grant least privilege (db_datareader, db_datawriter, no DDL for the app); 4. use a connection string with Authentication=Active Directory Default (or Active Directory Managed Identity plus User Id=<client id> for a user-assigned identity). Microsoft.Data.SqlClient gets and refreshes tokens itself, so EF Core needs no code change, and locally the same string uses your Azure CLI or Visual Studio sign-in. No secret exists to leak or rotate.
I'd inventory and classify every setting first: secrets, environment-specific values, shared values, and which must change live. Secrets go to Key Vault. Non-secret settings and feature flags go to Azure App Configuration with a label per environment, and secrets are referenced from there through Key Vault references. The app authenticates with its managed identity using least-privilege roles, and where possible secrets disappear entirely through passwordless Entra ID auth to SQL, Storage and Service Bus.
For refresh, use a sentinel key with a refresh interval and a secret refresh interval, and read live values through IOptionsMonitor. Rotation uses overlapping versions, so old and new both work during the window. Add start-up timeouts and replicas, and keep ValidateOnStart.
The trade-off: central, audited, rotatable configuration, in exchange for a network dependency at start-up that you must design for.
A typical .NET team uses a small, repeatable set of Azure services:
Everything is wired together with managed identity and Entra ID RBAC, not connection strings, and deployed with infrastructure as code. The trade-off: managed PaaS services remove patching and plumbing, but you accept each service's limits, pricing model and region availability.
How to tell it (STAR)
**S:** Our payments API had [four] connection strings and [two] storage keys, and one key had turned up in a support ticket just before a security review. **T:** I owned removing shared secrets without downtime. **A:** I created a user-assigned identity in Bicep with data roles on Key Vault and Storage, added a contained SQL user, and switched the code to one shared `TokenCredential`. We released through a staging slot, then disabled shared key access and SQL password logins. **R:** Six secrets and the quarterly rotation runbook disappeared, the review passed that control, and the storage logs showed [zero] key-based access afterwards.
Last updated 23 Nov 2026.