include::../description.adoc[] include::../ask-yourself.adoc[] include::../recommended.adoc[] == Sensitive Code Example This policy allows all users, including anonymous ones, to access an S3 bucket: ---- resource "aws_s3_bucket_policy" "mynoncompliantpolicy" { # Sensitive bucket = aws_s3_bucket.mybucket.id policy = jsonencode({ Id = "mynoncompliantpolicy" Version = "2012-10-17" Statement = [{ Effect = "Allow" Principal = { AWS = "*" } Action = [ "s3:PutObject" ] Resource: "${aws_s3_bucket.mybucket.arn}/*" } ] }) } ---- == Compliant Solution This policy allows only the authorized users: [source,terraform] ---- resource "aws_s3_bucket_policy" "mycompliantpolicy" { bucket = aws_s3_bucket.mybucket.id policy = jsonencode({ Id = "mycompliantpolicy" Version = "2012-10-17" Statement = [{ Effect = "Allow" Principal = { AWS = [ "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root" ] } Action = [ "s3:PutObject" ] Resource = "${aws_s3_bucket.mybucket.arn}/*" } ] }) } ---- include::../see.adoc[] ifdef::env-github,rspecator-view[] ''' == Implementation Specification (visible only on this page) include::../message.adoc[] endif::env-github,rspecator-view[]