2021-05-21 18:34:30 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
include::../ask-yourself.adoc[]
|
|
|
|
|
|
|
|
include::../recommended.adoc[]
|
|
|
|
|
|
|
|
== Sensitive Code Example
|
|
|
|
|
2022-09-30 15:16:31 +02:00
|
|
|
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
|
2021-06-30 10:12:45 +02:00
|
|
|
policy = jsonencode({
|
2021-06-30 13:38:51 +02:00
|
|
|
Id = "mynoncompliantpolicy"
|
|
|
|
Version = "2012-10-17"
|
|
|
|
Statement = [{
|
|
|
|
Effect = "Allow"
|
|
|
|
Principal = {
|
|
|
|
AWS = "*"
|
|
|
|
}
|
|
|
|
Action = [
|
2021-05-21 18:34:30 +02:00
|
|
|
"s3:PutObject"
|
2021-06-30 13:38:51 +02:00
|
|
|
]
|
|
|
|
Resource: "${aws_s3_bucket.mybucket.arn}/*"
|
2021-05-21 18:34:30 +02:00
|
|
|
}
|
|
|
|
]
|
2021-06-30 10:12:45 +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
|
|
|
----
|
2021-06-30 10:12:45 +02:00
|
|
|
resource "aws_s3_bucket_policy" "mycompliantpolicy" {
|
2021-05-21 18:34:30 +02:00
|
|
|
bucket = aws_s3_bucket.mybucket.id
|
2021-06-30 10:12:45 +02:00
|
|
|
policy = jsonencode({
|
2021-06-30 13:38:51 +02:00
|
|
|
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"
|
|
|
|
]
|
2021-06-30 13:38:51 +02:00
|
|
|
}
|
|
|
|
Action = [
|
2021-05-21 18:34:30 +02:00
|
|
|
"s3:PutObject"
|
2021-06-30 13:38:51 +02:00
|
|
|
]
|
|
|
|
Resource = "${aws_s3_bucket.mybucket.arn}/*"
|
2021-05-21 18:34:30 +02:00
|
|
|
}
|
|
|
|
]
|
2021-06-30 10:12:45 +02:00
|
|
|
})
|
2021-05-21 18:34:30 +02:00
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
include::../see.adoc[]
|
2023-06-22 10:38:01 +02:00
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|