Hello Sumit Bhardwaj,
Thank you for posting your question on the Microsoft Q&A forum.
From your description, I understand that your Azure Web App is running a query against a Storage Account and you are encountering an error that you suspect is related to insufficient permissions for the Managed Identity or Service Principal used by the Web App. You would like to know how to determine and grant the necessary permissions to resolve this issue.
In similar scenarios, I have been able to reproduce this issue when a .NET Core Web API attempted to access a Storage Account without the Managed Identity being assigned the Storage Blob Data Contributor role.
Once this role was assigned, the error was resolved.
Typically, to read and write blobs in Azure Storage, the Managed Identity of the Web App needs the Storage Blob Data Contributor role. You can assign this role as follows:
Azure Portal:
- Go to your Azure Web App in the Azure Portal.
- In the left pane, under Settings, select Identity.
- Enable System assigned or select a User assigned identity.
- Click on Azure role assignments.
- Click Add role assignment.
- Set Scope to Storage, select the appropriate Subscription and Storage Account, and assign the role Storage Blob Data Contributor.
Or Using Azure CLI
az webapp identity assign --name <WEBAPPNAME> --resource-group <RESOURCEGROUP> az role
assignment create --assignee $(az webapp identity show --name <WEBAPPNAME> --resource-group <RESOURCEGROUP> --query principalId -o tsv) --role "Storage Blob Data Contributor" --scope /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCEGROUP>/providers/Microsoft.Storage/storageAccounts/<STORAGEACCOUNTNAME>
For more details on role-based access to Azure Storage, you can refer to the official documentation: Assign Azure roles using the Azure portal
Feel free to post back if you have any further questions or need assistance with the workaround.