Skip to content

Commit af51199

Browse files
authored
VED-901: Add dps kms key on filenameproc lambda (#1068)
* add kms permission unto filenameprocessor lambda
1 parent 3d75e49 commit af51199

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

infrastructure/instance/environments/prod/blue/variables.tfvars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pds_environment = "prod"
55
batch_error_notifications_enabled = true
66
create_mesh_processor = true
77
has_sub_environment_scope = false
8+
dspp_kms_key_alias = "nhsd-dspp-core-prod-extended-attributes-gdp-key"

infrastructure/instance/environments/prod/green/variables.tfvars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pds_environment = "prod"
55
batch_error_notifications_enabled = true
66
create_mesh_processor = true
77
has_sub_environment_scope = false
8+
dspp_kms_key_alias = "nhsd-dspp-core-prod-extended-attributes-gdp-key"

infrastructure/instance/file_name_processor.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,44 @@ resource "aws_iam_policy" "filenameprocessor_dynamo_access_policy" {
253253
})
254254
}
255255

256+
# Kms policy setup on filenameprocessor lambda for dps cross account bucket access
257+
resource "aws_iam_policy" "filenameprocessor_dps_extended_attribute_kms_policy" {
258+
name = "${local.short_prefix}-filenameproc-dps-kms-policy"
259+
description = "Allow Lambda to use DPS KMS key for SSE-KMS encrypted S3 bucket access"
260+
261+
policy = jsonencode({
262+
Version = "2012-10-17"
263+
Statement = [
264+
{
265+
Effect = "Allow",
266+
Action = [
267+
"kms:Decrypt",
268+
"kms:GenerateDataKey",
269+
"kms:DescribeKey"
270+
],
271+
Resource = "arn:aws:kms:eu-west-2:${var.dspp_core_account_id}:key/*",
272+
"Condition" = {
273+
"ForAnyValue:StringEquals" = {
274+
"kms:ResourceAliases" = "alias/${var.dspp_kms_key_alias}"
275+
}
276+
}
277+
}
278+
]
279+
})
280+
}
256281

257282
# Attach the execution policy to the Lambda role
258283
resource "aws_iam_role_policy_attachment" "filenameprocessor_lambda_exec_policy_attachment" {
259284
role = aws_iam_role.filenameprocessor_lambda_exec_role.name
260285
policy_arn = aws_iam_policy.filenameprocessor_lambda_exec_policy.arn
261286
}
262287

288+
#Attach the dps kms policy to the Lambda role
289+
resource "aws_iam_role_policy_attachment" "filenameprocessor_lambda_dps_kms_ea_policy_attachment" {
290+
role = aws_iam_role.filenameprocessor_lambda_exec_role.name
291+
policy_arn = aws_iam_policy.filenameprocessor_dps_extended_attribute_kms_policy.arn
292+
}
293+
263294
# Attach the SQS policy to the Lambda role
264295
resource "aws_iam_role_policy_attachment" "filenameprocessor_lambda_sqs_policy_attachment" {
265296
role = aws_iam_role.filenameprocessor_lambda_exec_role.name

infrastructure/instance/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ variable "csoc_account_id" {
1010
default = "693466633220"
1111
}
1212

13+
variable "dspp_kms_key_alias" {
14+
description = "Alias name of the DPS KMS key allowed for SSE-KMS encryption"
15+
type = string
16+
default = "nhsd-dspp-core-ref-extended-attributes-gdp-key"
17+
}
18+
1319
variable "create_mesh_processor" {
1420
default = false
1521
}

0 commit comments

Comments
 (0)