All Products
Search
Document Center

Resource Management:Use tags to control access to ECS resources

Last Updated:Dec 19, 2023

You can add tags to your Elastic Compute Service (ECS) resources to categorize the resources and control access to them. This topic describes how to use tags to control the access of a RAM user to ECS instances.

Prerequisites

A RAM user is created within your Alibaba Cloud account. For more information, see Create a RAM user.

Background information

Tags are used to identify resources. The tags help you categorize, search for, and aggregate resources that have the same characteristics from different dimensions. This simplifies resource management. You can add multiple tags to each resource. For more information about the cloud services and resources that support tags, see Services that work with Tag.

Alibaba Cloud implements policy-based access control. You can configure RAM policies based on the roles of RAM users. You can define multiple tags in each policy and attach one or more policies to RAM users or RAM user groups.

By default, all resources within the current region are displayed in the resource list. To control the resources that are accessible to a RAM user, create a custom policy in which specific tags are specified, attach the policy to the RAM user, and add the tags to the resources.

Step 1: Create a custom policy and attach the policy to a RAM user

Create a custom policy named UserTagAccessRes by using an Alibaba Cloud account and attach the policy to the userTest RAM user. The UserTagAccessRes policy defines that you must specify the owner:zhangsan and environment:production tags when you use the RAM user to access ECS resources.

  1. Log on to the RAM console with your Alibaba Cloud account.

  2. Create a custom policy named UserTagAccessRes.

    The following code provides the document of the policy. For more information, see Create a custom policy.

    {
        "Statement": [
            {
                "Effect": "Allow",
                "Action": "ecs:*",
                "Resource": "*",
                "Condition": {
                    "StringEquals": {
                        "acs:RequestTag/owner": "zhangsan",
                        "acs:RequestTag/environment": "production"
                    }
                }
            },
            {
                "Action": [
                    "ecs:DescribeTagKeys",
                    "ecs:DescribeTags"
                ],
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Effect": "Deny",
                "Action": [
                    "ecs:DeleteTags",
                    "ecs:UntagResources",
                    "ecs:CreateTags",
                    "ecs:TagResources"
                ],
                "Resource": "*"
            }
        ],
        "Version": "1"
    }

    Permission

    Configuration

    Description

    Access resources to which specific tags are added

    • "acs:RequestTag/owner": "zhangsan"

    • "acs:RequestTag/environment": "production"

    You can control access to resources to which the specific tags are added.

    Call the API operations that are used to query tags

    • ecs:DescribeTagKeys

    • ecs:DescribeTags

    You can query tags in the ECS console.

    Not allowed to call the API operations that are used to manage tags

    • ecs:DeleteTags

    • ecs:UntagResources

    • ecs:CreateTags

    • ecs:TagResources

    The policy excludes all tag-related API operations from its permissions. This ensures that users still have permissions regardless of tag modifications.

  3. Attach the custom policy to the userTest RAM user.

    For more information, see Grant permissions to RAM users.

Step 2: Add tags to ECS instances

Use an Alibaba Cloud account to add tags to ECS instances.

Note

If you do not have ECS instances, create ECS instances first. For more information, see Creation methods.

  1. Log on to the Resource Management console. The Tags page appears.

  2. In the top navigation bar, select a region.

  3. On the Custom Tags tab, click Create Custom Tags.

  4. In the Create Custom Tags dialog box, add the owner:zhangsan and environment: production tags to existing ECS instances.

    For more information, see Add a custom tag.

Step 3: Access ECS instances to which specific tags are added

Log on to the ECS console as the userTest RAM user and access instances to which specific tags are added.

  1. Log on to the ECS console as the RAM user.

  2. In the left-side navigation pane, choose Instances & Images > Instances.

  3. In the top navigation bar, select a region.

  4. On the Instances page, click Filter by Tag on the right side of the search box and select the owner:zhangsan and environment:production tags.

    image.png

  5. View the resources to which only the owner:zhangsan and environment:production tags are added.