After you add tags to your Elastic Compute Service (ECS) resources, you can use the
tags to categorize the resources and control access to them. This topic describes
how to use tags to control the permissions of Resource Access Management (RAM) users
so that different users can be granted different access and operation permissions
on cloud resources based on tags.
Background information
Tags can be used to identify, categorize, or classify resources for easy management.
RAM allows you to manage user identities and resource access and operation permissions
based on policies. You can use tags as conditions in RAM policies to implement fine-grained
access control on resources.
The following figure shows how to use tags to manage resource access and operation
permissions of RAM users, which is called tag-based authentication.

Scenarios
The procedure in this topic describes how to use tag-based authentication. In the
example, the scenario that meets the following requirements is used:
- Resources to which the
costcenter:tony
tag is not added cannot be created.
- Operations can be performed only when requests contain the
costcenter:tony
tag.
- Resources created by other users that do not have the
costcenter:tony
tag added cannot be managed.
- Tag-based authentication supports some API operations that are used to query resources.
You can query the instances that have the
costcenter:tony
tag added.
- Tags cannot be modified.
Procedure
In this procedure, a custom policy named UserTagAccessRes is created by using an Alibaba
Cloud account and is attached to the RAM user userTest. The UserTagAccessRes policy
specifies that RAM users must specify the costcenter:tony
tag before they can access and manage ECS resources.
- Log on to the RAM console by using an Alibaba Cloud account.
- Create the UserTagAccessRes custom policy. For more information, see Create a custom policy.
In this example, you can configure multiple tag-based conditions for cloud resources
in the
Condition
element of the custom policy to restrict operation permissions. The following table
describes supported tag-based authentication conditions.
Tag-based authentication condition |
Description |
acs:RequestTag |
Indicates that a specific tag must be included in each API request.
If an API request does not include tag-related parameters, the acs:RequestTag condition cannot be used. Otherwise, authentication fails.
|
acs:ResourceTag |
Indicates that a specific tag must be added to the specified resource.
If an API request does not include a resource ID, the acs:ResourceTag condition cannot be used. Otherwise, authentication fails.
|
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecs:Run*",
"ecs:Create*",
"ecs:Purchase*",
"ecs:DescribeInstances",
"ecs:List*"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"acs:RequestTag/costcenter": "tony"
}
}
},
{
"Effect": "Allow",
"Action": "*",
"Resource": "*",
"Condition": {
"StringEquals": {
"acs:ResourceTag/costcenter": "tony"
}
}
},
{
"Effect": "Allow",
"Action": [
"ecs:List*",
"ecs:DescribeInstanceStatus",
"ecs:DescribeInstanceVncUrl",
"ecs:DescribeInstanceAutoRenewAttribute",
"ecs:DescribeInstanceRamRole",
"ecs:DescribeInstanceTypeFamilies",
"ecs:DescribeInstanceTypes",
"ecs:DescribeInstanceAttachmentAttributes",
"ecs:DescribeInstancesFullStatus",
"ecs:DescribeInstanceHistoryEvents",
"ecs:DescribeInstanceMonitorData",
"ecs:DescribeInstanceMaintenanceAttributes",
"ecs:DescribeInstanceModificationPrice",
"ecs:DescribeA*",
"ecs:DescribeC*",
"ecs:DescribeD*",
"ecs:DescribeE*",
"ecs:DescribeH*",
"ecs:DescribeIm*",
"ecs:DescribeInv*",
"ecs:DescribeK*",
"ecs:DescribeL*",
"ecs:DescribeM*",
"ecs:DescribeN*",
"ecs:DescribeP*",
"ecs:DescribeR*",
"ecs:DescribeS*",
"ecs:DescribeT*",
"ecs:DescribeZ*",
"vpc:DescribeVpcs",
"vpc:DescribeVSwitches",
"bss:PayOrder"
],
"Resource": "*"
},
{
"Effect": "Deny",
"Action": [
"ecs:RemoveTags",
"ecs:UntagResources",
"ecs:AddTags",
"ecs:TagResources"
],
"Resource": "*"
}
]
}
The preceding policy can provide the following access control:
- Resources to which the
costcenter:tony
tag is not added cannot be created.
Operations can be performed only when requests contain the costcenter:tony
tag.
{
"Effect": "Allow",
"Action": [
"ecs:Run*",
"ecs:Create*",
"ecs:Purchase*"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"acs:RequestTag/costcenter": "tony"
}
}
}
- Resources created by other users that do not have the
costcenter:tony
tag added cannot be managed. {
"Effect": "Allow",
"Action": "*",
"Resource": "*",
"Condition": {
"StringEquals": {
"acs:ResourceTag/costcenter": "tony"
}
}
}
- Tag-based authentication supports some API operations that are used to query resources.
You can query the instances that have the
costcenter:tony
tag added. {
"Effect": "Allow",
"Action": [
"ecs:DescribeInstances",
"ecs:List*"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"acs:RequestTag/costcenter": "tony"
}
}
},
{
"Effect": "Allow",
"Action": [
"ecs:List*",
"ecs:DescribeInstanceStatus",
"ecs:DescribeInstanceVncUrl",
"ecs:DescribeInstanceAutoRenewAttribute",
"ecs:DescribeInstanceRamRole",
"ecs:DescribeInstanceTypeFamilies",
"ecs:DescribeInstanceTypes",
"ecs:DescribeInstanceAttachmentAttributes",
"ecs:DescribeInstancesFullStatus",
"ecs:DescribeInstanceHistoryEvents",
"ecs:DescribeInstanceMonitorData",
"ecs:DescribeInstanceMaintenanceAttributes",
"ecs:DescribeInstanceModificationPrice",
"ecs:DescribeA*",
"ecs:DescribeC*",
"ecs:DescribeD*",
"ecs:DescribeE*",
"ecs:DescribeH*",
"ecs:DescribeIm*",
"ecs:DescribeInv*",
"ecs:DescribeK*",
"ecs:DescribeL*",
"ecs:DescribeM*",
"ecs:DescribeN*",
"ecs:DescribeP*",
"ecs:DescribeR*",
"ecs:DescribeS*",
"ecs:DescribeT*",
"ecs:DescribeZ*",
"vpc:DescribeVpcs",
"vpc:DescribeVSwitches",
"bss:PayOrder"
],
"Resource": "*"
}
- Tags cannot be modified.
{
"Effect": "Deny",
"Action": [
"ecs:RemoveTags",
"ecs:UntagResources",
"ecs:AddTags",
"ecs:TagResources"
],
"Resource": "*"
}
- Attach the custom policy to the RAM user or group for which you want to control access.
For more information, see Grant permissions to a RAM role.
In this step, attach the UserTagAccessRes policy to the RAM user userTest.
Note To attach the UserTagAccessRes policy to an existing RAM user, note that multiple
policies attached to a single RAM user may cause permission issues.