Perform the following steps to upload files as a user from account B to a bucket in account A:
- Create an access control policy document that grants access to account B and save it as acl-write-another-account.json:
{
"Owner": {
"DisplayName": "awsseccookbook",
"ID": "5df5b6014ae606808dcb64208aa09e4f19931b3123456e152c4dfa52d38bf8fd"
},
"Grants": [
{
"Grantee": {
"Type": "CanonicalUser",
"ID": "e280db54f21834544a8162b8fc5d23851972d31e1ae3560240156fa14d66b952"
},
"Permission": "WRITE"
}
]
}
The canonical ID of account A is provided under the Owner section, and the canonical ID of account B is provided under the Grants section.
- Update the ACL on the bucket owned by account A, as an administrator of account A:
aws s3api put-bucket-acl \
--bucket awsseccookbook \
--access-control-policy file://resources/acl-write-another-account.json \
--profile awssecadmin
We should now be able to upload objects to the bucket as an administrator from account B. However, a non-administrator from account B will not be able to upload files:
To grant permissions from the console, go to the bucket's ACL, click Add account, enter the canonical ID, and give the required permissions.
- Create a policy to delegate s3:PutObject access and the s3:PutObjectAcl action to administrator users in account B, and save this file as iam-policy-s3-put-obj-and-acl.json:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DelegateS3WriteAccess",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::awsseccookbook/*"
}
]
}
The s3:PutObjectAcl action is required to use canned ACLs later.
- Create a policy in account B using the preceding policy document as an administrator in account B:
aws iam create-policy \
--policy-name MyS3PutObjAndAclPolicy \
--policy-document file://resources/iam-policy-s3-put-obj-and-acl.json \
--profile awschild1admin
We should get a response as follows:
- Attach the preceding policy to the test user's group:
aws iam attach-group-policy \
--group-name testusergroup \
--policy-arn arn:aws:iam::380701114427:policy/MyS3PutObjAndAclPolicy \
--profile awschild1admin
We may also attach the policy directly to the user instead; however, using a group is a recommended practice.
- Upload the object to the bucket as a non-administrator user in account B:
aws s3 cp image-heartin-k.png s3://awsseccookbook/image-from-b-user.png \
--profile child1_testuser
We should be able to upload the file successfully.
If we try to download the object as an administrator in account A, the request will fail as follows:
- Upload the object to the bucket as a user in account B with the bucket-owner-full-control canned ACL:
aws s3 cp image-heartin-k.png s3://awsseccookbook/image-from-b-user.png \
--acl bucket-owner-full-control \
--profile child1_testuser
Account A should now be able to download the file successfully:
In the next section, we will learn to enforce the situation whereby account B should always give this permission to account A, with the bucket owner using bucket policies.