Same-region replication (SRR) across accounts automatically and asynchronously copies object operations, such as creation, updates, and deletions, from a source bucket under Account A to a destination bucket in the same region under Account B. This topic describes how to configure SRR across accounts.
Prerequisites
Create Bucket A in a region under Account A to serve as the source bucket for SRR. Record the UID of Account A, the name of Bucket A, and its region.
Create Bucket B in the same region under Account B to serve as the destination bucket for SRR. Record the UID of Account B and the name of Bucket B.
Role authorization
An SRR task across accounts involves buckets from two different accounts. Therefore, you must configure the required trust policy and least privilege policy for a Resource Access Management (RAM) role.
Use Account A to perform the following operations.
Create a service role.
ImportantYou can use a RAM user to create a role. The RAM user must have the following permissions:
ram:CreateRole,ram:GetRole,ram:ListPoliciesForRole, andram:AttachPolicyToRole. However, granting a RAM user permissions such asram:CreateRoleandram:GetRoleposes a high security threat. We recommend that you use your Alibaba Cloud account to create a RAM role and grant permissions to it. After the authorization is complete, the RAM user can directly use the RAM role created by the Alibaba Cloud account.During the role creation process, select Alibaba Cloud Service as the trusted entity type and Object Storage Service as the trusted entity name. For more information, see Create a service role.
NoteAfter the role is created, record the RAM role ARN from the Basic Information section for later use.
Grant the role permissions to perform SRR across accounts on the source bucket.
You can grant permissions to the role in either of the following ways.
Grant a system policy to the RAM role
WarningYou can grant the
AliyunOSSFullAccesssystem policy to the RAM role. TheAliyunOSSFullAccesspolicy grants full permissions on all buckets under the current account by default. Use this policy with caution.Grant a custom policy to the RAM role
Use a RAM policy to grant the RAM role the least privilege required for replication on the source bucket (src-bucket).
NoteWhen you use the policy, replace the source bucket name as needed.
{ "Version":"1", "Statement":[ { "Effect":"Allow", "Action":[ "oss:ReplicateList", "oss:ReplicateGet" ], "Resource":[ "acs:oss:*:*:src-bucket", "acs:oss:*:*:src-bucket/*" ] } ] }If you want to replicate Key Management Service (KMS) encrypted objects to the destination bucket, you must also grant the
AliyunKMSFullAccesssystem policy to the role. For more information, see Grant permissions to a RAM role.
Use Account B to grant the role permissions to receive replicated objects in the destination bucket.
(Recommended) Method 1: Add a policy using the visual editor
Log on to the OSS console.
In the navigation pane on the left, click Buckets, and then click the destination bucket name
dest-bucket.In the navigation pane on the left, choose .
On the Bucket Policy page, on the Add in GUI tab, click Receive Objects to Replicate.
In the Receive Objects to Replicate panel, for Obtain UID and RAM Role From, select Obtain From Source Replication RAM Role ARN. For Source RAM Role ARN for Replication, enter the role ARN that you recorded in Step 1. For Authorization Purpose, select Cross-account SRR.
Click Generate Policy.
Method 2: Add by Syntax Policy
In the navigation pane on the left, choose Permission Control > Bucket Policy.
On the Bucket Policy page, on the Add by Syntax tab, click Edit.
In the policy editor, enter the following bucket policy.
ImportantWhen you add a bucket policy using the JSON editor, the new policy overwrites the existing policy. Make sure the new policy includes the content of the existing policy. Otherwise, operations that rely on the existing policy may fail.
When you use the policy, replace the custom role name, the destination bucket name (dest-bucket), the UID of the account that owns the source bucket (137918634953xxxx), and the UID of the account that owns the destination bucket (111933544165xxxx) as needed. If the custom role name contains uppercase letters, convert them to lowercase. For example, if the created role is named AliyunOssDrsRole, you must convert it to aliyunossdrsrole. The UID must be the UID of an Alibaba Cloud account.
{ "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.
Replicate KMS-encrypted objects
If you want to replicate KMS-encrypted objects from the source bucket under Account A to the destination bucket under Account B, use Account B to perform the following steps.
Log on to the Instance Management page of the KMS console. Purchase and enable a KMS instance in the same region as the destination bucket. When you purchase the KMS instance, make sure that Access Management Quantity is 2 or greater. Keep the default configurations for the other parameters. For more information, see Purchase and enable a KMS instance.
NoteReplicating KMS-encrypted objects across accounts relies on KMS. The regions that support this feature are limited by KMS. For more information about the regions supported by KMS, see Regions and endpoints that support software-protected keys.
Create a key in the KMS instance. The key type must be a non-default key. We recommend that you use a software-protected key. For more information, see Create a software-protected key.
NoteAfter the key is created, record the key ARN from the Basic Information section for use when you create the replication rule.
Set a key policy for the created key. When you set the key policy, select Other Account User and specify the role ARN that you created in the preceding steps as the Other Account User. For more information, see Set a key policy.
ImportantTo replicate KMS-encrypted data across accounts, the key policy must include at least the decryption (
kms:Decrypt) and generate data key (kms:GenerateDataKey) permissions. When you set a key policy in the console, these permissions are included by default. If you set a custom key policy using OpenAPI, make sure that the policy includes at least thekms:Decryptandkms:GenerateDataKeypermissions.