Skip to content

Commit ae34a72

Browse files
authored
[feature] aws-s3-public-bucket require https, allow disabling versioning (#278)
1 parent 1b53806 commit ae34a72

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

aws-s3-public-bucket/main.tf

+23-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ resource "aws_s3_bucket" "bucket" {
2020
policy = data.aws_iam_policy_document.bucket_policy.json
2121

2222
versioning {
23-
enabled = true
23+
enabled = var.enable_versioning
2424
}
2525

2626
server_side_encryption_configuration {
@@ -37,6 +37,28 @@ data "aws_iam_policy_document" "bucket_policy" {
3737
# Deny access to bucket if it's not accessed through HTTPS
3838
source_json = var.bucket_policy
3939

40+
dynamic statement {
41+
for_each = var.require_tls ? ["enabled"] : []
42+
content {
43+
sid = "EnforceTLS"
44+
actions = ["s3:GetObject"]
45+
resources = ["arn:aws:s3:::${local.bucket_name}/*"]
46+
47+
principals {
48+
type = "*"
49+
identifiers = ["*"]
50+
}
51+
52+
effect = "Deny"
53+
54+
condition {
55+
test = "Bool"
56+
variable = "aws:SecureTransport"
57+
values = ["false"]
58+
}
59+
}
60+
}
61+
4062
statement {
4163
sid = "AllowPublicRead"
4264
actions = ["s3:GetObject"]

aws-s3-public-bucket/variables.tf

+12
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,15 @@ variable "public_read_justification" {
4444
type = string
4545
description = "Describe why this bucket must be public and what it is being used for."
4646
}
47+
48+
variable "enable_versioning" {
49+
type = bool
50+
description = "Keep old versions of objects in this bucket."
51+
default = true
52+
}
53+
54+
variable "require_tls" {
55+
type = bool
56+
description = "Require TLS to read objects from this bucket."
57+
default = true
58+
}

0 commit comments

Comments
 (0)