Skip to content

Commit ddbfb9e

Browse files
committed
fix(webhook): grant KMS permission to decrypt wehn using EventBridge
1 parent 9c9219b commit ddbfb9e

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

modules/webhook/direct/webhook.tf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,15 @@ resource "aws_iam_role_policy" "webhook_sqs" {
117117

118118
policy = templatefile("${path.module}/../policies/lambda-publish-sqs-policy.json", {
119119
sqs_resource_arns = jsonencode(var.config.sqs_job_queues_arns)
120-
kms_key_arn = var.config.kms_key_arn != null ? var.config.kms_key_arn : ""
120+
})
121+
}
122+
123+
resource "aws_iam_role_policy" "webhook_kms" {
124+
name = "kms-policy"
125+
role = aws_iam_role.webhook_lambda.name
126+
127+
policy = templatefile("${path.module}/../policies/lambda-kms.json", {
128+
kms_key_arn = var.config.kms_key_arn != null ? var.config.kms_key_arn : "arn:${var.config.aws_partition}:kms:::CMK_NOT_IN_USE"
121129
})
122130
}
123131

@@ -128,7 +136,6 @@ resource "aws_iam_role_policy" "webhook_workflow_job_sqs" {
128136

129137
policy = templatefile("${path.module}/../policies/lambda-publish-sqs-policy.json", {
130138
sqs_resource_arns = jsonencode([var.config.sqs_workflow_job_queue.arn])
131-
kms_key_arn = var.config.kms_key_arn != null ? var.config.kms_key_arn : ""
132139
})
133140
}
134141

modules/webhook/eventbridge/dispatcher.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,15 @@ resource "aws_iam_role_policy" "dispatcher_sqs" {
116116

117117
policy = templatefile("${path.module}/../policies/lambda-publish-sqs-policy.json", {
118118
sqs_resource_arns = jsonencode(var.config.sqs_job_queues_arns)
119-
kms_key_arn = var.config.kms_key_arn != null ? var.config.kms_key_arn : ""
119+
})
120+
}
121+
122+
resource "aws_iam_role_policy" "dispatcher_kms" {
123+
name = "kms-policy"
124+
role = aws_iam_role.webhook_lambda.name
125+
126+
policy = templatefile("${path.module}/../policies/lambda-kms.json", {
127+
kms_key_arn = var.config.kms_key_arn != null ? var.config.kms_key_arn : "arn:${var.config.aws_partition}:kms:::CMK_NOT_IN_USE"
120128
})
121129
}
122130

modules/webhook/eventbridge/webhook.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ resource "aws_iam_role_policy" "webhook_ssm" {
127127
})
128128
}
129129

130+
resource "aws_iam_role_policy" "webhook_kms" {
131+
name = "kms-policy"
132+
role = aws_iam_role.webhook_lambda.name
133+
134+
policy = templatefile("${path.module}/../policies/lambda-kms.json", {
135+
kms_key_arn = var.config.kms_key_arn != null ? var.config.kms_key_arn : "arn:${var.config.aws_partition}:kms:::CMK_NOT_IN_USE"
136+
})
137+
}
138+
130139
resource "aws_iam_role_policy" "xray" {
131140
count = var.config.tracing_config.mode != null ? 1 : 0
132141
name = "xray-policy"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Effect": "Allow",
6+
"Action": [
7+
"kms:Decrypt",
8+
"kms:GenerateDataKey"
9+
],
10+
"Resource": "${kms_key_arn}"
11+
}
12+
]
13+
}

modules/webhook/policies/lambda-publish-sqs-policy.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@
55
"Effect": "Allow",
66
"Action": ["sqs:SendMessage", "sqs:GetQueueAttributes"],
77
"Resource": ${sqs_resource_arns}
8-
%{ if kms_key_arn != "" ~}
9-
},
10-
{
11-
"Effect": "Allow",
12-
"Action": [
13-
"kms:Decrypt",
14-
"kms:GenerateDataKey"
15-
],
16-
"Resource": "${kms_key_arn}"
17-
%{ endif ~}
188
}
199
]
2010
}

0 commit comments

Comments
 (0)