Skip to content

Commit

Permalink
BFD-2869: Removal of ACLs on S3 terraservices (#2035)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael J Burling <[email protected]>
  • Loading branch information
brandoncruz3 and mjburling authored Nov 6, 2023
1 parent 3927c6a commit 8bf83b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 50 deletions.
41 changes: 9 additions & 32 deletions ops/terraform/services/common/s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ resource "aws_s3_bucket" "this" {

# block public access to the bucket
resource "aws_s3_bucket_public_access_block" "this" {
bucket = aws_s3_bucket.this.id

bucket = aws_s3_bucket.this.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
Expand All @@ -29,27 +28,16 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
}

resource "aws_s3_bucket_logging" "this" {
# TODO: Make this work better for ephemeral environments, etc
count = local.is_ephemeral_env ? 0 : 1

bucket = aws_s3_bucket.this.id

# TODO: consider adding this...
# expected_bucket_owner = local.account_id
expected_bucket_owner = local.account_id

target_bucket = local.logging_bucket
target_prefix = "${local.legacy_service}_s3_access_logs/"
}

resource "aws_s3_bucket_acl" "this" {
# After April 2023, new S3 Buckets have public access disabled along with ACLs disabled. This
# resource will fail to apply for ephemeral environments (new buckets)
# FIXME: Replace/resolve this before accepting BFD-2554
count = local.is_ephemeral_env ? 0 : 1

bucket = aws_s3_bucket.this.id
acl = "private"
}

resource "aws_s3_bucket" "logging" {
bucket = local.logging_bucket
Expand All @@ -59,32 +47,21 @@ resource "aws_s3_bucket" "logging" {
}
}

resource "aws_s3_bucket_server_side_encryption_configuration" "logging" {
bucket = aws_s3_bucket.logging.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}

resource "aws_s3_bucket_public_access_block" "logging" {
bucket = aws_s3_bucket.logging.id

bucket = aws_s3_bucket.logging.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}

resource "aws_s3_bucket_acl" "logging" {
# After April 2023, new S3 Buckets have public access disabled along with ACLs disabled. This
# resource will fail to apply for ephemeral environments
# TODO: Replace/resolve this in BFD-2554
count = local.is_ephemeral_env ? 0 : 1

acl = "log-delivery-write"
resource "aws_s3_bucket_server_side_encryption_configuration" "logging" {
bucket = aws_s3_bucket.logging.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}

resource "aws_s3_bucket_policy" "logging" {
Expand Down
20 changes: 2 additions & 18 deletions ops/terraform/services/pipeline/s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ resource "aws_s3_bucket" "this" {

# block public access to the bucket
resource "aws_s3_bucket_public_access_block" "this" {
bucket = aws_s3_bucket.this.id

bucket = aws_s3_bucket.this.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
Expand All @@ -31,26 +30,11 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
}

resource "aws_s3_bucket_logging" "this" {
# After April 2023, new S3 Buckets have public access disabled along with ACLs disabled. This
# resource will fail to apply for ephemeral environments (new buckets)
# FIXME: Replace/resolve this before accepting BFD-2554
count = local.is_ephemeral_env ? 0 : 1

bucket = aws_s3_bucket.this.id
target_bucket = local.logging_bucket

# TODO: correct the target prefix by adding a trailing '/'
target_prefix = "${local.legacy_service}_s3_access_logs"
}

resource "aws_s3_bucket_acl" "this" {
# After April 2023, new S3 Buckets have public access disabled along with ACLs disabled. This
# resource will fail to apply for ephemeral environments
# FIXME: Replace/resolve this after accepting BFD-2554
count = local.is_ephemeral_env ? 0 : 1

bucket = aws_s3_bucket.this.id
acl = "private"
target_prefix = "${local.legacy_service}_s3_access_logs/"
}

resource "aws_s3_bucket_notification" "etl_bucket_notifications" {
Expand Down

0 comments on commit 8bf83b0

Please sign in to comment.