Skip to content

Commit

Permalink
restrict public access and add bucket encryption using cmk (#2525)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcmcand authored Jul 4, 2024
2 parents c42a104 + 18330c0 commit d9e8f20
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/_nebari/stages/infrastructure/template/aws/modules/s3/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
resource "aws_kms_key" "main" {
description = "KMS key for ${var.name}"
enable_key_rotation = true
}

resource "aws_s3_bucket" "main" {
bucket = var.name
acl = var.public ? "public-read" : "private"
Expand All @@ -11,3 +16,22 @@ resource "aws_s3_bucket" "main" {
Description = "S3 bucket for ${var.name}"
}, var.tags)
}

resource "aws_s3_bucket_server_side_encryption_configuration" "main" {
bucket = aws_s3_bucket.main.id

rule {
apply_server_side_encryption_by_default {
kms_master_key_id = aws_kms_key.main.arn
sse_algorithm = "aws:kms"
}
}
}

resource "aws_s3_bucket_public_access_block" "main" {
bucket = aws_s3_bucket.main.id
ignore_public_acls = true
block_public_acls = true
block_public_policy = true
restrict_public_buckets = true
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
resource "aws_kms_key" "tf-state-key" {
enable_key_rotation = true
}

resource "aws_s3_bucket" "terraform-state" {
bucket = "${var.name}-terraform-state"

Expand All @@ -16,6 +20,25 @@ resource "aws_s3_bucket" "terraform-state" {
}
}

resource "aws_s3_bucket_server_side_encryption_configuration" "terraform-state" {
bucket = aws_s3_bucket.terraform-state.id

rule {
apply_server_side_encryption_by_default {
kms_master_key_id = aws_kms_key.tf-state-key.arn
sse_algorithm = "aws:kms"
}
}
}

resource "aws_s3_bucket_public_access_block" "terraform-state" {
bucket = aws_s3_bucket.terraform-state.id
ignore_public_acls = true
block_public_acls = true
block_public_policy = true
restrict_public_buckets = true
}

resource "aws_dynamodb_table" "terraform-state-lock" {
name = "${var.name}-terraform-state-lock"

Expand Down

0 comments on commit d9e8f20

Please sign in to comment.