2

看起来我在 Terraform 部署中得到了一个格式错误的策略,并且在查看它时没有看到任何问题,所有这些Principals似乎都到位并且没有任何异常。有人能找出为什么这个政策被认为是畸形的吗?

这是抛出的 TF 输出

module.s3-bucket.aws_s3_bucket_policy.bucket_policy: Creating...
  bucket: "" => "the_s3_bucket"
  policy: "" => "{\n  \"Version\":\"2012-10-17\",\n    \"Statement\":[{\n      \"Principal\": \"*\",\n      \"Action\":[\n        \"s3:GetBucketLocation\",\n        \"s3:ListAllMyBuckets\"\n      ],\n        \"Resource\":[\n          \"arn:aws:s3:::*\"\n      ],\n    \"Effect\":\"Allow\"\n  }, {\n    \"Principal\": \"*\",\n    \"Action\":[\n      \"s3:ListBucket\",\n      \"s3:ListBucketMultipartUploads\"\n    ],\n    \"Resource\":[\n      \"arn:aws:s3:::the_s3_bucket\"\n    ],\n    \"Effect\":\"Allow\"\n    }, {\n      \"Principal\": \"*\",\n    \"Action\":[\n      \"s3:GetObject\",\n      \"s3:AbortMultipartUpload\",\n      \"s3:ListMultipartUploadParts\",\n      \"s3:DeleteObject\",\n      \"s3:PutObject\",\n      \"s3:GetObjectAcl\",\n      \"s3:PutObjectAcl\"\n    ],\n    \"Resource\":[\n      \"arn:aws:s3:::the_s3_bucket/*\"\n    ],\n    \"Effect\":\"Allow\"\n  }]\n}\n"

(非详细)错误:

Error applying plan:

1 error(s) occurred:

* module.s3-bucket.aws_s3_bucket_policy.bucket_policy: 1 error(s) occurred:

* aws_s3_bucket_policy.bucket_policy: Error putting S3 policy: MalformedPolicy: Policy has invalid action
    status code: 400, request id: DCAEB510D9FE431C, host id: FwZ187PM8RKZljAZGo1578UvsgW3kwtZpaI2Mom46lu7Jr+NV9Jum8txjsfwdJw0jm9ct0awRWk=

这是它包含的内容的漂亮打印

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

更新

很明显,这与该Principal领域有关,在通过 AWS 控制台运行它后,我得到了错误

This policy contains the following error: Has prohibited field Principal For more information about the IAM policy grammar, see AWS IAM Policies 
4

1 回答 1

2

s3:ListAllMyBuckets权限不能应用于 S3 存储桶策略,而是 IAM 策略权限。您还必须在存储桶策略中直接指定策略附加到的存储桶,而不是使用该存储桶"Resource": ["*"]或其他一些通配符。

IAM 策略和 S3 存储桶策略密切相关并且重叠很多,但您应该将它们视为有时可能需要的进一步控制级别。不幸的是,S3 权限模型非常混乱,并且有多层添加访问控制,从存储桶 ACL和对象 ACL(包括完全可配置的和罐装的)到存储桶策略以及附加到 IAM 用户或角色的直接IAM 权限。

大多数情况下,您最好使用预设 ACL,然后使用 IAM 用户策略来控制谁可以执行 ACL 不允许的额外操作。用户指南中对这些有进一步的解释。

于 2018-07-12T17:01:36.077 回答