Not able to access S3 bucket from another AWS account in cross account scenario.

0

Hi Team,

I have requirement to access S3 bucket which exists in AWS account (say Account A) from Account B using Athena. I had done following setup for this :-

In Account A:-

  • Added bucket policy as below :- { "Version": "2012-10-17", "Statement": [ { "Sid": "Statement1", "Effect": "Allow", "Principal": { "AWS": [ "arn:aws:iam::<Account B ID>:user/cloud_user", "arn:aws:iam::<Account B ID>:root", "arn:aws:iam::<Account B ID>:role/GlueaccesstoS3" ] }, "Action": "s3:", "Resource": [ "arn:aws:s3:::<Bucket name in Account A>", "arn:aws:s3:::<Bucket name in Account A>/" ] } ] }
  • In Account B :- Created a role named "GlueaccesstoS3" with following details :-
  1. added AWS managed policy AmazonS3FullAccess
  2. added AWS managed policy AWSGlueServiceRole
  3. added AWS managed policy AWSGlueConsoleFullAccess
  4. added AWS managed policy AWSGlueServiceNotebookRole
  5. added AWS managed policy AWSGlueConsoleSageMakerNotebookFullAccess
  6. Also added customer inline policy with below info :- { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:PutObject", "s3:PutObjectAcl" ], "Resource": "arn:aws:s3:::<Bucket name in Account A>/*" } ] }

and, added below trust entities for this role in Account B:- { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": [ "arn:aws:iam::<Parent of Account A Id>:root", "arn:aws:iam::<Parent of Account A Id>:role/AWS-Data-Analytics", "arn:aws:iam::<Account A Id>:role/admin-All", "arn:aws:iam::<Account A Id>:root" ], "Service": "glue.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }

  • Then, in Account B, using AWS Glue's crawler, trying to create crawler by assigning Role "GlueaccesstoS3" and pointing S3 bucket of Account A.
  • When I ran crawler in Account B, it is throwing error as "Crawler Error: User does not have access to target s3://<Bucket name in Account A>/"
2 Answers
0

You need to make sure of following points:

  1. Account A s3 bucket must be SSE-KMS CMK or SSE-S3 key encrypted, it should not have SSE-KMS(aws/s3) encryption enabled as otherwise Account B role won't be able to access Account A bucket key(aws/s3) and bucket access would fail. SSE-KMS(aws/s3) key is AWS managed key and is unique for each account, it doesn't allow you to add resource policy granting other account access. Hence account A bucket must be SSE-KMS CMK or SSE-S3 encrypted. I'd suggest you to have Account A S3 bucket SSE-KMS CMK encrypted and then follow the next steps.

  2. Account B:

    • Role GlueaccesstoS3 has access to Account A S3 bucket
    • Role GlueaccesstoS3 has access to Account A s3 bucket KMS Key(if this bucket is SSE-KMS CMK) encrypted
  3. Account A:

    • S3 bucket policy should allow Account B role GlueaccesstoS3 required permission(GET/PUT etc) based on your exact requirement
    • S3 bucket KMS Key policy should allow Account B role GlueaccesstoS3 required permission(Encrypt, Decrypt, GenerateDataKey)

Hope you find this information helpful.

Comment here if you have additional questions, happy to help.

Abhishek

profile pictureAWS
EXPERT
answered 8 months ago
  • SSE-S3 works for cross account s3 access, with this you need to update the bucket policy to allow account B role for getobject, putobject etc based on your exact requirement. you can refer this re:Post Knowledge Center Article.

  • Hi Gurpreet, Were you able to pass the issue?

0

Thanks @secondabhi_aws for your reply. As of now, my bucket in Account A is set "Server-side encryption with Amazon S3 managed keys (SSE-S3)" with Bucket Key as enabled. Please find the attached screen-shot for your reference.

Enter image description here

Do i need to make any changes here ?

answered 8 months ago
  • Just commented above if you want to keep SSE-S3 encryption for bucket.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions