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-allows-get-actions-from-all-principals.md.
A documentation index is available at /llms.txt.
S3 bucket policies must not allow GET actions to all principals (*). Public read permissions can lead to data exfiltration or unauthorized disclosure of sensitive content. Check AWS::S3::BucketPolicy resources’ Properties.PolicyDocument.Statement entries and flag any statement with Effect: "Allow" and Principal: "*" (or equivalent wildcard) where Action contains GET operations (for example, s3:GetObject). Instead, restrict Principal to specific AWS account IDs, roles, or ARNs, or remove GET actions. If public access is required, apply scoped conditions (IP ranges, VPC endpoints) or enable S3 Block Public Access to limit exposure.
Secure configuration example (restrict principal to a specific role):
#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:"GetObject"Effect:AllowResource:"*"Principal:"*"Condition:StringLike:'aws:Referer':- 'http://www.example.com/*'- 'http://example.net/*'SampleBucketPolicy4:Type:'AWS::S3::BucketPolicy'Properties:Bucket:!Ref DOC-EXAMPLE-BUCKETPolicyDocument:Statement:- Action:- "DeleteObject"- "GetObject"Effect:AllowResource:"*"Principal:"*"Condition:StringLike:'aws:Referer':- 'http://www.example.com/*'- 'http://example.net/*'