Not able to Access Billing info using Azure CLI

393 Views Asked by At

I created a service principal using rbac and using the subscription id and I was able to login and all CLI calls with Azure using this sp and this login

(creating SP az ad sp create-for-rbac -n "AppName1" --role contributor --scopes /subscriptions//resourceGroups/)

But when I call for billing info as: az consumption usage list --subscription Unauthorized. Request ID:

I am not sure what authentication permission scope to add to enable this. Tried too many things and somehow I feel I am not in the right direction. Any help will be greatly appreciated.

2

There are 2 best solutions below

0
On

Did you login with the service principle using the following command before hitting the billing/usage?

az login --service-principal -u <app-url> -p <password-or-cert> --tenant <tenant>

1
On

I believe the issue is that you assigned the “contributor” role at the resource group level and then trying to access a subscription level resource. Since you don’t have permission for that, you’re getting this “Unauthorized” error.

To fix this, please try to assign the “contributor” role at the subscription level for this service principal.