Skip to content

Commit bf32f5e

Browse files
committed
CCM-13611: Allow access to Core PDF pipeline bucket for getletterdata lambda
1 parent 313bff3 commit bf32f5e

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

infrastructure/terraform/components/api/locals.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ locals {
2828
APIM_CORRELATION_HEADER = "nhsd-correlation-id",
2929
DOWNLOAD_URL_TTL_SECONDS = 60
3030
}
31+
32+
core_pdf_bucket_arn = "arn:aws:s3:::comms-${var.core_account_id}-eu-west-2-${var.core_environment}-api-stg-pdf-pipeline"
33+
core_s3_kms_key_alias_name = "alias/comms-${var.core_environment}-api-s3"
3134
}

infrastructure/terraform/components/api/module_lambda_get_letter_data.tf

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,43 @@ data "aws_iam_policy_document" "get_letter_data_lambda" {
6868
]
6969
}
7070

71+
statement {
72+
sid = "S3ListBucketForPresign"
73+
actions = [
74+
"s3:ListBucket"
75+
]
76+
resources = [
77+
module.s3bucket_test_letters.arn,
78+
local.core_pdf_bucket_arn
79+
]
80+
}
81+
7182
statement {
7283
sid = "S3GetObjectForPresign"
7384
actions = [
7485
"s3:GetObject",
75-
"s3:ListBucket"] # allows 404 response instead of 403 if object missing
76-
resources = ["${module.s3bucket_test_letters.arn}/*"]
86+
"s3:PutObject",
87+
] # allows 404 response instead of 403 if object missing
88+
resources = [
89+
"${module.s3bucket_test_letters.arn}/*",
90+
"${local.core_pdf_bucket_arn}/*",
91+
]
92+
}
93+
94+
statement {
95+
sid = "KMSForCoreS3Access"
96+
actions = [
97+
"kms:Decrypt",
98+
"kms:GenerateDataKey",
99+
"kms:DescribeKey"
100+
]
101+
resources = [
102+
"arn:aws:kms:${var.region}:${var.core_account_id}:key/*"
103+
]
104+
condition {
105+
test = "ForAnyValue:StringEquals"
106+
variable = "kms:ResourceAliases"
107+
values = [local.core_s3_kms_key_alias_name]
108+
}
77109
}
78110
}

infrastructure/terraform/components/api/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,15 @@ variable "eventpub_control_plane_bus_arn" {
134134
description = "ARN of the EventBridge control plane bus for eventpub"
135135
default = ""
136136
}
137+
138+
variable "core_account_id" {
139+
type = string
140+
description = "AWS Account ID for Core"
141+
default = "000000000000"
142+
}
143+
144+
variable "core_environment" {
145+
type = string
146+
description = "Environment of Core"
147+
default = "prod"
148+
}

0 commit comments

Comments
 (0)