Skip to content

Commit

Permalink
Merge pull request #85 from kitware-resonant/acls
Browse files Browse the repository at this point in the history
Disable S3 bucket ACLs
  • Loading branch information
brianhelba authored Nov 21, 2024
2 parents 982004b + a8fd436 commit b2ed6ce
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions modules/storage/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,32 @@ resource "aws_s3_bucket" "storage" {
bucket = var.bucket_name
}

resource "aws_s3_bucket_ownership_controls" "storage" {
bucket = aws_s3_bucket.storage.id
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"
}
}

resource "aws_s3_bucket_acl" "storage" {
bucket = aws_s3_bucket.storage.id
acl = "private"
# This is the default for new buckets, but any other value prevents "BucketOwnerEnforced"
# ownership controls
acl = "private"
}

resource "aws_s3_bucket_public_access_block" "storage" {
bucket = aws_s3_bucket.storage.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" "storage" {
Expand Down Expand Up @@ -125,13 +148,3 @@ data "aws_iam_policy_document" "storage_django" {
]
}
}

resource "aws_s3_bucket_public_access_block" "storage" {
bucket = aws_s3_bucket.storage.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
}

0 comments on commit b2ed6ce

Please sign in to comment.