Skip to content

Commit

Permalink
allow permissions on kms key
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-whitwell committed Jan 7, 2025
1 parent 8fad946 commit e6fe538
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
46 changes: 46 additions & 0 deletions terraform/account/kms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module "event_receiver_mrk" {

key_description = "KMS key for received events"
key_alias = "${local.environment}-event-receiver-mrk"
key_policy = data.aws_iam_policy_document.event_receiver_kms.json
deletion_window_in_days = 7

providers = {
Expand Down Expand Up @@ -146,3 +147,48 @@ data "aws_iam_policy_document" "cloudwatch_kms" {
}
}
}

data "aws_iam_policy_document" "event_receiver_kms" {
statement {
sid = "Allow Encryption by Service"
effect = "Allow"
resources = [
"arn:aws:kms:*:${data.aws_caller_identity.current.account_id}:key/*"
]
actions = [
"kms:Encrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey",
]

principals {
type = "Service"
identifiers = [
"events.amazonaws.com",
]
}
}

statement {
sid = "Allow Decryption by Service"
effect = "Allow"
resources = [
"arn:aws:kms:*:${data.aws_caller_identity.current.account_id}:key/*"
]
actions = [
"kms:Decrypt",
"kms:GenerateDataKey*",
"kms:DescribeKey",
]

principals {
type = "Service"
identifiers = [
"sqs.amazonaws.com",
"events.amazonaws.com",
"lambda.amazonaws.com",
]
}
}
}
4 changes: 4 additions & 0 deletions terraform/environment/region/modules/event_bus/kms.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "aws_kms_alias" "event_receiver_mrk" {
name = "alias/${var.environment_name}-event-receiver-mrk"
provider = aws.region
}
9 changes: 2 additions & 7 deletions terraform/environment/region/modules/event_bus/sqs.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
data "aws_kms_alias" "sqs" {
name = "alias/sqs-mrk"
provider = aws.region
}

resource "aws_sqs_queue" "receive_events_queue" {
count = var.event_bus_enabled ? 1 : 0
name = "${var.environment_name}-receive-events-queue"
kms_master_key_id = data.aws_kms_alias.sqs.target_key_id
kms_master_key_id = data.aws_kms_alias.event_receiver_mrk.target_key_id
kms_data_key_reuse_period_seconds = 300

visibility_timeout_seconds = var.queue_visibility_timeout
Expand All @@ -30,7 +25,7 @@ resource "aws_sqs_queue_policy" "receive_events_queue_policy" {
resource "aws_sqs_queue" "receive_events_deadletter" {
count = var.event_bus_enabled ? 1 : 0
name = "${var.environment_name}-receive-events-deadletter"
kms_master_key_id = data.aws_kms_alias.sqs.target_key_id
kms_master_key_id = data.aws_kms_alias.event_receiver_mrk.target_key_id
kms_data_key_reuse_period_seconds = 300
provider = aws.region
}
Expand Down

0 comments on commit e6fe538

Please sign in to comment.