For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/cloudformation-aws-s3-bucket-with-all-permissions.md.
A documentation index is available at /llms.txt.
S3 bucket policies must not grant Allow for all actions to all principals. This creates public full access to the bucket and can result in data exposure, tampering, or deletion.
Check AWS::S3::BucketPolicy resources’ Properties.PolicyDocument.Statement entries and flag any statement where Effect: "Allow", Action: "*", and Principal: "*". Statements matching these conditions will be reported. Restrict principals to specific AWS account IDs/ARNs or services and limit Action to the minimum required S3 operations instead of using wildcards.
Secure example limiting access to a specific account and action:
#this code is a correct code for which the query should not find any resultResources:SampleBucketPolicy1:Type:'AWS::S3::BucketPolicy'Properties:Bucket:!Ref DOC-EXAMPLE-BUCKETPolicyDocument:Statement:- Action:- 's3:GetObject'Effect:DenyResource:'*'Principal:'*'Condition:StringLike:'aws:Referer':- 'http://www.example.com/*'- 'http://example.net/*'
#this is a problematic code where the query should report a result(s)Resources:SampleBucketPolicy3:Type:'AWS::S3::BucketPolicy'Properties:Bucket:!Ref DOC-EXAMPLE-BUCKETPolicyDocument:Statement:- Action:"*"Effect:AllowResource:"*"Principal:"*"Condition:StringLike:'aws:Referer':- 'http://www.example.com/*'- 'http://example.net/*'