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

Not able to update tag with tag contributors role

Open johnakash opened this issue 6 years ago • 5 comments

Describe the bug We are trying to update / add tag to resource group using a service principal. While using PowerShell it is working as expected. But when we are trying to update tag via JAVA sdk we are getting following error

The client 'f73daaab-9eaf-484d-83e9-b22ecbf00102' with object id 'f73daaab-9eaf-484d-83e9-b22ecbf00102' does not have authorization to perform action 'Microsoft.Resources/subscriptions/resourcegroups/write' over scope '/subscriptions/be1bsdfnb-fhfd-4ce7-b323-6732ecc0987/resourcegroups/test-RG' or the scope is invalid. If access was recently granted, please refresh your credentials.

To Reproduce

  1. Create a service principal
  2. Attach tag contributor
  3. Run java code to update resource group

Command used az group update --resource-group test-RG --set tags.CostCenter='{"Dept":"IT","Environment":"Test"}' Environment summary

az --version
azure-cli                          2.9.1
command-modules-nspkg              2.0.3
core                               2.9.1
nspkg                              3.0.4
telemetry                          1.0.4
Python location '/usr/local/Cellar/azure-cli/2.9.1/libexec/bin/python'
Extensions directory '/Users/akashjohn/.azure/cliextensions'
Python (Darwin) 3.8.5 (default, Jul 21 2020, 10:48:26)
[Clang 11.0.3 (clang-1103.0.32.62)]
Legal docs and information: aka.ms/AzureCliLegal
Your CLI is up-to-date.
Please let us know how we are doing: https://aka.ms/azureclihats
and let us know if you're interested in trying out our newest features: https://aka.ms/CLIUXstudy

johnakash avatar Jul 23 '20 18:07 johnakash

add to S174

yonzhan avatar Jul 23 '20 22:07 yonzhan

@johnakash In fact, there are two types of commands to manage tags:

  1. Based on the respective Resource Provider Such as az resource tag and az group update ... --set tags.xxx , it seems that at the moment each RP has its own permission control and does not get through with the Tag Contributor role.
  2. Based on ARM service Such as az tag, this command can also support tagging resources, customers with Tag Contributor role should be able to tag resources by using this command.

So there are two kinds of solutions:

  1. Use command az tag to tag resources with role Tag Contributor For example, you can use:
az tag create --resource-id {resource-group-id} --tags {tags}
  1. If you want to use the original command az group update ... --set tags.xxx, you need to assign a role with Microsoft.Resources/subscriptions/resourcegroups/write permission to this service principal.

If you still have any other questions, please feel free to let us know~

zhoxing-ms avatar Aug 07 '20 07:08 zhoxing-ms

@zhoxing-ms - I tried the option which you provided but it throw an error as below,

az tag create --resource-id essAstPrdWu2RgSecurity --tags {"Dept":"IT"}
The request did not have a subscription or a valid tenant level resource provider.

We passed the subscription id as well to the command execution and we are getting the same response,

az tag create --subscription d9b9kdc9-4z2a-4368-bfe3-13e88044d5d4 --resource-id essAstPrdWu2RgSecurity --tags {"Dept":"IT"}
The request did not have a subscription or a valid tenant level resource provider.

johnakash avatar Aug 10 '20 20:08 johnakash

@johnakash In fact, the parameter --resource-id needs to be passed in a complete resource ID, not the name of the resource (Because it supports different scopes).

If you need to tag a resource group, you can refer to the example in the help of command az tag create -h:

Create or update the entire set of tags on a resource group.
    az tag create --resource-id /subscriptions/{sub-id}/resourcegroups/{rg} --tags Dept=Finance
    Status=Normal

zhoxing-ms avatar Aug 11 '20 01:08 zhoxing-ms

Because there is no reply to this question for a long time, I will close it temporarily. If you have any questions, please feel free to let us know.

zhoxing-ms avatar Aug 21 '20 02:08 zhoxing-ms