Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Update "assetstore" module to use S3 bucket ownership controls #41

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
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
35 changes: 23 additions & 12 deletions modules/assetstore/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,30 @@ resource "aws_s3_bucket" "assetstore" {
bucket = var.bucket_name
}

resource "aws_s3_bucket_acl" "assetstore" {
resource "aws_s3_bucket_ownership_controls" "assetstore" {
bucket = aws_s3_bucket.assetstore.id
acl = "private"
rule {
# Disable all ACLs, as they are discouraged for typical use cases
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html
object_ownership = "BucketOwnerEnforced"
}
}

# Don't use an aws_s3_bucket_acl resource. Attempting any ACL operation on a bucket with
# "BucketOwnerEnforced" ownership controls (which is the default for new buckets) will fail.
# If importing old buckets, a public canned ACL policy might need to be manually disabled before
# applying "BucketOwnerEnforced" ownership controls will succeed.

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

block_public_policy = true
# restrict_public_buckets also blocks cross-account access to the bucket
restrict_public_buckets = true
# ACLs are already disabled via "aws_s3_bucket_ownership_controls", but many audit tools prefer
# these settings too
block_public_acls = true
ignore_public_acls = true
}

resource "aws_s3_bucket_cors_configuration" "assetstore" {
Expand Down Expand Up @@ -106,13 +127,3 @@ data "aws_iam_policy_document" "assetstore" {
}
}
}

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

block_public_acls = true
block_public_policy = true
ignore_public_acls = true
# restrict_public_buckets also blocks cross-account access to the bucket
restrict_public_buckets = true
}