【问题标题】:Access Denied from S3 Bucket [pendente]来自 S3 存储桶的访问被拒绝 [pendente]
【发布时间】:2017-02-07 01:16:58
【问题描述】:

在账户 A 中,我使用 cloudformation 创建了一个 s3 存储桶,CodeBuild 构建了一个工件并上传到该存储桶。在账户 B 中,我尝试使用 cloudformation 创建堆栈,并使用账户 A 的存储桶中的工件来部署我的 Lambda 函数。但是,我收到拒绝访问错误。有谁知道解决方案?谢谢...

"TestBucket": {
  "Type": "AWS::S3::Bucket",
  "DeletionPolicy": "Retain",
  "Properties": {
    "AccessControl": "BucketOwnerFullControl"
  }
},
"IAMPolicy": {
  "Type": "AWS::S3::BucketPolicy",
  "Properties": {
    "Bucket": {
      "Ref": "TestBucket"
    },
    "PolicyDocument": {
      "Statement": [
        {
          "Effect": "Allow",
          "Principal": {
            "AWS": [
              "arn:aws:iam::xxxxxxxxxxxx:root",
              "arn:aws:iam::xxxxxxxxxxxx:root"
            ]
          },
          "Action": [
            "s3:GetObject"
          ],
          "Resource": [
            {
              "Fn::Join": [
                "",
                [
                  "arn:aws:s3:::",
                  {
                    "Ref": "TestBucket"
                  },
                  "/*"
                ]
              ]
            },
            {
              "Fn::Join": [
                "",
                [
                  "arn:aws:s3:::",
                  {
                    "Ref": "TestBucket"
                  }
                ]
              ]
            }
          ]
        }
      ]
    }
  }
}

【问题讨论】:

    标签: amazon-web-services amazon-s3 amazon-cloudformation


    【解决方案1】:

    假设下面语句中的 xxxxx 是 Account B 的帐号:

    "AWS": [
                  "arn:aws:iam::xxxxxxxxxxxx:root",
                  "arn:aws:iam::xxxxxxxxxxxx:root"
                ]
    

    您是说此存储桶根据账户 B IAM 服务中持有的 IAM 权限/策略授予对账户 B 的访问权限。

    因此,基本上所有具有显式 S3 访问权限的用户/实例配置文件/策略都将能够访问账户 A 的这个存储桶。这意味着您附加到账户 B 中 lambda 角色的 IAM 策略可能不具有明确的 S3 访问权限。

    我建议让 S3 访问您的 Lambda 函数,这应该可行。

    请注意,以后如果您想从账户 B 写入账户 A 的 S3 存储桶,您必须确保将 bucket-owner-full-control acl 放入以便对象可用所有帐户。

    示例

    使用 CLI: $ aws s3api put-object --acl bucket-owner-full-control --bucket my-test-bucket --key dir/my_object.txt --body /path/to/my_object.txt

    【讨论】:

      【解决方案2】:

      不要让"arn:aws:iam::xxxxxxxxxxxx:root" 仅授予对 root 角色的访问权限,而是尝试通过仅将帐户 ID 指定为 Principal/AWS 对象中的项目来授予对帐户中所有身份的访问权限:"xxxxxxxxxxxx"

      更多详情请见Using a Resource-based Policy to Delegate Access to an Amazon S3 Bucket in Another Account

      【讨论】:

        猜你喜欢
        • 2019-02-03
        • 2018-01-10
        • 1970-01-01
        • 2021-09-03
        • 2017-02-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-05
        相关资源
        最近更新 更多