Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] aws-s3-public-bucket require https, allow disabling versioning #278

Merged
merged 2 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion aws-s3-public-bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ resource "aws_s3_bucket" "bucket" {
policy = data.aws_iam_policy_document.bucket_policy.json

versioning {
enabled = true
enabled = var.enable_versioning
}

server_side_encryption_configuration {
Expand All @@ -37,6 +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}/*"]

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

effect = "Deny"

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

statement {
sid = "AllowPublicRead"
actions = ["s3:GetObject"]
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 @@ -44,3 +44,9 @@ variable "public_read_justification" {
type = string
description = "Describe why this bucket must be public and what it is being used for."
}

variable "enable_versioning" {
type = bool
description = "Keep old versions of objects in this bucket."
default = true
}