Controlling access to tags - AWS Key Management Service

Controlling access to tags

To add, view, and delete tags, either in the AWS KMS console or by using the API, principals need tagging permissions. You can provide these permissions in key policies. You can also provide them in IAM policies (including VPC endpoint policies), but only if the key policy allows it. The AWSKeyManagementServicePowerUser managed policy allows principals to tag, untag, and list tags on all CMKs the account can access.

You can also limit these permissions by using AWS global condition keys for tags. In AWS KMS, these conditions can control access to tagging operations, such as TagResource and UntagResource.

Note

Be cautious when giving principals permission to manage tags and aliases. Changing a tag or alias can allow or deny permission to the CMK. For details, see Using ABAC for AWS KMS and Using tags to control access to CMKs.

For example policies and more information, see Controlling Access Based on Tag Keys in the IAM User Guide.

Permissions to create and manage tags work as follows.

kms:TagResource

Allows principals to add or edit tags. To add tags while creating a CMK, the principal must have permission in an IAM policy that isn't restricted to particular CMKs.

kms:ListResourceTags

Allows principals to view tags on CMKs.

kms:UntagResource

Allows principals to delete tags from CMKs.

Tag permissions in policies

You can provide tagging permissions in a key policy or IAM policy. For example, the following example key policy gives select users tagging permission on the CMK. It gives all users who can assume the example Administrator or Developer roles permission to view tags.

{ "Version": "2012-10-17", "Id": "key-policy-example", "Statement": [ { "Sid": "Enable IAM policies", "Effect": "Allow", "Principal": {"AWS": "arn:aws:iam::111122223333:root"}, "Action": "kms:*", "Resource": "*" }, { "Sid": "Allow all tagging permissions", "Effect": "Allow", "Principal": {"AWS": [ "arn:aws:iam::111122223333:user/LeadAdmin", "arn:aws:iam::111122223333:user/SupportLead" ]}, "Action": [ "kms:TagResource", "kms:ListResourceTags", "kms:UntagResource" ], "Resource": "*" }, { "Sid": "Allow roles to view tags", "Effect": "Allow", "Principal": {"AWS": [ "arn:aws:iam::111122223333:role/Administrator", "arn:aws:iam::111122223333:role/Developer" ]}, "Action": "kms:ListResourceTags", "Resource": "*" } ] }

To give principals tagging permission on multiple CMKs, you can use an IAM policy. For this policy to be effective, the key policy for each CMK must allow the account to use IAM policies to control access to the CMK.

For example, the following IAM policy allows the principals to create CMKs. It also allows them to create and manage tags on all CMKs in the specified account. This combination allows the principals to use the Tags parameter of the CreateKey operation to add tags to a CMK while they are creating it.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "IAMPolicyCreateKeys", "Effect": "Allow", "Action": "kms:CreateKey", "Resource": "*" }, { "Sid": "IAMPolicyTags", "Effect": "Allow", "Action": [ "kms:TagResource", "kms:UntagResource", "kms:ListResourceTags" ], "Resource": "arn:aws:kms:*:111122223333:key/*" } ] }

Limiting tag permissions

You can limit tagging permissions by using policy conditions. The following policy conditions can be applied to the kms:TagResource and kms:UntagResource permissions. For example, you can use the aws:RequestTag/tag-key condition to allow a principal to add only particular tags, or prevent a principal from adding tags with particular tag keys. Or, you can use the kms:KeyOrigin condition to prevent principals from tagging or untagging CMKs with imported key material.

As a best practice when you use tags to control access to CMKs, use the aws:RequestTag/tag-key or aws:TagKeys condition key to determine which tags (or tag keys) are allowed.

For example, the following IAM policy is similar to the previous one. However, this policy allows the principals to create tags (TagResource) and delete tags UntagResource only for tags with a Project tag key.

Because TagResource and UntagResource requests can include multiple tags, you must specify a ForAllValues or ForAnyValue set operator with the aws:TagKeys condition. The ForAnyValue operator requires that at least one of the tag keys in the request matches one of the tag keys in the policy. The ForAllValues operator requires that all of the tag keys in the request match one of the tag keys in the policy. The ForAllValues operator also returns true if there are no tags in the request, but TagResource and UntagResource fail when no tags are specified. For details about the set operators, see Use multiple keys and values in the IAM User Guide.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "IAMPolicyCreateKey", "Effect": "Allow", "Action": "kms:CreateKey", "Resource": "*" }, { "Sid": "IAMPolicyViewAllTags", "Effect": "Allow", "Action": "kms:ListResourceTags", "Resource": "arn:aws:kms:*:111122223333:key/*" }, { "Sid": "IAMPolicyManageTags", "Effect": "Allow", "Action": [ "kms:TagResource", "kms:UntagResource" ], "Resource": "arn:aws:kms:*:111122223333:key/*", "Condition": { "ForAllValues:StringEquals": {"aws:TagKeys": "Project"} } } ] }