- Newest
- Most votes
- Most comments
Hi,
This KC article is the one to read and follow to successfully achieve cross-account S3 access: https://repost.aws/knowledge-center/cross-account-access-s3
When followed properly, you get working cross-account access.
Best,
Didier
Based on the information provided, there are a few reasons why you might be experiencing an "Access Denied" error when trying to access the S3 bucket in Account B from Account A:
-
Role assumption: It appears that you have set up cross-account access correctly with the IAM user in Account A having permission to assume the role in Account B. However, when you're running the AWS CLI command, you're not actually assuming that role. You need to explicitly assume the role before accessing the S3 bucket.
-
S3 bucket policy: While you have a bucket policy that allows access from the IAM user in Account A, this policy is not aligned with your cross-account role setup. The bucket policy should grant access to the assumed role in Account B, not directly to the IAM user in Account A.
-
Missing S3 permissions: The role in Account B (s3-assumerole) has administrative permissions, but you should ensure it explicitly includes S3 access permissions.
To resolve this issue:
-
Assume the role in Account B before accessing the S3 bucket. You can do this using the AWS CLI with the following command:
aws sts assume-role --role-arn arn:aws:iam::AccountB:role/s3-assumerole --role-session-name MySession
This will provide temporary credentials that you can use to access resources in Account B.
-
Update the S3 bucket policy in Account B to allow access from the assumed role:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::AccountB:role/s3-assumerole" }, "Action": "s3:", "Resource": [ "arn:aws:s3:::account-b-bucket", "arn:aws:s3:::account-b-bucket/" ] } ] }
-
Ensure the role in Account B (s3-assumerole) has the necessary S3 permissions. You can add an inline policy or attach an AWS managed policy that includes S3 access.
After making these changes, you should be able to assume the role and then access the S3 bucket in Account B. Remember to use the temporary credentials provided by the assume-role command when accessing the bucket.
Sources
Cannot Access S3 Access Point Cross-Account with Role | AWS re:Post
Access Denied for boto3 list_buckets operation when assuming cross account role from sagemaker notebook | AWS re:Post
Are you assuming the role in Account B before trying to access the buckets in Account A. That could be the issue.
Your trying to access the bucket with 2 different methods.
- Role assumtion in account b
- Directly accessing the bucket with an IAM user in Account A with a bucket policy
You need to choose which method you are going to use. You also need to ensure that if your using KMS keys on your objects in the bucket in account b, then the user in account A/Role in Account B needs KMS:Decrypt
See Didier's Answer as this is perfect!
