When you use Alibaba Cloud SDKs to call OpenAPI operations through shared gateways and dedicated gateways, the authentication methods are the same. RAM-based authentication methods such as AccessKey pairs, STS tokens, RamRoleArn, and ECS instance RAM roles are supported. This topic describes how to create access credentials.
For more information about access credential types, see Manage credentials.
AccessKey
By default, an Alibaba Cloud account has administrator permissions for all resources, which cannot be modified. To ensure resource security, we recommend that you use a RAM user to create an AccessKey pair and grant it only the necessary permissions.
Log on to the RAM console. On the Users page, click the name of the target RAM user.
On the Secret Management tab, in the AccessKey section, click Create AccessKey.
Grant the RAM user permissions to access KMS.
Method 1: Configure an identity-based policy
In the Actions column of the RAM user, click Grant Permission to attach a built-in system permission policy for KMS to the RAM user. For more information about the system permission policies for KMS, see System policies for KMS.
NoteYou can also create custom permission policies. For more information, see Create a custom policy.
Method 2: Configure a resource-based policy
KMS supports resource-based policies that grant access permissions for individual keys and secrets. You can use these policies to control which Alibaba Cloud accounts, RAM users, and RAM roles can manage or use KMS keys and secrets. For more information, see Key policies and Secret policies.
ECS instance RAM role
An ECS instance RAM role allows you to obtain a temporary access credential (STS token) from within an ECS instance to call KMS API operations, without needing to configure an AccessKey pair.
For more information, see Instance RAM roles.
Log on to the RAM console and create a RAM role for a trusted Alibaba Cloud service.
Trusted Entity Type: Select Elastic Compute Service.
Trusted entity: Select Elastic Compute Service (ECS).
Grant the RAM role permissions to access KMS.
Method 1: Configure an identity-based policy
In the Actions column of the RAM role, click Grant Permission to attach a built-in system permission policy for KMS to the RAM role. For more information about the system permission policies for KMS, see System policies for KMS.
NoteYou can also create custom permission policies. For more information, see Create a custom policy.
Method 2: Configure a resource-based policy
KMS supports resource-based policies that grant access permissions for individual keys and secrets. You can use these policies to control which Alibaba Cloud accounts, RAM users, and RAM roles can manage or use KMS keys and secrets. For more information, see Key policies and Secret policies.
Log on to the ECS console and attach the RAM role to an ECS instance.
STS token
Security Token Service (STS) issues a temporary access credential, an STS token, to a RAM user or RAM role. This token allows access to KMS with specific permissions for a limited validity period. After the token expires, it automatically becomes invalid.
Log on to the RAM console to create a RAM user or a RAM role. For more information, see Create a RAM user and Create a RAM role.
Grant the
AliyunSTSAssumeRoleAccesspermission to the RAM user or RAM role. For more information, see Manage RAM user permissions and Grant permissions to a RAM role.Grant the RAM user or RAM role permissions to access KMS.
Method 1: Configure an identity-based policy
In the Actions column of the RAM role or user, click Grant Permission to attach a built-in system permission policy for KMS. For more information about the system permission policies for KMS, see System policies for KMS.
NoteYou can also create custom permission policies. For more information, see Create a custom policy.
Method 2: Configure a resource-based policy
KMS supports resource-based policies that grant access permissions for individual keys and secrets. You can use these policies to control which Alibaba Cloud accounts, RAM users, and RAM roles can manage or use KMS keys and secrets. For more information, see Key policies and Secret policies.
Use the RAM user or RAM role to call the STS AssumeRole operation to obtain a temporary STS access credential. For more information, see AssumeRole.
RamRoleArn
RAM users or cloud services can assume a role to obtain temporary permissions (STS token) instead of using long-term keys, which reduces the risk of key leaks. For example, in a temporary data processing task, a RAM user or cloud service temporarily assumes a role with a specific RamRoleArn. After the task is complete, the role permissions are revoked, minimizing the risk of exposure.
Create a user AccessKey pair
Log on to the RAM console. In the left-side navigation pane, choose . On the Users page, click the name of the target RAM user.
Attach the
AliyunSTSAssumeRoleAccesssystem policy or a custom policy that includes thests:AssumeRoleaction to the RAM user.On the Secret Management tab, in the AccessKey section, click Create AccessKey.
Create and authorize a RAM role:
In the left-side navigation pane, choose . On the Roles page, click Create Role. For more information, see Create a RAM role.
Grant the RAM role permissions to access KMS.
Method 1: Configure an identity-based policy
In the Actions column of the RAM role, click Grant Permission to attach a built-in system permission policy for KMS to the RAM role. For more information about the system permission policies for KMS, see System policies for KMS.
NoteYou can also create custom permission policies. For more information, see Create a custom policy.
Method 2: Configure a resource-based policy
KMS supports resource-based policies that grant access permissions for individual keys and secrets. You can use these policies to control which Alibaba Cloud accounts, RAM users, and RAM roles can manage or use KMS keys and secrets. For more information, see Key policies and Secret policies.
Obtain the RamRoleArn of the target RAM role. For more information, see View the information about a RAM role.
In the left-side navigation pane, choose . On the Roles page, click the name of the target role.
On the role details page, find the RamRoleArn in the ARN section.
NoteThe RamRoleArn is the Alibaba Cloud Resource Name (ARN) of the RAM role to assume. The format is
acs:ram::$accountID:role/$roleName, where$accountIDis the Alibaba Cloud account ID and$roleNameis the RAM role name.