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-without-ssl-in-write-actions.md.
A documentation index is available at /llms.txt.
S3 buckets should enforce SSL/TLS for data in transit to prevent unencrypted requests from exposing sensitive data or enabling man-in-the-middle attacks.
Ensure each AWS::S3::Bucket has an associated AWS::S3::BucketPolicy whose Properties.PolicyDocument.Statement enforces aws:SecureTransport. For example, use a Deny statement that blocks unsafe actions (such as s3:* or s3:PutObject) when Condition.Bool["aws:SecureTransport"] is false. Alternatively, use Allow statements that only permit those actions when aws:SecureTransport is true.
Resources missing an AWS::S3::BucketPolicy, or with statements that do not include the Condition.Bool["aws:SecureTransport"] check (that is, do not deny unsecured requests), will be flagged.
#this code is a correct code for which the query should not find any resultAWSTemplateFormatVersion:2010-09-09Resources:S3Bucket:Type:AWS::S3::BucketProperties:BucketName:S3BucketAccessControl:PublicReadWebsiteConfiguration:IndexDocument:index.htmlErrorDocument:error.htmlDeletionPolicy:RetainBucketPolicy:Type:AWS::S3::BucketPolicyProperties:PolicyDocument:Id:MyPolicyVersion:2012-10-17Statement:- Sid:PublicReadForGetBucketObjectsEffect:AllowPrincipal:'*'Action:'s3:GetObject'Resource:!Join- ''- - 'arn:aws:s3:::'- !Ref S3Bucket- /*- Sid:EnsureSSLEffect:DenyPrincipal:'*'Action:'s3:PutObject'Condition:Bool:'aws:SecureTransport':falseResource:!Join- ''- - 'arn:aws:s3:::'- !Ref S3Bucket- /*Bucket:!Ref S3BucketOutputs:WebsiteURL:Value:!GetAtt- S3Bucket- WebsiteURLDescription:URL for website hosted on S3S3BucketSecureURL:Value:!Join- ''- - 'https://'- !GetAtt- S3Bucket- DomainNameDescription:Name of S3 bucket to hold website content
AWSTemplateFormatVersion:2010-09-09Resources:S3Bucket2:Type:AWS::S3::BucketProperties:BucketName:S3Bucket2AccessControl:PublicReadWebsiteConfiguration:IndexDocument:index.htmlErrorDocument:error.htmlDeletionPolicy:RetainBucketPolicy:Type:AWS::S3::BucketPolicyProperties:PolicyDocument:Id:MyPolicyVersion:2012-10-17Statement:- Sid:EnsureSSLEffect:DenyPrincipal:'*'Action:'s3:*'Condition:Bool:'aws:SecureTransport':falseResource:!Join- ''- - 'arn:aws:s3:::'- !Ref S3Bucket2- /*Bucket:!Ref S3Bucket2S3Bucket3:Type:AWS::S3::BucketProperties:AccessControl:PublicReadWebsiteConfiguration:IndexDocument:index.htmlErrorDocument:error.htmlDeletionPolicy:RetainBucketPolicy2:Type:AWS::S3::BucketPolicyProperties:PolicyDocument:Id:MyPolicy2Version:2012-10-17Statement:- Sid:EnsureSSLEffect:DenyPrincipal:'*'Action:'s3:*'Condition:Bool:'aws:SecureTransport':falseResource:!Join- ''- - 'arn:aws:s3:::'- !Ref S3Bucket3- /*Bucket:!Ref S3Bucket3Outputs:WebsiteURL:Value:!GetAtt- S3Bucket2- WebsiteURLDescription:URL for website hosted on S3S3BucketSecureURL:Value:!Join- ''- - 'https://'- !GetAtt- S3Bucket2- DomainNameDescription:Name of S3 bucket to hold website content
{"AWSTemplateFormatVersion":"2010-09-09T00:00:00Z","Resources":{"S3Bucket":{"Type":"AWS::S3::Bucket","Properties":{"BucketName":"S3Bucket","AccessControl":"PublicRead","WebsiteConfiguration":{"IndexDocument":"index.html","ErrorDocument":"error.html"}},"DeletionPolicy":"Retain"},"BucketPolicy":{"Type":"AWS::S3::BucketPolicy","Properties":{"Bucket":"S3Bucket","PolicyDocument":{"Id":"MyPolicy","Version":"2012-10-17T00:00:00Z","Statement":[{"Sid":"PublicReadForGetBucketObjects","Effect":"Allow","Principal":"*","Action":"s3:GetObject","Resource":["",["arn:aws:s3:::","S3Bucket","/*"]]},{"Principal":"*","Action":"s3:PutObject","Condition":{"Bool":{"aws:SecureTransport":false}},"Resource":["",["arn:aws:s3:::","S3Bucket","/*"]],"Sid":"EnsureSSL","Effect":"Deny"}]}}}},"Outputs":{"WebsiteURL":{"Value":["S3Bucket","WebsiteURL"],"Description":"URL for website hosted on S3"},"S3BucketSecureURL":{"Description":"Name of S3 bucket to hold website content","Value":["",["https://",["S3Bucket","DomainName"]]]}}}
Non-Compliant Code Examples
AWSTemplateFormatVersion:2010-09-09Resources:S3Bucket:Type:AWS::S3::BucketProperties:BucketName:S3BucketAccessControl:PublicReadWebsiteConfiguration:IndexDocument:index.htmlErrorDocument:error.htmlDeletionPolicy:RetainBucketPolicy:Type:AWS::S3::BucketPolicyProperties:PolicyDocument:Id:MyPolicyVersion:2012-10-17Statement:- Sid:PublicReadForGetBucketObjectsEffect:AllowPrincipal:'*'Action:'s3:GetObject'Resource:!Join- ''- - 'arn:aws:s3:::'- !Ref S3Bucket- /*Bucket:!Ref S3BucketOutputs:WebsiteURL:Value:!GetAtt- S3Bucket- WebsiteURLDescription:URL for website hosted on S3S3BucketSecureURL:Value:!Join- ''- - 'https://'- !GetAtt- S3Bucket- DomainNameDescription:Name of S3 bucket to hold website content