Managed identities provide an identity in Microsoft Entra ID for an Azure resource. Azure manages the credentials, and the workload obtains tokens from the platform. This reduces secret distribution and rotation work, but the identity still needs narrowly scoped Azure role assignments.
Before You Begin
- An Azure resource that supports managed identity.
- Permission to enable identity and create role assignments.
- The target resource and the minimum data-plane role required.
Recommended Approach
1. Choose identity lifecycle
Use a system-assigned identity when the identity should exist only with one resource. Use a user-assigned identity when multiple resources need a shared identity or the identity lifecycle should be independent of one compute resource.
2. Enable the identity
Open the resource configuration and enable its system-assigned identity, or create a user-assigned identity and associate it with the workload. Record the principal or client ID for later assignment.
3. Assign a narrow role
At the target resource, grant the identity the smallest suitable built-in or custom role at the narrowest scope. For Blob data access, choose a data-plane role such as Storage Blob Data Reader or Contributor only when required.
4. Acquire a token in the workload
Use the Azure SDK credential chain or managed identity endpoint supported by the hosting environment. Avoid embedding client secrets or account keys as a fallback.
5. Verify and monitor
Test the exact operation from the deployed resource. Confirm access is denied at broader scopes and review role assignments periodically. Remove assignments when the workload is retired.
Operational Considerations
Cloud storage and compute designs should account for security, availability, lifecycle, and cost together. Decide where data resides, how long it is retained, which identities can reach it, and how the service behaves during a regional or credential failure. Separate production and test resources when their access needs differ. Review data-transfer charges, request volume, version retention, and abandoned multipart uploads as part of routine operations.
How to Verify the Result
Test the workflow using the same role and network path that the deployed application will use. Verify successful access to the intended object or service, denial for an unrelated object, and behavior after a temporary credential expires. Check logs for the principal and operation, and confirm that lifecycle, versioning, and backup settings match the data-retention policy.
Example Configuration
Illustrative example — adapt values to your environment
# Python example using the Azure SDK credential chain
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient
credential = DefaultAzureCredential()
client = BlobServiceClient(
account_url="https://mystorageacct.blob.core.windows.net",
credential=credential
)
Common Mistakes to Avoid
- A managed identity does not automatically have permission to read or write a resource.
- Do not grant Owner or Contributor at subscription scope when a data-plane role on one storage account is sufficient.
- System-assigned identities are deleted with their resource; account for this when replacing infrastructure.
Make one change at a time, test it from the perspective of the actual user or application, and record the reason for the change. Keep a rollback path for network, identity, and production configuration changes.
Final Checklist
- The configuration matches the intended environment and service version.
- Access is limited to the required identities, resources, ports, and operations.
- The expected workflow has been tested, including a negative test for unauthorized access.
- Secrets and temporary credentials are protected and excluded from logs and source control.
- The configuration owner, purpose, and review or expiration date are documented.