question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Permissions required when tagging resources

See original GitHub issue

I am trying to trying to update tags (adding tags but also removing/updating) on the resources of type Microsoft.Compute.

I have a service principal that has been granted Tag Contributor, however I receive this when updating the tag using the code below:

The client '<guid>' with object id '<guid>' does not have authorisation to perform action 'Microsoft.Compute/disks/write' over scope <resource id> or the scope is invalid.

Please can you take a look at the code below either let me know if it can be modified so I can get away with the tag contributor permission or will I need to grant my service principal a higher level of privileges?


var azureCredentials #set above

using (var client = new Microsoft.Azure.Management.Resources.ResourceManagementClient(azureCredentials))
{
  var tags = new Dictionary<string, string>
  {
   { "environment", "test" },
   { "department", "tech" }
  };

  try
  {
    var result = await client.Resources.CreateOrUpdateAsync(resourceGroupName, resourceIdentity, genericResourceParameters, cts.Token);
    if (result.StatusCode == System.Net.HttpStatusCode.OK)
    {
      System.Console.WriteLine(string.Format("Tags updated for {0}", resource.Name));
      InsertLogEntry(resource.Id, true, null);
    }
  }
  catch (Hyak.Common.CloudException cloudException)
  {
    System.Console.WriteLine(string.Format("Caught Hyak.Common.CloudException when updating {0}, {1}", resource.Name, cloudException.Message));
  }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
allenjzhangcommented, Mar 18, 2021

I am using Microsoft.Azure.Management.ResourceManager SDK. Here is a sample project I tested with.

1reaction
allenjzhangcommented, Mar 17, 2021

To leverage the tag contributor permission, the call must explicitly go thru tags operation instead of general update operation on the resource. Otherwise the underlying call is a PUT on /provider/Microsoft.Provider/xxx instead of /provider/Microsoft.Provider/xxx/provider/Microsoft.Resource/tags/default which triggers different RBAC.

Here is the sample code. You can look into TagsOperation documentation. Methods without AtScope are creating default tags collections at subscription level vs ones with it applying the tags on each resource (specified with scope). Hope this clears it up.

                    var patchTags = new TagsPatchResource(
                        "Delete",
                        new Tags(new Dictionary<string, string>
                            {
                                { "environment", "test2" },
                                { "department", "tech2" }
                            }));

                    var result = await client.Tags.UpdateAtScopeAsync(
                        "/subscriptions/XXX/resourceGroups/XX/providers/Microsoft.Network/networkSecurityGroups/XXX",
                        patchTags);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Grant permission to tag resources during creation
To force users to specify tags when they create a resource, you must use the aws:RequestTag condition key or the aws:TagKeys condition key...
Read more >
Permissions by Resource-Tag at AWS - 1-Minute IAM Lesson
Bart continues his AWS Identity & Access Management video series. Today he is talking about enforcing permissions for actions based on the ...
Read more >
Use IAM authorization based resource tags with ...
IAM policies can use the global condition key aws:ResourceTag to control access based on the resource's tag key and value. Not all AWS...
Read more >
tag-resources — AWS CLI 2.13.11 Command Reference
To add tags to a resource, you need the necessary permissions for the service that the resource belongs to as well as permissions...
Read more >
Granting users access to tag resources and service IDs
Tagging permissions. Any user in an account can view tags. When a resource is tagged, all users that have read access to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found