AccessDenied for ListObjects for S3 bucket when permissions are s3:*

前端 未结 13 1047
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-29 22:02

I am getting:

An error occurred (AccessDenied) when calling the ListObjects operation: Access Denied

When I try to get folder from

13条回答
  •  忘了有多久
    2021-01-29 22:15

    If you wanted to copy all s3 bucket objects using the command "aws s3 cp s3://bucket-name/data/all-data/ . --recursive" as you mentioned, here is a safe and minimal policy to do that:

    {
      "Version": "2012-10-17",
      "Statement": [
          {
              "Effect": "Allow",
              "Action": [
                  "s3:ListBucket"
              ],
              "Resource": [
                  "arn:aws:s3:::bucket-name"
              ],
              "Condition": {
                  "StringLike": {
                      "s3:prefix": "data/all-data/*"
                  }
              }
          },
          {
              "Effect": "Allow",
              "Action": [
                  "s3:GetObject"
              ],
              "Resource": [
                  "arn:aws:s3:::bucket-name/data/all-data/*"
              ]
          }
      ]
    }
    

    The first statement in this policy allows for listing objects inside a specific bucket's sub directory. The resource needs to be the arn of the S3 bucket, and to limit listing to only a sub-directory in that bucket you can edit the "s3:prefix" value.

    The second statement in this policy allows for getting objects inside of the bucket at a specific sub-directory. This means that anything inside the "s3://bucket-name/data/all-data/" path you will be able to copy. Be aware that this doesn't allow you to copy from parent paths such as "s3://bucket-name/data/".

    This solution is specific to limiting use for AWS CLI commands; if you need to limit S3 access through the AWS console or API, then more policies will be needed. I suggest taking a look here: https://aws.amazon.com/blogs/security/writing-iam-policies-grant-access-to-user-specific-folders-in-an-amazon-s3-bucket/.

    A similar issue to this can be found here which led me to the solution I am giving. https://github.com/aws/aws-cli/issues/2408

    Hope this helps!

提交回复
热议问题