You can use an Alibaba Cloud account (Alibaba Cloud Account A) to create a Resource Access Management (RAM) role, specify another Alibaba Cloud account (Alibaba Cloud Account B) to assume the RAM role, and grant the RAM role the specific permissions on Simple Log Service resources of Alibaba Cloud Account A. Then, you can grant the AssumeRole permission to a RAM user of Alibaba Cloud Account B. Then, you can use Alibaba Cloud Account B or the specified RAM user to call a Security Token Service (STS) API operation to obtain temporary security credentials. These credentials include the AccessKey ID, AccessKey secret, and security token. This way, you can use the RAM user to call Simple Log Service API operations and access Simple Log Service resources.
Solution overview
Enterprise A has an Alibaba Cloud account named Alibaba Cloud Account A, and Enterprise B has an Alibaba Cloud account named Alibaba Cloud Account B. To isolate business data or outsourced projects, the user of Alibaba Cloud Account A wants to grant Alibaba Cloud Account B the specific permissions on Simple Log Service resources of Alibaba Cloud Account A. The following permissions are granted:
Alibaba Cloud Account B is authorized to write data to Simple Log Service of Alibaba Cloud Account A. In addition, Alibaba Cloud Account B is authorized to use consumer groups to consume data from Simple Log Service of Alibaba Cloud Account A.
A RAM user of Alibaba Cloud Account B is authorized to write data to Simple Log Service of Alibaba Cloud Account A. In addition, the RAM user is authorized to use consumer groups to consume data from Simple Log Service of Alibaba Cloud Account A.
Alibaba Cloud Account B is authorized to call an STS API operation to obtain temporary security credentials and use the credentials to call Simple Log Service API operations. For more information, see What is STS?
To meet the preceding requirements, perform the following steps:
Step 1: The user of Alibaba Cloud Account A creates a RAM role for Alibaba Cloud Account B and grants permissions to Alibaba Cloud Account B
The user of Alibaba Cloud Account A creates a RAM role, specifies Alibaba Cloud Account B to assume the RAM role, and grants the RAM role the specific permissions on Simple Log Service resources of Alibaba Cloud Account A.
You can create a RAM role in the RAM console. For more information, see Create a RAM user and authorize the RAM user to access Simple Log Service. You can also call the CreateRole API operation of RAM to create a RAM role. For more information, see CreateRole. The following example describes how to create a RAM role in the console.
Log on to the Resource Access Management (RAM) console by using your Alibaba Cloud account.
Create a RAM role and specify Alibaba Cloud Account B to assume the RAM role.
In the left-side navigation pane, choose
.On the Roles page, click Create Role.
In the Select Role Type step of the Create Role wizard, select Alibaba Cloud Account for Select Trusted Entity and click Next.
In the Configure Role step, configure the RAM Role Name and Note parameters. Select Other Alibaba Cloud Account for the Select Trusted Alibaba Cloud Account parameter, enter the
ID of Alibaba Cloud Account B
, and then click OK.NoteTo view the ID of an Alibaba Cloud account, move the pointer over the profile picture in the upper-right corner of the console.
The following example shows the RAM role that was created in the preceding steps:
{ "Statement": [ { "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { "RAM": [ "acs:ram ::<ID of Alibaba Cloud Account B>:root" ] } } ], "Version": "1" }
Create a custom policy. On the JSON tab of the Create Policy page, replace the existing script in the code editor with the following policy document. For more information, see Create a custom policy on the JSON tab.
Grant the write permissions on Simple Log Service
{ "Version": "1", "Statement": [ { "Action": "log:PostLogStoreLogs", "Resource": "*", "Effect": "Allow" } ] }
Grant the permissions to use consumer groups to pull data from Simple Log Service
{ "Version": "1", "Statement": [ { "Action": [ "log:GetCursorOrData", "log:CreateConsumerGroup", "log:ListConsumerGroup", "log:ConsumerGroupUpdateCheckPoint", "log:ConsumerGroupHeartBeat", "log:GetConsumerGroupCheckPoint", "log:UpdateConsumerGroup" ], "Resource": "*", "Effect": "Allow" } ] }
ImportantThe preceding policies grant permissions on all projects and Logstores of Alibaba Cloud Account A. If you want to grant permissions on a specific project and Logstore, include the following code in the Resource element of the policies:
To grant permissions on a project, use
acs:log::{projectOwnerAliUid}:project/
.To grant permissions on a Logstore, use
acs:log::{projectOwnerAliUid}:project/{projectName}/logstore/{logstoreName}/
.
For more information, see Resource list.
Attach the created custom policy to the RAM role. For more information, see Grant permissions to a RAM role.
Step 2: The user of Alibaba Cloud Account B creates the user-b RAM user and grants permissions to the RAM user
The user of Alibaba Cloud Account B creates the user-b
RAM user and attaches the AliyunSTSAssumeRoleAccess
system policy to RAM user. The AliyunSTSAssumeRoleAccess policy grants the RAM user the permissions to call the AssumeRole API operation of STS.
Use Alibaba Cloud Account B to log on to the RAM console.
Create a RAM user named
user-b
and select Console Access and Using permanent AccessKey to access in the Access Mode section. For more information, see Create a RAM user.ImportantAn AccessKey secret for a RAM user is displayed only when you create an AccessKey pair. You cannot query the AccessKey secret in subsequent operations. Therefore, you must back up your AccessKey secret.
An AccessKey pair is a permanent credential for application access. If the AccessKey pair of an Alibaba Cloud account is leaked, the resources that belong to the account are exposed to potential risks. To prevent credential leak risks, we recommend that you use Security Token Service (STS) tokens. For more information, see Best practices for using an access credential to call API operations.
Attach the AliyunSTSAssumeRoleAccess policy to the RAM user. This way, the RAM user can assume the RAM role to obtain Security Token Service (STS) tokens. For more information, see Grant permissions to a RAM user.
Step 3: The user-b
RAM user obtains STS tokens to access Simple Log Service resources
Call the AssumeRole API operation to obtain the temporary AccessKey pair and security token. For more information, see AssumeRole.
You can call this operation by using the following method:
Call the operation by using STS SDK. For more information, see STS SDK overview.
Call API operations of Simple Log Service. For more information, see Overview of Simple Log Service SDK.