【问题标题】:Enable logging S3 via cloudFormation template?通过 cloudFormation 模板启用日志记录 S3?
【发布时间】:2017-08-08 08:25:06
【问题描述】:

我正在尝试使用 2 个不同的策略创建 2 个存储桶。

一个桶,VendorsWGLogs,将是日志输出的目的地。

另一个存储桶 VendorsWG 将授予 GetObject、PutObject 和 DeleteObject 对指定 IAM 组的访问权限。

这是我目前所拥有的:

"Resources": {
    "VendorsWGLogs": {
      "Type": "AWS::S3::Bucket",
      "Properties": {},
    },
    "LogsBucketPolicy": {
      "Type": "AWS::S3::BucketPolicy",
      "Properties": {
        "Bucket": {
          "Ref": "VendorsWGLogs"
        },
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Sid": "WeatherGuidance LogBucket permissions",
              "Effect": "Allow",
              "Principal": {
                "AWS" : "arn:aws:s3:::VendorsWG"
              },
              "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:PutObjectAcl"
              ],
              "Resource" : { "Fn::Join" : [
                  "", [ "arn:aws:s3:::", { "Ref" : "VendorsWGLogs" } , "/*" ]
               ]}
            }
          ]
        }
      }
    },
    "VendorsWG": {
      "Type": "AWS::S3::Bucket",
      "Properties": {
        "LoggingConfiguration": {
          "DestinationBucketName": {"Ref" : "VendorsWGLogs"},
          "LogFilePrefix": "testing-logs"
        }
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "a1169860-d743-406e-a3e5-e12831826439"
        },
      }
    },
    "S3BP4TNQZ": {
      "Type": "AWS::S3::BucketPolicy",
      "Properties": {
        "Bucket": {
          "Ref": "VendorsWG"
        },
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Sid": "WeatherGuidance Object permissions",
              "Effect": "Allow",
              "Principal": {
                "AWS" : "arn:aws:iam::someUserGroup"
              },
              "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:DeleteObject"
              ],
              "Resource" : { "Fn::Join" : [
                  "", [ "arn:aws:s3:::", { "Ref" : "VendorsWG" } , "/*" ]
               ]}
            },
            {
              "Sid": "WeatherGuidance ListBucket",
              "Effect": "Allow",
              "Principal": {
                "AWS" : "arn:aws:iam::someUserGroup"
              },
              "Action": "s3:ListBucket",
              "Resource" : { "Fn::Join" : [
                  "", [ "arn:aws:s3:::", { "Ref" : "VendorsWG" } ]
               ]},
              "Condition": {
                "StringLike": {
                  "s3:prefix": "weatherguidance*"
                }
              }
            }
          ]
        }
      }
    }
  }

当我尝试创建堆栈时,我收到此错误

事件日志输出:

类型:

AWS::S3::Bucket

逻辑 ID:

VendorsWG   

状态原因:

You must give the log-delivery group WRITE and READ_ACP permissions to the target bucket

我认为将目标存储桶的策略主体指定为 VendorsWGLogs 可以解决此问题,但现在我没有想法了。

我做错了什么?我可以做些什么来启用日志记录? 谢谢

【问题讨论】:

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


    【解决方案1】:

    需要把它放在日志桶的属性下

    Properties: {
          AccessControl: "LogDeliveryWrite"
    }
    

    【讨论】:

      【解决方案2】:

      我认为你的问题有两个方面:

      1. 动作中没有s3:ListBucket,因此无法读取存储桶的内容
      2. s3 存储桶上的操作在存储桶 (VendorsWGLogs) 和内容 (VendorsWGLogs/*) 级别运行,因此您需要将它们都列在资源下。生成的策略应为

        “资源”:[ "arn:aws:s3:::VendorsWGLogs", “arn:aws:s3:::VendorsWGLogs/*” ]

      【讨论】:

      • 感谢您的回复!我不明白你所说的 #1 是什么意思 另外,bucket 应该列在 resources where 下?
      • 我将操作更改为使用通配符 *,并添加了 Resource 行,但我仍然收到相同的错误......
      猜你喜欢
      • 2020-09-17
      • 1970-01-01
      • 1970-01-01
      • 2020-06-15
      • 2014-11-10
      • 1970-01-01
      • 1970-01-01
      • 2021-09-17
      • 2020-02-20
      相关资源
      最近更新 更多