CostManagement REST API using a Managed Identity is failing authorization.

Alex Ho 0 Reputation points Microsoft Employee
2023-08-17T15:01:49.42+00:00

I'm setting up a Python script in an Azure Container Instance that will read costs from my resources using the CostManagement REST API through a Managed Identity. However, it is being rejected despite having the correct authorization. Important things to note:

  1. The query works correctly on my computer with my personal credentials
  2. The query does not work when run on an Azure Container Instance using a Managed Identity. Instead, I get the following error:

`{'error': {'code': 'AuthorizationFailed', 'message': "The client '

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
690 questions
Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
2,504 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Monalla-MSFT 12,861 Reputation points
    2023-08-31T19:05:44.72+00:00

    @Alex Ho - Welcome to Microsoft Q&A and thanks for reaching out to us.

    The issue might be because of not having necessary permissions for Managed Identity that is being used by Azure Container Instance to access the Cost Management REST API.

    Please ensure that Managed Identity has the appropriate role-based access control (RBAC) role for the Cost Management API. You can assign the Managed Identity the "Cost Management Contributor" role, which provides read and write access to cost management data.

    Hope this helps. and please feel free to reach out if you have any further questions.


    If the above response was helpful, please feel free to "Accept as Answer" and click "Yes" so it can be beneficial to the community.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.