admin管理员组

文章数量:1290981

I have an IAM role which grants permission to list objects only in some prefixes in my bucket. Listing is done directory-style, hence the delimiter/prefix conditions.

  {
    "Effect":   "Allow",
    "Action":   [ "s3:ListBucket" ],
    "Resource": [ "arn:aws:s3:::my-bucket" ],
    "Condition": { 
      "StringEquals": { 
        "s3:prefix":    [ <<ALLOWED-PREFIXES>> ],
        "s3:delimiter": [ "/" ]
      }
  }

The role also needs to have permission to call the HeadBucket API.

Both ListObjectsV2 and HeadBucket require the s3:ListBucket permission. However, the above policy is causing a Forbidden response when calling HeadBucket. I had hoped to find some condition key such that I can add a statement allowing HeadBucket to succeed while maintaining restricted prefix access - eg aws:http-method=HEAD or s3:operation=head-bucket. However, that doesn't seem to exist.

Converting the StringEquals condition to StringEqualsIfExists nearly does the trick, though now you can call list-objects-v2 without args and list the entire contents of the bucket.

Is there some combination of statements with/without conditions which might allow this? Or is it just the desired/expected behavior from S3 HeadObject since the role does not have FULL access to the bucket?

本文标签: