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

chore: disable SSE-KMS encryption in S3 #52

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions infrastructure/environments/dev/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions infrastructure/environments/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ module "core" {
module "glue" {
source = "../../modules/glue"

environment = var.environment
data_bucket_id = module.core.data_bucket_id
s3_encryption_key_arn = module.core.s3_encryption_key_arn
environment = var.environment
data_bucket_id = module.core.data_bucket_id
# =====================================================================================
# DELETE THIS AND UNCOMMENT THE FOLLOWING LINE TO ENABLE SSE-KMS ENCRYPTION IN S3.
# =====================================================================================
# s3_encryption_key_arn = module.core.s3_encryption_key_arn
glue_assets_bucket_name = var.glue_assets_bucket_name
glue_scripts_bucket_name = var.glue_scripts_bucket_name
}
Expand Down
9 changes: 6 additions & 3 deletions infrastructure/environments/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ module "core" {
module "glue" {
source = "../../modules/glue"

environment = var.environment
data_bucket_id = module.core.data_bucket_id
s3_encryption_key_arn = module.core.s3_encryption_key_arn
environment = var.environment
data_bucket_id = module.core.data_bucket_id
# =====================================================================================
# DELETE THIS AND UNCOMMENT THE FOLLOWING LINE TO ENABLE SSE-KMS ENCRYPTION IN S3.
# =====================================================================================
# s3_encryption_key_arn = module.core.s3_encryption_key_arn
glue_assets_bucket_name = var.glue_assets_bucket_name
glue_scripts_bucket_name = var.glue_scripts_bucket_name
}
Expand Down
9 changes: 6 additions & 3 deletions infrastructure/environments/qa/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ module "core" {
module "glue" {
source = "../../modules/glue"

environment = var.environment
data_bucket_id = module.core.data_bucket_id
s3_encryption_key_arn = module.core.s3_encryption_key_arn
environment = var.environment
data_bucket_id = module.core.data_bucket_id
# =====================================================================================
# DELETE THIS AND UNCOMMENT THE FOLLOWING LINE TO ENABLE SSE-KMS ENCRYPTION IN S3.
# =====================================================================================
# s3_encryption_key_arn = module.core.s3_encryption_key_arn
glue_assets_bucket_name = var.glue_assets_bucket_name
glue_scripts_bucket_name = var.glue_scripts_bucket_name
}
Expand Down
9 changes: 6 additions & 3 deletions infrastructure/environments/staging/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ module "core" {
module "glue" {
source = "../../modules/glue"

environment = var.environment
data_bucket_id = module.core.data_bucket_id
s3_encryption_key_arn = module.core.s3_encryption_key_arn
environment = var.environment
data_bucket_id = module.core.data_bucket_id
# =====================================================================================
# DELETE THIS AND UNCOMMENT THE FOLLOWING LINE TO ENABLE SSE-KMS ENCRYPTION IN S3.
# =====================================================================================
# s3_encryption_key_arn = module.core.s3_encryption_key_arn
glue_assets_bucket_name = var.glue_assets_bucket_name
glue_scripts_bucket_name = var.glue_scripts_bucket_name
}
Expand Down
23 changes: 14 additions & 9 deletions infrastructure/modules/core/kms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
# Service keys (SSE-KMS) instead. Please refer to
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingEncryption.html for further
# details.
resource "aws_kms_key" "s3" {
description = "This key protects S3 objects tackled by the AWS Glue CI/CD Blueprint"
enable_key_rotation = true
}

resource "aws_kms_alias" "s3" {
name = "alias/glue-ci-cd-blueprint/s3-${var.environment}"
target_key_id = aws_kms_key.s3.key_id
}
# =======================================================================================
# THE KMS KEY IS DISABLED BY DEFAULT TO AVOID EXTRA COSTS IN THE BLUEPRINT VALIDATION
# ACCOUNTS. DELETE THE LINES DELIMITED BY `# =...=` AND UNCOMMENT THE FOLLOWING RESOURCES
# TO CREATE/ENABLE THEM.
# =======================================================================================
# resource "aws_kms_key" "s3" {
# description = "This key protects S3 objects tackled by the AWS Glue CI/CD Blueprint"
# enable_key_rotation = true
# }
#
# resource "aws_kms_alias" "s3" {
# name = "alias/glue-ci-cd-blueprint/s3-${var.environment}"
# target_key_id = aws_kms_key.s3.key_id
# }
9 changes: 6 additions & 3 deletions infrastructure/modules/core/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ output "data_bucket_id" {
value = aws_s3_bucket.data.id
}

output "s3_encryption_key_arn" {
value = aws_kms_key.s3.arn
}
# =======================================================================================
# KMS KEY ARE DISABLED BY DEFAULT. PLEASE REFER TO `kms.tf` FOR DETAILS.
# =======================================================================================
# output "s3_encryption_key_arn" {
# value = aws_kms_key.s3.arn
# }
23 changes: 13 additions & 10 deletions infrastructure/modules/core/s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ resource "aws_s3_bucket" "data" {
bucket = "${var.data_bucket_name}-${var.environment}"
}

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

rule {
apply_server_side_encryption_by_default {
kms_master_key_id = aws_kms_key.s3.arn
sse_algorithm = "aws:kms"
}
}
}
# =======================================================================================
# KMS KEY ARE DISABLED BY DEFAULT. PLEASE REFER TO `kms.tf` FOR DETAILS.
# =======================================================================================
# resource "aws_s3_bucket_server_side_encryption_configuration" "data" {
# bucket = aws_s3_bucket.data.id
#
# rule {
# apply_server_side_encryption_by_default {
# kms_master_key_id = aws_kms_key.s3.arn
# sse_algorithm = "aws:kms"
# }
# }
# }
23 changes: 13 additions & 10 deletions infrastructure/modules/glue/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ data "aws_s3_bucket" "data" {
}

data "aws_iam_policy_document" "glue_service_custom" {
statement {
effect = "Allow"
actions = [
"kms:Decrypt",
"kms:GenerateDataKey"
]
resources = [
var.s3_encryption_key_arn
]
}
# =====================================================================================
# DELETE THIS AND UNCOMMENT THE FOLLOWING STATEMENT TO ENABLE SSE-KMS ENCRYPTION IN S3.
# =====================================================================================
# statement {
# effect = "Allow"
# actions = [
# "kms:Decrypt",
# "kms:GenerateDataKey"
# ]
# resources = [
# var.s3_encryption_key_arn
# ]
# }
statement {
effect = "Allow"
actions = [
Expand Down
13 changes: 8 additions & 5 deletions infrastructure/modules/glue/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ variable "data_bucket_id" {
default = ""
}

variable "s3_encryption_key_arn" {
description = "ARN of the key that protects S3 objects tackled by the AWS Glue CI/CD Blueprint."
type = string
default = ""
}
# =======================================================================================
# DELETE THIS AND UNCOMMENT THE FOLLOWING VARIABLE TO ENABLE SSE-KMS ENCRYPTION IN S3.
# =======================================================================================
# variable "s3_encryption_key_arn" {
# description = "ARN of the key that protects S3 objects tackled by the AWS Glue CI/CD Blueprint."
# type = string
# default = ""
# }

variable "glue_assets_bucket_name" {
description = "Name of the S3 bucket used to store AWS Glue assets."
Expand Down
Loading