I have a simple bucket that looks like images.mysite.com
on my S3 and other buckets containing backups, etc.
I want to allow a specific user to be able
I found this solution:
AWS FLOW:
Bucket policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::MyExampleBucket",
"arn:aws:s3:::MyExampleBucket/*"
],
"Condition": {
"StringNotLike": {
"aws:userId": [
"AROAEXAMPLEID:*", #Role ID
"111111111111" #AccountID
]
}
}
}
]
}
IAM policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::MyExampleBucket",
"arn:aws:s3:::MyExampleBucket/*"
],
"Condition": {
"StringNotLike": {
"aws:userId": [
"AROAEXAMPLEID:*", #Role ID
"AIDAEXAMPLEID", #UserID
"111111111111" #AccountID
]
}
}
}
]
}
aws iam get-user -–user-name USER-NAME --profile=ExampleProfile
aws iam get-role --role-name ROLE-NAME --profile=ExampleProfile
Source: https://aws.amazon.com/blogs/security/how-to-restrict-amazon-s3-bucket-access-to-a-specific-iam-role/
P.S. be careful with bucket policy, you can stay out without permissions