For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/terraform-aws-s3-bucket-access-to-any-principal.md.
A documentation index is available at /llms.txt.
When an S3 bucket policy allows access to all AWS principals (*), it creates a significant security vulnerability by potentially exposing sensitive data to anyone on the internet. Malicious actors could access, modify, or delete your data, leading to data breaches, regulatory violations, and reputational damage. To secure your S3 bucket, avoid using * in the Principal field with an Allow effect. Instead, explicitly specify authorized principals or use a Deny effect, as shown below:
resource"aws_s3_bucket""this"{bucket="my_tf_test_bucket"tags={Name="My bucket"}}resource"aws_s3_bucket_policy""this"{bucket=aws_s3_bucket.this.idpolicy= jsonencode({Version="2012-10-17"Statement=[{ # When used directly as a Cloudfront origin.
Effect="Allow"Action="s3:GetObject"Principal={Service="cloudfront.amazonaws.com"}Resource=["${aws_s3_bucket.this.arn}/*",]Condition={StringEquals={"AWS:SourceArn"=aws_cloudfront_distribution.this.arn}}},{ # Admin access for policy updates, etc.
Effect="Allow"Action="s3:*"Principal={AWS=[data.aws_caller_identity.current.id,]}Resource=["${aws_s3_bucket.this.arn}/*",]},{ # Delegate access to the access point.
Effect="Allow"Action="*"Principal={AWS=["*"]}Resource=[aws_s3_bucket.this.arn,"${aws_s3_bucket.this.arn}/*",]Condition={"StringEquals"={"s3:DataAccessPointAccount"=data.aws_caller_identity.current.account_id}}}]})}
1
2
rulesets:- Terraform / AWS # Rules to enforce / AWS.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.