Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS IAM s3:prefix

I have an AWS IAM policy in Terraform that is written like such:

            {
                "Effect": "Allow",
                "Action": [
                    "s3:ListBucket"
                ],
                "Resource": "arn:aws:s3:::bucket-name",
                "Condition": {
                    "StringLike": {
                        "s3:prefix": "${local.account_id}/*"
                    }
                }
            }

However, I'm trying to understand why s3:prefix is used at all. Can't this be done with:

            {
                "Effect": "Allow",
                "Action": [
                    "s3:ListBucket"
                ],
                "Resource": "arn:aws:s3:::bucket-name/${local.account_id}/*",
            }
like image 668
sebastian Avatar asked Jan 24 '23 12:01

sebastian


1 Answers

s3:ListBucket only applies to the Resource of bucket. In your second example, your Resource are objects, and the s3:ListBucket will not apply. So your policy will have no effect.

In contrast, in the frist example the Resource is actual bucket, not objects. s3:ListBucket will work. Additionally, due to the Condition, s3:ListBucket will only allow listing content of folder ${local.account_id} in the bucket.

Other such scenarios are discussed here.

like image 132
Marcin Avatar answered Jan 27 '23 00:01

Marcin