我需要一个可以完全访问单个存储桶的Amazon S3用户

问题描述 投票:31回答:7

我有一个具有以下权限的用户foo(它不是任何组的成员):

{
  "Statement": [
    {
      "Sid": "Stmt1308813201865",
      "Action": "s3:*",
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::bar"
    }
  ]
}

然而,在我授予对经过身份验证的用户(可能适用于任何人)的完全访问权限之前,该用户似乎无法上传或执行任何操作。这仍然不允许用户更改权限,因为在上传后尝试执行key.set_acl('public-read')时抛出错误。

理想情况下,这个用户可以完全访问bar桶,没有别的,我做错了什么?

amazon-s3 amazon-web-services user-permissions amazon-iam
7个回答
39
投票

您需要向存储桶本身授予s3:ListBucket权限。请尝试以下政策。

{
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "S3:*",
      "Resource": "arn:aws:s3:::bar/*",
      "Condition": {}
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket"
      ],
      "Resource": "arn:aws:s3:::bar",
      "Condition": {}
    }
  ]
}

20
投票

选定的答案对我不起作用,但是这个答案是:

{
  "Statement": [
    {
      "Action": "s3:*",
      "Effect": "Allow",
      "Resource": [
        "arn:aws:s3:::my-bucket",
        "arn:aws:s3:::my-bucket/*"
      ]
    }
  ],
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "s3:ListAllMyBuckets",
      "Resource": "arn:aws:s3:::*"
    }
  ]
}

图片来源:http://mikeferrier.com/2011/10/27/granting-access-to-a-single-s3-bucket-using-amazon-iam/


8
投票

你知道AWS Policy Generator吗?


1
投票

Writing IAM Policies: How to Grant Access to an Amazon S3 Bucket上有正式的AWS文档

只需复制并粘贴相应的规则,然后在所有语句中将“资源”键更改为存储桶的ARN。

对于程序化访问,策略应该是:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": ["s3:ListBucket"],
            "Resource": ["arn:aws:s3:::bar"]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:GetObject",
                "s3:GetObjectAcl",
                "s3:DeleteObject"
            ],
            "Resource": ["arn:aws:s3:::bar/*"]
        }
    ]
}

对于控制台访问访问应该是:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetBucketLocation",
                "s3:ListAllMyBuckets"
            ],
            "Resource": "arn:aws:s3:::bar*"
        },
        {
            "Effect": "Allow",
            "Action": ["s3:ListBucket"],
            "Resource": ["arn:aws:s3:::bar"]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:GetObject",
                "s3:GetObjectAcl",
                "s3:DeleteObject"
            ],
            "Resource": ["arn:aws:s3:::bar/*"]
        }
    ]
}

0
投票

这对我行得通:

{
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetBucketLocation",
                "s3:ListBucketMultipartUploads",
                "s3:ListBucketVersions"
            ],
            "Resource": "arn:aws:s3:::bucket_name_here"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:*Object*",
                "s3:ListMultipartUploadParts",
                "s3:AbortMultipartUpload"
            ],
            "Resource": "arn:aws:s3:::bucket_name_here/*"
        }
    ]
}

0
投票

如果你一直在拔头发,因为你无法弄清楚为什么Cyber​​duck无法设置对象ACL但它可以与另一个客户端(如Panic Transmit)一起使用,这里是解决方案:

您需要将s3:GetBucketAcl添加到您的动作列表中,例如:

{
    "Statement": [
        {
            "Sid": "Stmt1",
            "Action": [
                "s3:GetBucketAcl",
                "s3:ListBucket",
                "s3:DeleteObject",
                "s3:GetObject",
                "s3:GetObjectAcl",
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::your-bucket-name"
        }
    ]
}

当然,如果你对s3:*的限制较少,你不需要这样做,但我认为这很好。


0
投票

@ cloudberryman的回答是正确的,但我喜欢让事情尽可能短。这个答案可以简化为:

{  
   "Statement":[  
      {  
         "Effect":"Allow",
         "Action":"S3:*",
         "Resource":[  
            "arn:aws:s3:::bar",
            "arn:aws:s3:::bar/*"
         ]
      }
   ]
}
© www.soinside.com 2019 - 2024. All rights reserved.