wasAsked.

Should we use managed identity or ClientID, client secret stored in azure KV? Both are secure. How to choose between the two?

Wipro · Role not specified · technical

Published

Year not specified · Azure, Authentication & Security

Community answers

Posted by wasAsked editorial collection

Both can be secure, but managed identity removes a whole class of risk, so it should be the default whenever the code runs on Azure. Managed identity - Azure creates and manages an identity for the resource (App Service, Functions, Container Apps, VM, AKS with workload identity). - No secret exists for you to store, leak, expire or rotate — Azure handles credentials internally. - Code uses DefaultAzureCredential or ManagedIdentityCredential; access is granted through Azure RBAC. - System-assigned identities share the resource's lifecycle; user-assigned identities can be shared by several resources and survive redeployments. Client ID + client secret (service principal) stored in Key Vault - You still need a way to read Key Vault — usually managed identity anyway — so you are adding a second credential behind the first. - Secrets expire (often within 6–24 months), must be rotated, and can leak through logs, configuration or developer machines. - If a secret leaks, it works from anywhere until revoked. Choose managed identity when - The workload runs in Azure and the target supports Microsoft Entra authentication: Key Vault, Storage, Service Bus, Event Hubs, Cosmos DB, Azure SQL, App Configuration, your own APIs protected by Entra ID. Use a client ID with a credential when - The workload runs outside Azure (on-premises servers, another cloud, some CI systems) — though even then, prefer workload identity federation (federated credentials with OIDC from GitHub Actions, Kubernetes or another cloud) or a certificate over a client secret. - A third-party or multi-tenant scenario requires an app registration you control. - A legacy SDK or service does not support managed identity. If you must use a secret - Store it in Key Vault, read it through managed identity, prefer certificates over secrets, set short expiry with automated rotation, and monitor sign-in logs for the service principal. Summary answer: "Inside Azure we use managed identity because there is no secret to manage. Client ID and secret are a fallback for workloads outside Azure, and even there we prefer federated credentials or certificates."

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics