App Service and Manged Identity
You have a web application (App Service) that needs to fetch a database connection string stored in Azure Key Vault. Instead of hardcoding credentials, the app uses Managed Identity for secure authentication.
Application → Managed Identity → Azure AD → Token → Key Vault → Azure AD → OpenID → Secrets → Application
Security Benefits
No Secrets in Code: Connection strings and API keys stay in Key Vault
Automatic Rotation: Key Vault handles secret rotation
Managed Identity: No service principal credentials to manage
Azure AD Integration: Leverages enterprise-grade authentication
Audit Trail: All access is logged in Azure Monitor
This authentication flow enables Azure services to securely access secrets without storing credentials in code. An application uses its managed identity to obtain a token from Azure AD, which Key Vault validates via OpenID Connect before providing secrets. This eliminates the need for hardcoded connection strings or API keys, leveraging Azure's built-in identity management for secure, credential-free access to protected resources like databases and API keys.
🔄 Flow Explanation
-
Application → Managed Identity
-
The application code (running in Azure App Service, VM, Function, etc.) requests an access token from its system-assigned managed identity.
-
Example (C#):
-
-
Managed Identity → Azure AD
-
The Managed Identity endpoint (provided by Azure infrastructure) forwards this request to Azure Active Directory.
-
Azure AD authenticates the Managed Identity (since it’s already registered in AD by Azure).
-
-
Azure AD → Token Issued
-
Azure AD issues a JWT access token scoped for Azure Key Vault (https://vault.azure.net).
-
This token proves: “This app is who it claims to be.”
-
-
Managed Identity → Key Vault
-
The Managed Identity now sends this token to Azure Key Vault along with the request:
-
-
Key Vault → Azure AD (Validation)
-
Key Vault checks the token with Azure AD (OpenID Connect metadata) to validate authenticity (issuer, signature, expiration, etc.).
-
-
Azure AD → Confirmation
-
Azure AD confirms: “Yes, this token is valid and issued to this Managed Identity.”
-
-
Key Vault → Returns Secret
-
Key Vault checks RBAC/Access Policies → if the Managed Identity has Get Secret permissions, it returns the secret (e.g., database connection string) to the application.
-
-
Application → Uses Secret
-
The application now safely uses the retrieved connection string without ever storing credentials in code.
-
✅ Example in Action
-
Web App runs code → Calls Managed Identity endpoint.
-
Managed Identity → Gets token from Azure AD.
-
Web App uses token → Calls Key Vault.
-
Key Vault validates token with Azure AD → Returns secret.
🔐 Key Points:
-
The app never sees a password or client secret.
-
Azure AD is the central authority for authentication.
-
Key Vault enforces authorization (who can access what).
Comments
Post a Comment