Based on your description, you’re dealing with a combination of RBAC and network security issues. Let me walk through the complete solution:
1. Managed Identity Configuration:
First, verify the managed identity is properly configured and the application is using it correctly. Run this from the VM to confirm identity access:
curl 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://storage.azure.com/' -H Metadata:true
This should return an access token. If it fails, the managed identity isn’t properly enabled.
2. RBAC Role Assignment:
You need “Storage Blob Data Reader” role, but verify the scope is correct:
- Navigate to Storage Account → Access Control (IAM) → Role assignments
- Confirm the system-assigned identity from your VM is listed
- Verify the role is assigned at storage account level or specific container level
- If you only need specific containers, assign at container scope for better security
Important: The role must be “Storage Blob Data Reader” (data plane) not “Reader” (management plane). These are different permission sets.
3. Storage Account Firewall Rules:
This is likely your primary issue. When “Selected networks” is enabled, you must explicitly allow access:
Option A - Service Endpoints (Recommended):
- Enable service endpoint on VM subnet: Subnet → Service endpoints → Add Microsoft.Storage
- Add subnet to storage firewall: Storage Account → Networking → Firewalls and virtual networks → Add existing virtual network
- Select your VNet and subnet
Option B - Trusted Azure Services:
Enable the exception: Storage Account → Networking → Exceptions → Check “Allow Azure services on the trusted services list to access this storage account”
This allows managed identity authentication to bypass firewall rules.
4. Storage Access Validation:
After configuring network rules, test access from the VM:
az storage blob list --account-name <storage-account> --container-name <container> --auth-mode login
If this works but your application still fails, the issue is in your application code’s credential chain.
5. Application Startup Considerations:
For application startup scenarios, implement retry logic. Managed identity token acquisition can occasionally fail during VM startup when the identity service isn’t fully initialized. Add exponential backoff:
- Initial retry after 2 seconds
- Subsequent retries with 5, 10, 30 second delays
- Maximum 5 retry attempts
6. Monitoring and Troubleshooting:
Enable storage account diagnostic logs to see detailed authentication failures:
- Storage Account → Diagnostic settings → Add diagnostic setting
- Enable StorageRead, StorageWrite logs
- Send to Log Analytics workspace
- Query for 403 errors to see exact failure reasons
Complete Checklist:
- [ ] System-assigned managed identity enabled on VM
- [ ] “Storage Blob Data Reader” role assigned to managed identity
- [ ] Role assignment propagated (wait 10 minutes after assignment)
- [ ] Service endpoint enabled on VM subnet
- [ ] VM subnet added to storage account firewall rules
- [ ] “Allow trusted Azure services” exception enabled
- [ ] Application using correct credential provider (DefaultAzureCredential)
- [ ] Retry logic implemented for startup scenarios
The combination of service endpoints and the trusted services exception should resolve your 403 errors. The firewall rules are almost certainly blocking your managed identity authentication attempts despite correct RBAC configuration.