71 lines
1.5 KiB
Plaintext
Raw Normal View History

2021-05-21 18:34:30 +02:00
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:
2021-05-21 18:34:30 +02:00
----
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 = [
2021-05-21 18:34:30 +02:00
"s3:PutObject"
]
Resource: "${aws_s3_bucket.mybucket.arn}/*"
2021-05-21 18:34:30 +02:00
}
]
})
2021-05-21 18:34:30 +02:00
}
----
== Compliant Solution
This policy allows only the authorized users:
2022-02-04 17:28:24 +01:00
[source,terraform]
2021-05-21 18:34:30 +02:00
----
resource "aws_s3_bucket_policy" "mycompliantpolicy" {
2021-05-21 18:34:30 +02:00
bucket = aws_s3_bucket.mybucket.id
policy = jsonencode({
Id = "mycompliantpolicy"
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = {
AWS = [
2021-05-21 18:34:30 +02:00
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
]
}
Action = [
2021-05-21 18:34:30 +02:00
"s3:PutObject"
]
Resource = "${aws_s3_bucket.mybucket.arn}/*"
2021-05-21 18:34:30 +02:00
}
]
})
2021-05-21 18:34:30 +02:00
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
endif::env-github,rspecator-view[]