amazon-web-services - 允许访问特定用户并限制所有用户的 S3 存储桶策略

标签 amazon-web-services amazon-s3

我搜索了现有的问题,但找不到答案。因此在这里发帖。

我想限制所有用户访问 S3 存储桶,除了使用 S3 存储桶策略选择少数用户。我了解 IAM 策略易于管理和管理,我不喜欢为此特定案例创建角色和组,并希望创建 S3 存储桶策略。

这是我到目前为止所尝试的,它没有按预期限制对用户的访问。

{
  "Version": "2012-10-17",
  "Id": "bucketPolicy",
  "Statement": [
    {

      "Effect": "Allow",
      "Principal": {
        "AWS": ["arn:aws:iam::1234567890:user/allowedusername"]
      },
      "Action": "s3:*",
      "Resource": ["arn:aws:s3:::examplebucket",
                   "arn:aws:s3:::examplebucket/*"]
    },
    {

      "Effect": "Deny",
      "Principal": {
        "AWS": ["arn:aws:iam::1234567890:user/denieduser"]
      },
      "Action": "s3:*",
      "Resource": ["arn:aws:s3:::examplebucket",
                   "arn:aws:s3:::examplebucket/*"]
    }

  ]
}

我试图拒绝所有如下内容,但明确拒绝优先于允许,我自己现在无法访问存储桶;-(这是我遇到的另一个问题
{

          "Effect": "Deny",
          "Principal": {
            "AWS": ["*"]
          },
          "Action": "s3:*",
          "Resource": ["arn:aws:s3:::examplebucket",
                       "arn:aws:s3:::examplebucket/*"]
        }

最佳答案

要实现您想要的,请使用带有 NotPrincipal 策略元素的显式拒绝。下面的策略将确保除了 NotPrincipal 元素中列出的用户之外,没有其他用户可以访问存储桶:

{
        "Id": "bucketPolicy",
        "Statement": [
                {
                        "Action": "s3:*",
                        "Effect": "Deny",
                        "NotPrincipal": {
                                "AWS": [
                                        "arn:aws:iam::1234567890:user/alloweduser"
                                ]
                        },
                        "Resource": [
                                "arn:aws:s3:::examplebucket",
                                "arn:aws:s3:::examplebucket/*"
                        ]
                }
        ],
        "Version": "2012-10-17"
}

关于amazon-web-services - 允许访问特定用户并限制所有用户的 S3 存储桶策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36207399/

相关文章:

amazon-web-services - 为什么 boto3 s3 对象缺少存储类属性?

python - 我可以将 xvfb 与 AWS Lambda 一起使用吗?

amazon-web-services - 如何找到 AWS 中现有资源的正确 ID 以便导入 Terraform 资源?

amazon-s3 - 在没有签名 URL 的情况下使用 CloudFront/S3 设置内容处置

amazon-web-services - AWS CloudWatch 指标直接到 S3

tensorflow - 带有 s3 logdir 的 Tensorboard/tensorflow - curl 返回错误代码 6

amazon-web-services - 禁用 http 重定向到 https

reporting-services - Cloud Reporting Services中的自定义渲染扩展

amazon-web-services - 如何使用AWS Lambda检查S3中的文件

php - 将YouTube视频上传到AWS S3不能正常播放