I came here to learn how to restrict access to a bucket to one (or a list) of users. Maybe the title of the message is ambiguous?
In any case, it seems that Google is using it, so let it enrich it a bit:
If you need to restrict access to the bucket to some users (users) , follow these steps:
First, get the identifiers of the user to whom you want to grant rights.
This can be achieved with the awscli aws iam list-users command.
These identifiers are as follows: "AIDAIFKYAC9DNJXM2CRD" or "AIDAZ362UEKJCJMFFXCL"
Please comment if it is available in the web console.
After you receive the identifiers that should be granted access, enter the policy in the bucket that you want to protect.
To do this using the web console:
→ Open S3 → Open bucket → Select the “Properties” tab → Click “Change bucket policy”
To apply a policy using awscli, create a file with the contents of the policy and put it in your bucket using this command:
aws s3api put-bucket-policy --bucket NAME_OF_YOUR_BUCKET --policy file:///path/to/policyFile.json
Of course, set YOUR_BUCKET_NAME and the path to your values, BUT DO NOT delete the file: // prefix before your file name
Warning : this deny policy will override the standard "s3 access" that the user may have. This means that you can deny access to your OWN user with this. Use with caution!
I’m even afraid that you might make the bucket completely inaccessible.
Out of curiosity, I tried to access our root user , which I did not provide access to, and actually could not.
Gotta ask for support and hopefully update this answer.
In any case, I'm sure that you will be careful enough, so here is an example of a policy.
Just replace the bucket name with yours and userId with the one you want to allow access to.
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::your-bucket-name", "arn:aws:s3:::your-bucket-name/*" ], "Condition": { "StringNotLike": { "aws:userId": [ "AIDAXAXAXAXAXAXAXAXAX", "AIDAOXOXOXOXOXOOXOXOX", "AIDAXIXIXIXIXIXIXIXIX" ] } } } ] }
For something more specific, or if you want to use roles instead of users, see this AWS Post, which explains in detail how to restrict access to buckets
Hope this helps