Skip to content

Commit

Permalink
Modify rule S6249: fix Terraform code examples (#4502)
Browse files Browse the repository at this point in the history
  • Loading branch information
GabinL21 authored Nov 14, 2024
1 parent 9f98b3b commit 19f97f6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions rules/S6249/terraform/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include::../recommended.adoc[]

No secure policy is attached to this bucket:

[source,terraform]
----
resource "aws_s3_bucket" "mynoncompliantbucket" { # Sensitive
bucket = "mynoncompliantbucketname"
Expand All @@ -16,6 +17,7 @@ resource "aws_s3_bucket" "mynoncompliantbucket" { # Sensitive

A policy is defined but forces only HTTPs communication for some users:

[source,terraform]
----
resource "aws_s3_bucket" "mynoncompliantbucket" { # Sensitive
bucket = "mynoncompliantbucketname"
Expand All @@ -31,13 +33,13 @@ resource "aws_s3_bucket_policy" "mynoncompliantbucketpolicy" {
{
Sid = "HTTPSOnly"
Effect = "Deny"
Principal = [
"arn:aws:iam::123456789123:root"
] # secondary location: only one principal is forced to use https
Principal = {
"AWS": "arn:aws:iam::123456789123:root"
} # secondary location: only one principal is forced to use https
Action = "s3:*"
Resource = [
aws_s3_bucket.mynoncompliantbucketpolicy.arn,
"${aws_s3_bucket.mynoncompliantbucketpolicy.arn}/*",
aws_s3_bucket.mynoncompliantbucket.arn,
"${aws_s3_bucket.mynoncompliantbucket.arn}/*",
]
Condition = {
Bool = {
Expand Down Expand Up @@ -70,7 +72,9 @@ resource "aws_s3_bucket_policy" "mycompliantpolicy" {
{
Sid = "HTTPSOnly"
Effect = "Deny"
Principal = "*"
Principal = {
"AWS": "*"
}
Action = "s3:*"
Resource = [
aws_s3_bucket.mycompliantbucket.arn,
Expand Down

0 comments on commit 19f97f6

Please sign in to comment.