Skip to content

Commit

Permalink
Make requiring TLS optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarrien committed Jan 12, 2021
1 parent b3d02f1 commit 70000e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
29 changes: 16 additions & 13 deletions aws-s3-public-bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,25 @@ data "aws_iam_policy_document" "bucket_policy" {
# Deny access to bucket if it's not accessed through HTTPS
source_json = var.bucket_policy

statement {
sid = "EnforceTLS"
actions = ["s3:GetObject"]
resources = ["arn:aws:s3:::${local.bucket_name}/*"]
dynamic statement {
for_each = var.require_tls ? ["enabled"] : []
content {
sid = "EnforceTLS"
actions = ["s3:GetObject"]
resources = ["arn:aws:s3:::${local.bucket_name}/*"]

principals {
type = "*"
identifiers = ["*"]
}
principals {
type = "*"
identifiers = ["*"]
}

effect = "Deny"
effect = "Deny"

condition {
test = "Bool"
variable = "aws:SecureTransport"
values = ["false"]
condition {
test = "Bool"
variable = "aws:SecureTransport"
values = ["false"]
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions aws-s3-public-bucket/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ variable "enable_versioning" {
description = "Keep old versions of objects in this bucket."
default = true
}

variable "require_tls" {
type = bool
description = "Require TLS to read objects from this bucket."
default = true
}

0 comments on commit 70000e3

Please sign in to comment.