I can help you troubleshoot this systematically. The 403 error indicates an authorization problem, and there are several layers to check:
1. Managed Identity RBAC Verification
First, confirm the managed identity is correctly assigned and active:
az functionapp identity show \
--name <function-app-name> \
--resource-group <rg-name>
Note the principalId. Then verify role assignments:
az role assignment list \
--assignee <principal-id> \
--scope <log-analytics-workspace-resource-id>
For custom log ingestion, “Log Analytics Contributor” is actually insufficient. You need “Monitoring Metrics Publisher” role or a custom role with Microsoft.Insights/Logs/Write permission. The Contributor role provides management plane access but doesn’t grant data plane write permissions for log ingestion.
2. Log Analytics Permissions and API Method
Determine which ingestion method you’re using:
- Legacy HTTP Data Collector API: Requires workspace ID and shared key (doesn’t use managed identity at all)
- Data Collection Rules (DCR): Uses Azure AD authentication with managed identity
If you’re using DCR-based ingestion (the modern approach), the managed identity needs:
- “Monitoring Metrics Publisher” role on the DCR resource
- Proper DCR configuration with the workspace as destination
- The DCR endpoint URL (not the workspace URL)
Verify your DCR configuration and ensure the managed identity has permissions on the DCR itself, not just the workspace.
3. Activity Log Review for Changes
Check Activity Logs for the workspace:
az monitor activity-log list \
--resource-id <workspace-resource-id> \
--start-time <yesterday> \
--query "[?contains(operationName.value, 'roleAssignments')]"
Look for:
- Role assignment deletions or modifications
- Workspace configuration changes
- Access control policy updates
- Any failed authentication attempts in the logs
Resolution Steps
- If using DCR-based ingestion, add the correct role:
az role assignment create \
--assignee <managed-identity-principal-id> \
--role "Monitoring Metrics Publisher" \
--scope <dcr-resource-id>
-
If using legacy API, either:
- Switch to DCR-based ingestion (recommended)
- Use workspace shared keys stored in Key Vault (less secure)
-
Verify the Function App code is using the correct endpoint URL:
- DCR: `https://.ingest.monitor.azure.com
- Legacy: `https://.ods.opinsights.azure.com
-
Test authentication separately:
- Use Azure CLI or PowerShell to test if the managed identity can authenticate to the workspace
- Check for any Conditional Access policies blocking service principal authentication
Common Gotcha: If your organization recently enabled Azure Policy for Log Analytics or deployed security baselines, there might be new policies preventing managed identity access. Check Azure Policy compliance for your workspace resource.
After making RBAC changes, wait 5-10 minutes for propagation, then test your function. If still failing, capture the detailed error response body - it often contains specific permission requirements that are missing.