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 remove the password entirely with Microsoft Entra authentication and a managed identity. On the Azure SQL server I set an Entra admin group and, ideally, enable Entra-only authentication so SQL logins can't be used at all. I turn on a managed identity for the App Service or Container App. Then, connected as the Entra admin, I run
CREATE USER [orders-api] FROM EXTERNAL PROVIDERin the database and give it only the roles it needs, usually reader and writer; migrations run from the pipeline under a different identity that has DDL rights.The connection string becomes
Server=tcp:myserver.database.windows.net;Database=orders;Authentication=Active Directory Default;Encrypt=True.Microsoft.Data.SqlClientusesDefaultAzureCredentialbehind that keyword, gets a token for the managed identity and refreshes it, soUseSqlServerdoesn't change. Locally the same string picks up myaz loginor Visual Studio account, so there is no secret in user-secrets either. For a user-assigned identity I useActive Directory Managed IdentitywithUser Idset to its client id, which avoids the credential chain probing other sources.The point is not convenience: a connection string with a password is a long-lived credential that ends up in config, logs and backups. With a managed identity there is nothing to leak or rotate, which lines up with the ACSC Essential Eight and reduces Notifiable Data Breach exposure."
{
"ConnectionStrings": {
"Orders": "Server=tcp:sql-orders-aue.database.windows.net,1433;Database=orders;Authentication=Active Directory Default;Encrypt=True;"
}
}
CREATE USER [app-orders-api] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [app-orders-api];
ALTER ROLE db_datawriter ADD MEMBER [app-orders-api];
| Keyword | Use |
|---|---|
Active Directory Default |
Same string for local dev and Azure |
Active Directory Managed Identity + User Id |
User-assigned identity, no credential probing |
| SQL login + password in Key Vault | Only when Entra auth is impossible |
Removing SQL logins from [six] services removed [six] secrets from Key Vault rotation, and a later leaked config file in a support ticket exposed no usable credential.
Checks secure production configuration.
Last updated 23 Nov 2026.