Need help formulating a complex bucket policy -
I own a s3 bucket with highly sensitive content in an AWS account that I do not administer. I wish to introduce a bucket policy to prevent undesired access, including by users with permissive s3 access IAM policies (which I cannot control because I'm not the account admin).
My bucket policy is currently blocking all access except for my own IAM user - it looks like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::<my-bucket-name>",
"arn:aws:s3:::<my-bucket-name>/*"
],
"Condition": {
"StringNotLike": {
"aws:userId": [
"<my IAM userId>",
"<my AWS AccountId>"
]
}
}
}
]
}
This works fine, but now I need to add permissions for certain roles to be able to read/write anywhere in their respective folder under the root folder, so the bucket policy needs to allow the following (and block anything else):
- allow my own IAM user full access to manage the bucket and its entire content
- Allow
roleAread/write access to their respective folderfolderAunder the root folder - Allow
roleBread/write access to their respective folderfolderBunder the root folder
Can someone advise how best to acheive this outcome?
This will work assuming that you do not have any files on the root of the bucket, if you have files on the root of the bucket anyone with access to folder1 or folder2 will have access to them too.
To get an IAM role Unique ID you can do so by using the following command
or if you do not have IAM permission, you can ask someone with Role A access to do
And copy paste anything before the ":"
Example
AROA1234567890EXAMPLE:[email protected] -> Copy the AROA1234567890EXAMPLE