Skip to content

Commit 784af81

Browse files
give lambda role to decrypt kms key
1 parent 090b65a commit 784af81

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

infrastructure/modules/dynamodb/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@ output "arn" {
55
output "table_name" {
66
value = aws_dynamodb_table.dynamodb_table.name
77
}
8+
9+
output "dynamodb_kms_key_arn" {
10+
value = aws_kms_key.dynamodb_cmk.arn
11+
}
12+
13+
output "dynamodb_kms_key_id" {
14+
value = aws_kms_key.dynamodb_cmk.id
15+
}
16+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
output "aws_lambda_function_id" {
22
value = aws_lambda_function.eligibility_signposting_lambda.id
33
}
4+
output "aws_lambda_function_arn" {
5+
value = aws_lambda_function.eligibility_signposting_lambda.arn
6+
}

infrastructure/stacks/api-layer/iam_policies.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,40 @@ resource "aws_iam_role_policy" "external_s3_write_policy" {
125125
policy = data.aws_iam_policy_document.s3_audit_bucket_policy.json
126126
}
127127

128+
## KMS
129+
data "aws_iam_policy_document" "kms_key_policy" {
130+
statement {
131+
sid = "EnableIamUserPermissions"
132+
effect = "Allow"
133+
principals {
134+
type = "AWS"
135+
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
136+
}
137+
actions = ["kms:*"]
138+
resources = ["*"]
139+
}
140+
statement {
141+
sid = "Allow lambda role"
142+
effect = "Allow"
143+
principals {
144+
type = "AWS"
145+
identifiers = [
146+
aws_iam_role.eligibility_lambda_role.arn
147+
]
148+
}
149+
actions = [
150+
"kms:Decrypt"
151+
]
152+
resources = [
153+
module.eligibility_status_table.dynamodb_kms_key_arn
154+
]
155+
}
156+
}
157+
158+
# attach kms decrypt policy kms key
159+
resource "aws_kms_key_policy" "kms_key" {
160+
key_id = module.eligibility_status_table.dynamodb_kms_key_id
161+
policy = data.aws_iam_policy_document.kms_key_policy.json
162+
}
163+
128164

0 commit comments

Comments
 (0)