I'm using the Azure cost management API to read monthly spend. Users are allowed to read the costs of the resource groups for which they have been given "Cost Management Reader" access. The cost management usage REST API seems to have a bug. Even though I've restricted access to specific resource groups, when I run the below POST request at subscription scope, it retrieves the costs for all resource groups. What I noticed is when no access is granted to any resource group, REST API returns a 401 response. But when I give access to even one resource group, then it returns costs for all resource groups. The behavior is not the same in azure portal.
https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.CostManagement/query?api-version=2019-11-01
{
"type": "Usage",
"timeframe": "MonthToDate",
"dataset": {
"granularity": "None",
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"grouping": [
{
"type": "Dimension",
"name": "ResourceGroup"
}
]
}
}