Not able to update tag with tag contributors role
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
- Create a service principal
- Attach tag contributor
- 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
add to S174
@johnakash In fact, there are two types of commands to manage tags:
- Based on the respective Resource Provider
Such as
az resource tagandaz group update ... --set tags.xxx, it seems that at the moment each RP has its own permission control and does not get through with theTag Contributorrole. - Based on ARM service
Such as
az tag, this command can also support tagging resources, customers withTag Contributorrole should be able to tag resources by using this command.
So there are two kinds of solutions:
- Use command
az tagto tag resources with roleTag ContributorFor example, you can use:
az tag create --resource-id {resource-group-id} --tags {tags}
- If you want to use the original command
az group update ... --set tags.xxx, you need to assign a role withMicrosoft.Resources/subscriptions/resourcegroups/writepermission to this service principal.
If you still have any other questions, please feel free to let us know~
@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 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
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.