简体   繁体   中英

Incorrect S3 bucket policy is detected for bucket at Cloud Trail

Receveing this error Incorrect S3 bucket policy is detected for bucket:

(Service: AWSCloudTrail; Status Code: 400; Error Code: InsufficientS3BucketPolicyException; Request ID: ebaf35b8-a38e-4357-a742-af5fa92bbc43)

Parameters:
    trailname:
      Type: String
    s3bucketname:
      Type: String
Resources:
    myvpctrail:
      DependsOn:
        - s3bucketpolicy
        - creates3bucket
      Type: AWS::CloudTrail::Trail
      Properties:
        IsLogging: true
        IsMultiRegionTrail: true
        IncludeGlobalServiceEvents: true
        S3BucketName: !Ref creates3bucket
    creates3bucket:
      Type: AWS::S3::Bucket
      Properties: 
        BucketName: !Sub ${s3bucketname}
    s3bucketpolicy:
      Type: AWS::S3::BucketPolicy
      Properties:
        Bucket: !Sub ${s3bucketname}
        PolicyDocument:
          Version: '2012-10-17'
          Statement:
            - Sid: 'AWSCloudTrailAclCheck20150319'
              Effect: 'Allow'
              Principal: 
                  Service: 'cloudtrail.amazonaws.com'
              Action: 's3:GetBucketAcl'
              Resource: 
                !Sub 'arn:aws:s3:::${s3bucketname}'
        PolicyDocument:
          Version: '2012-10-17'
          Statement:
            - Sid: AWSCloudTrailWrite20150319
              Effect: 'Allow'
              Principal: 
                  Service: 'cloudtrail.amazonaws.com'
              Action: 's3:PutObject'
              Resource: 
                !Sub 'arn:aws:s3:::${s3bucketname}/AWSLogs/${AWS::AccountId}/*'
              Condition:
                StringEquals: 
                    s3:x-amz-acl: 'bucket-owner-full-control'

Incorrect S3 bucket policy is detected for bucket: (Service: AWSCloudTrail; Status Code: 400; Error Code: InsufficientS3BucketPolicyException; Request ID: ebaf35b8-a38e-4357-a742-af5fa92bbc43) enter code here

You should be extremely careful with indentation and property names in YAML. I believe the problem is in Condition which should be something like:

        Condition:
          StringEquals:
            's3:x-amz-acl': bucket-owner-full-control

Compare this to your:

      Condition:
        StringEquals: 
            s3:x-amz-acl: 'bucket-owner-full-control'

The problem lies with these lines:

          Statement:
            - Sid: 'AWSCloudTrailAclCheck20150319'

should be:

          Statement:
            - 
              Sid: 'AWSCloudTrailAclCheck20150319'

And:

          Statement:
            - Sid: AWSCloudTrailWrite20150319

should be:

          Statement:
            - 
              Sid: AWSCloudTrailWrite20150319

This is because they are dictionary values, not a list .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM