Same-region replication (SRR) across accounts allows the automatic and asynchronous (near real-time) replication of Object Storage Service (OSS) objects from Bucket A, which is located in a region and belongs to Account A to Bucket B, which is located in the same region and belongs to Account B. Operations, such as the creation, update, and deletion of objects, can be replicated from Bucket A to Bucket B. This topic describes how to perform SRR across accounts.
Prerequisites
Bucket A, which works as the source bucket of an SRR task, is created in a region within Account A. The UID of Account A, the name of Bucket A, and the region in which Bucket A is located are recorded.
Bucket B, which works as the destination bucket of the SRR task, is created in the same region within Account B. The UID of Account B and the name of Bucket B are recorded.
Grant permissions to a RAM role used to perform SRR across accounts
Two buckets that belong to different Alibaba Cloud accounts are required for data replication across accounts. The following items describe the trust policy and minimum permissions required by a RAM role for data replication across accounts.
Use Account A to perform the following operations:
Create a normal service role.
ImportantYou can create a RAM role by using a RAM user. The RAM user must have the following permissions:
ram:CreateRole
,ram:GetRole
,ram:ListPoliciesForRole
, andram:AttachPolicyToRole
. However, security risks may arise if you grant a RAM user permissions such asram:CreateRole
andram:GetRole
. You can use the Alibaba Cloud account with which the RAM user is associated to create a RAM role and grant the required permissions to the RAM role. Then, the RAM user can assume the RAM role that is created by the Alibaba Cloud account.When you create the RAM role, set Select Trusted Entity to Alibaba Cloud Service, Role Type to Normal Service Role, and then Select Trusted Service to OSS. For more information, see Create a regular service role.
NoteAfter the RAM role is created, record the Alibaba Cloud Resource Name (ARN) of the RAM role in the Basic Information section for subsequent permission authorization.
Grant the RAM role the permissions to perform SRR on the source bucket.
You can use one of the following methods to grant the permissions to the RAM role:
Attach the required system policy to the RAM role
WarningAttach the
AliyunOSSFullAccess
system policy to the RAM role. The RAM role to which theAliyunOSSFullAccess
system policy is attached has the permissions to perform all operations on all buckets within the current Alibaba Cloud account. Exercise caution when you attach the system policy to the RAM role.Attach a custom policy to the RAM role
You can use a RAM policy to grant the RAM role the minimum permissions required to perform SRR on the source bucket.
NoteReplace src-bucket with the name of the source bucket based on your business requirements.
{ "Version":"1", "Statement":[ { "Effect":"Allow", "Action":[ "oss:ReplicateList", "oss:ReplicateGet" ], "Resource":[ "acs:oss:*:*:src-bucket", "acs:oss:*:*:src-bucket/*" ] } ] }
If you want to replicate objects encrypted by Key Management Service (KMS) to the destination bucket, you must attach the
AliyunKMSFullAccess
system policy to the RAM role. For more information about how to attach a system policy to a RAM role, see Grant permissions to a RAM role.
Use Account B to grant the RAM role the permissions to receive the objects that you want to replicate to the destination bucket.
Method 1: (Recommended) Add in GUI
Log on to the OSS console.
In the left-side navigation pane, click Buckets. On the Buckets page, find the bucket named
dest-bucket
and click the bucket's name.In the left-side navigation tree, choose
.On the Bucket Policy tab, click Add in GUI and then click Receive Objects to Replicate.
In the Receive Objects to Replicate panel, set Obtain UID and RAM Role From to Source RAM role ARN for replication, and enter the ARN of the RAM role that you created in Step 1 for Source RAM Role ARN for Replication.
Click Generate Policy.
Method 2: Add by Syntax
In the left-side navigation tree, choose Permission Control > Bucket Policy.
On the Bucket Policy tab, click Add by Syntax and then click Edit.
In the code editor, enter the following bucket policy.
ImportantIf you configure a bucket policy by specifying policy statements to grant the RAM role the required permissions, the new bucket policy overwrites the existing bucket policy. Make sure that the new bucket policy contains the content of the existing bucket policy. Otherwise, the authorization of the existing bucket policy may fail.
Replace the role name with the name of the RAM role that you created based on your business requirements. If the name of the RAM role that you created contains uppercase letters, you must convert them to lowercase letters. For example, if the name of the RAM role that you created is AliyunOssDrsRole, you must convert AliyunOssDrsRole to aliyunossdrsrole. In the following example, the name of the destination bucket is dest-bucket, the UID of the account to which the source bucket belongs is 137918634953xxxx, and the UID of the account to which the destination bucket belongs is 111933544165xxxx.
{ "Version":"1", "Statement":[ { "Effect":"Allow", "Action":[ "oss:ReplicateList", "oss:ReplicateGet", "oss:ReplicatePut", "oss:ReplicateDelete" ], "Principal": [ "arn:sts::137918634953xxxx:assumed-role/aliyunossdrsrole/*" ], "Resource":[ "acs:oss:*:111933544165xxxx:dest-bucket", "acs:oss:*:111933544165xxxx:dest-bucket/*" ] } ] }
Click Save. In the message that appears, click OK.
Replicate objects encrypted by using SSE-KMS
Objects encrypted based on KMS can be replicated to buckets in the following regions: China (Hangzhou), China (Shanghai), China (Shenzhen), China (Heyuan), China (Guangzhou), China (Qingdao), China (Beijing), China (Zhangjiakou), China (Hohhot), China (Ulanqab), China (Chengdu), China East 2 Finance, China (Hong Kong), Singapore (Singapore), Malaysia (Kuala Lumpur), Indonesia (Jakarta), Philippines (Manila), Thailand (Bangkok), Japan (Tokyo), US (Silicon Valley), US (Virginia), Germany (Frankfurt), and UK (London).
If you want to copy objects encrypted by using SSE-KMS from a source bucket that belongs to Account A to a destination bucket that belongs to Account B, use Account B to perform the following steps:
Log on to the KMS console. In the left-side navigation pane, choose Resource > Instances. On the Instances page, create and enable a KMS instance in the same region in which the destination bucket is located. When you create a KMS instance, make sure that the value of the Access Management Quantity parameter is greater than or equal to 2. Retain the default settings for other parameters. For more information, see Purchase and enable a KMS instance.
NoteCross-account replication of objects encrypted by SSE-KMS depends on KMS. The supported regions are determined by KMS. For more information about regions supported by KMS, see Software key management.
Create a key in the KMS instance. The key type cannot be Default. We recommend that you use software keys. For more information, see Software-protected key.
NoteAfter you create a key, record the ARN of the key in the Basic Information section for subsequent replication rule configuration.
Configure a policy for the key. When you configure a key policy, set Cross-account User to the ARN of the role created in the preceding step. For more information, see Configure a key policy.
ImportantTo replicate objects encrypted by SSE-KMS across accounts, the key policy must have at least the
kms:Decrypt
andkms:GenerateDataKey
permissions. When you configure a key policy in the KMS console, the preceding permissions are added by default. If you call an API operation to configure a custom key policy, make sure that the policy has at least thekms:Decrypt
andkms:GenerateDataKey
permissions.