All Products
Search
Document Center

Key Management Service:Service-linked roles

Last Updated:Sep 08, 2026

A service-linked role is a type of Resource Access Management (RAM) role whose trusted entity is an Alibaba Cloud service. Key Management Service (KMS) uses service-linked roles to access other cloud services and cloud resources. Typically, the system automatically creates a service-linked role when you perform a specific operation. If automatic creation fails, you must create the role manually.

Use cases

KMS automatically creates and authorizes service-linked roles in the following scenarios:

  • Scenario 1: When you enable a KMS instance

    KMS automatically creates the service-linked role AliyunServiceRoleForKMSKeyStore to allow KMS to access services such as ECS, Virtual Private Cloud (VPC), and Simple Log Service. KMS automatically attaches the AliyunServiceRolePolicyForKMSKeyStore permission policy to this role.

  • Scenario 2: When you create an ECS secret

    KMS automatically creates the service-linked role AliyunServiceRoleForKMSSecretsManagerForECS to allow KMS to access ECS to manage and rotate ECS secrets. KMS automatically attaches the AliyunServiceRolePolicyForKMSSecretsManagerForECS permission policy to this role.

  • Scenario 3: When you create an ApsaraDB RDS secret

    KMS automatically creates the service-linked role AliyunServiceRoleForKMSSecretsManagerForRDS to allow KMS to access ApsaraDB RDS to manage and rotate ApsaraDB RDS secrets. KMS automatically attaches the AliyunServiceRolePolicyForKMSSecretsManagerForRDS permission policy to this role.

  • Scenario 4: When you create an ApsaraDB for Redis secret

    KMS automatically creates the service-linked role AliyunServiceRoleForKMSSecretsManagerForRedis, to allow KMS to access ApsaraDB for Redis to manage and rotate ApsaraDB for Redis secrets. KMS automatically attaches the AliyunServiceRolePolicyForKMSSecretsManagerForRedis permission policy to this role.

RAM user permissions

To create or delete a service-linked role, a RAM user must have administrative permissions (AliyunKMSFullAccess) or have a custom permission policy that includes the following permissions in its Action statement:

  • Create a service-linked role: ram:CreateServiceLinkedRole

  • Delete a service-linked role: ram:DeleteServiceLinkedRole

{
    "Action": [
        "ram:CreateServiceLinkedRole",
        "ram:DeleteServiceLinkedRole"
    ],
    "Resource": "*",
    "Effect": "Allow",
    "Condition": {
        "StringEquals": {
             "ram:ServiceName": [
                        "keystore.kms.aliyuncs.com",
                        "secretsmanager-ecs.kms.aliyuncs.com",
                        "secretsmanager-rds.kms.aliyuncs.com",
                        "secretsmanager-redis.kms.aliyuncs.com"
                    ]
        }
     }
}

For more information about how to grant permissions, see Permissions required to manage service-linked roles and Grant permissions to a RAM user.

Create a service-linked role

The system automatically creates a service-linked role in the following scenarios:

  • AliyunServiceRoleForKMSKeyStore: When you enable a KMS instance.

  • AliyunServiceRoleForKMSSecretsManagerForECS: When you create an ECS secret.

  • AliyunServiceRoleForKMSSecretsManagerForRDS: When you create an ApsaraDB RDS secret.

  • AliyunServiceRoleForKMSSecretsManagerForRedis: When you create an ApsaraDB for Redis secret.

Important

After a service-linked role is created, the trusted cloud service can assume the role to access cloud resources in other services. This action may incur charges from creating KMS instances or using Simple Log Service.

View a service-linked role

After a service-linked role is created, you can go to the Roles page in the RAM console and search for the role by its name, such as AliyunServiceRoleForKMSKeyStore, to view the following information:

  • Basic information

    On the details page of the AliyunServiceRoleForKMSKeyStore role, view basic information about the role in the Basic Information section, including the role name, creation time, role ARN, and description.

  • Permission policy

    On the details page of the AliyunServiceRoleForKMSKeyStore role, click the Permissions tab. Click a permission policy name to view its content and the cloud resources that the role can access.

  • Trust policy

    On the details page of the AliyunServiceRoleForKMSKeyStore role, click the Trust Policy Management tab to view the trust policy. A trust policy defines the trusted entities that can assume the RAM role. For a service-linked role, the trusted entity is a cloud service, which you can identify in the Service field of the trust policy.

For more information about how to view a service-linked role, see View the information about a RAM role.

Delete a service-linked role

Important

If you delete a service-linked role, the features that depend on it will stop working. Proceed with caution.

When no KMS resources exist in your account, the system automatically deletes the service-linked role. No action is required.

If you do not use KMS for an extended period, you can manually delete the service-linked role in the RAM console.

Before you delete the role, ensure that all instances in your account have been released.

For detailed instructions, see Delete a RAM role.