azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Az cli authorization failed, when user has owner permissions

Open donets420 opened this issue 6 years ago • 6 comments

az feedback auto-generates most of the information requested below, as of CLI version 2.0.62

Describe the bug My user has owner permissions on tenant level. when I tried to run command "az account management-group show "name_mgmt" -e" I received error: AzureResponseError: code: AuthorizationFailed - , The client 'user_name' with object id 'xxx' does not have authorization to perform action 'Microsoft.Management/managementGroups/read' over scope '/providers/Microsoft.Management/managementGroups/name_mgmt' or the scope is invalid. If access was recently granted, please refresh your credentials.

To Reproduce az login az account management-group show "name_mgmt" -e

Expected behavior output of mgmt and nested objects

Environment summary azure-cli 2.13.0 core 2.13.0

extensions: account 0.2.1 ai-examples 0.2.4

donets420 avatar Oct 20 '20 21:10 donets420

add to S178

yonzhan avatar Oct 21 '20 00:10 yonzhan

I have found reason of my problem. If look to help (az account management-group show --help): Arguments --name -n [Required] : Name of the management group.

But it doesn't work with name, it works with management group id in general.

donets420 avatar Oct 21 '20 17:10 donets420

Yea, have just lost half my day due to this issue.

From the azure-cli help:

Arguments
    --name -n            [Required] : Name of the management group.

...

Examples
    Get a management group.
        az account management-group show --name GroupName

az account management-group show -n remediationMgmtGrp

  "displayName": "Remediation",
  "id": "/providers/Microsoft.Management/managementGroups/remediationMgmtGrp",
  "name": "remediationMgmtGrp",

So a human will see the instructions as saying use required arg --name and think that refers to the displayName when it actually refers to the name key.

ausfestivus avatar Nov 11 '20 04:11 ausfestivus

There are 2 issues we are facing here:

Issue 1: displayName can't be used to show the management group

This can be reproduced with:

> az account management-group create --name mg20201111 --display-name mg20201111-display
{
  "id": "/providers/Microsoft.Management/managementGroups/mg20201111",
  "name": "mg20201111",
  "properties": {
    ...
    "displayName": "mg20201111-display",
    "tenantId": "54826b22-38d6-4fb2-bad9-b7b93a3e9c5a"
  },
  "status": "Succeeded",
  "type": "/providers/Microsoft.Management/managementGroups"
}


> az account management-group show --name mg20201111
{
  ...
  "displayName": "mg20201111-display",
  "id": "/providers/Microsoft.Management/managementGroups/mg20201111",
  "name": "mg20201111",
  "roles": null,
  "tenantId": "54826b22-38d6-4fb2-bad9-b7b93a3e9c5a",
  "type": "/providers/Microsoft.Management/managementGroups"
}

> az account management-group show --name mg20201111-display
code: AuthorizationFailed - , The client '[email protected]' with object id '6d97229a-391f-473a-893f-f0608b592d7b' does not have authorization to perform action 'Microsoft.Management/managementGroups/read' over scope '/providers/Microsoft.Management/managementGroups/mg20201111-display' or the scope is invalid. If access was recently granted, please refresh your credentials.

For the terms we use in Azure:

  • id: the resource ID, like /providers/Microsoft.Management/managementGroups/mg20201111
  • name: the resource name. It is also the last part of the resource ID, like mg20201111

displayName is one of the properties and is not an Azure resource common property. In other words, it is specific to /providers/Microsoft.Management/managementGroups resource type.

Issue 2: the command raises AuthorizationFailed instead of ResourceNotFoundError

If the user doesn't have tenant-level permission, it is expected that CLI shows AuthorizationFailed because the user shouldn't have the permission to know whether the specified management group exists or not.

# Login with an account that doesn't have tenant-level permission
> az account management-group show --name mg20201111-display
code: AuthorizationFailed - , The client '[email protected]' with object id '6d97229a-391f-473a-893f-f0608b592d7b' does not have authorization to perform action 'Microsoft.Management/managementGroups/read' over scope '/providers/Microsoft.Management/managementGroups/mg20201111-display' or the scope is invalid. If access was recently granted, please refresh your credentials.

# Grant tenant level permission using another tenant-level Owner
> az role assignment create --assignee [email protected] --scope / --role Reader

# Now it shows ResourceNotFoundError
> az account management-group show --name mg20201111-display
ResourceNotFoundError: (NotFound) '/providers/Microsoft.Management/managementGroups/mg20201111-display' not found

jiasli avatar Nov 11 '20 06:11 jiasli

I will update the help message of --name (#15871). Thank you for the feedback.

jiasli avatar Nov 11 '20 07:11 jiasli

For others who end up here: Make sure that you specify which subscription azure-cli should look at.

You can run this command:

az account set --subscription xxx-subscription-id-here-xxx

worldsayshi avatar Jun 02 '22 09:06 worldsayshi