You are developing a background worker service in C# that runs as a containerized application within Azure Container Apps. The service must run on a schedule without user interaction and authenticate to the Microsoft Identity Platform to read files from Microsoft Graph.
To comply with security policies, you must use Azure Managed Identities for authentication. The credentials must persist independently of the containerized app's lifecycle, allowing the container instances to be deleted, recreated, or scaled across different resource groups without requiring permissions to be reconfigured in Microsoft Entra ID.
Which approach should you use to implement this authentication?
- AEnable a system-assigned managed identity on the Azure Container App. Grant the identity the required Microsoft Graph application permissions, and initialize DefaultAzureCredential in your code without specifying a client ID.
- Create a user-assigned managed identity as a standalone Azure resource. Grant this identity the required Microsoft Graph application permissions, associate it with the Azure Container App, and initialize DefaultAzureCredential by passing the client ID of the user-assigned managed identity.Cevap
- CRegister a confidential client application in Microsoft Entra ID and generate a client secret. Store the secret in Azure App Configuration, reference it in the worker service using the syntax @Microsoft.KeyVault(SecretUri=...), and build the client using ConfidentialClientApplicationBuilder.
- DCreate a Shared Access Signature (SAS) token in the Microsoft Entra ID portal with the Directory.Read.All scope, store it in the application's configuration, and authenticate using PublicClientApplicationBuilder.
Cevap
Create a user-assigned managed identity as a standalone Azure resource. Grant this identity the required Microsoft Graph application permissions, associate it with the Azure Container App, and initialize DefaultAzureCredential by passing the client ID of the user-assigned managed identity.
The correct approach is to create a user-assigned managed identity. A user-assigned managed identity is created as a standalone Azure resource and has its own lifecycle independent of the Azure Container App. If the container app is deleted or recreated, the user-assigned identity and its assigned Microsoft Graph permissions persist. When initializing DefaultAzureCredential in code, the client ID of the user-assigned managed identity must be specified to ensure the SDK authenticates with the correct identity.
Adım Adım Çözüm
Anahtar Kavram
Managed Identities (system-assigned vs. user-assigned) and their lifecycle differences when authenticating to the Microsoft Identity Platform.