Skip to content

Commit a4c380f

Browse files
authored
Merge pull request #176 from NHSDigital/bugfix/eja-eli-306-adding-kms-decrypt-for-lambda-rules-bucket
Bugfix/eja eli 306 adding kms decrypt for lambda rules bucket
2 parents 7d3bbec + 40920df commit a4c380f

1 file changed

Lines changed: 72 additions & 32 deletions

File tree

infrastructure/stacks/api-layer/iam_policies.tf

Lines changed: 72 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ resource "aws_iam_role_policy" "external_s3_write_policy" {
127127
}
128128

129129
## KMS
130-
data "aws_iam_policy_document" "kms_key_policy" {
130+
data "aws_iam_policy_document" "dynamodb_kms_key_policy" {
131+
#checkov:skip=CKV_AWS_111: Root user needs full KMS key management
132+
#checkov:skip=CKV_AWS_356: Root user needs full KMS key management
133+
#checkov:skip=CKV_AWS_109: Root user needs full KMS key management
131134
statement {
132135
sid = "EnableIamUserPermissions"
133136
effect = "Allow"
@@ -136,55 +139,92 @@ data "aws_iam_policy_document" "kms_key_policy" {
136139
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
137140
}
138141
actions = ["kms:*"]
139-
resources = [
140-
module.eligibility_status_table.dynamodb_kms_key_arn,
141-
module.s3_rules_bucket.storage_bucket_kms_key_arn,
142-
module.s3_audit_bucket.storage_bucket_kms_key_arn,
143-
module.eligibility_signposting_api_gateway.kms_key_arn,
142+
resources = ["*"]
143+
}
144144

145-
]
145+
statement {
146+
sid = "AllowLambdaDecrypt"
147+
effect = "Allow"
148+
principals {
149+
type = "AWS"
150+
identifiers = [aws_iam_role.eligibility_lambda_role.arn]
151+
}
152+
actions = ["kms:Decrypt"]
153+
resources = ["*"]
146154
}
155+
}
156+
157+
resource "aws_kms_key_policy" "dynamodb_kms_key" {
158+
key_id = module.eligibility_status_table.dynamodb_kms_key_id
159+
policy = data.aws_iam_policy_document.dynamodb_kms_key_policy.json
160+
}
161+
162+
data "aws_iam_policy_document" "s3_rules_kms_key_policy" {
163+
#checkov:skip=CKV_AWS_111: Root user needs full KMS key management
164+
#checkov:skip=CKV_AWS_356: Root user needs full KMS key management
165+
#checkov:skip=CKV_AWS_109: Root user needs full KMS key management
147166
statement {
148-
sid = "Allow lambda decrypt role"
167+
sid = "EnableIamUserPermissions"
149168
effect = "Allow"
150169
principals {
151-
type = "AWS"
152-
identifiers = [
153-
aws_iam_role.eligibility_lambda_role.arn
154-
]
170+
type = "AWS"
171+
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
155172
}
156-
actions = [
157-
"kms:Decrypt"
158-
]
159-
resources = [
160-
module.eligibility_status_table.dynamodb_kms_key_arn,
161-
module.s3_rules_bucket.storage_bucket_kms_key_arn,
162-
]
173+
actions = ["kms:*"]
174+
resources = ["*"]
163175
}
164176

165177
statement {
166-
sid = "Allow lambda full write role"
178+
sid = "AllowLambdaDecrypt"
167179
effect = "Allow"
168180
principals {
169-
type = "AWS"
170-
identifiers = [
171-
aws_iam_role.eligibility_lambda_role.arn
172-
]
181+
type = "AWS"
182+
identifiers = [aws_iam_role.eligibility_lambda_role.arn]
173183
}
174-
actions = [
184+
actions = ["kms:Decrypt"]
185+
resources = ["*"]
186+
}
187+
}
188+
189+
resource "aws_kms_key_policy" "s3_rules_kms_key" {
190+
key_id = module.s3_rules_bucket.storage_bucket_kms_key_arn
191+
policy = data.aws_iam_policy_document.s3_rules_kms_key_policy.json
192+
}
193+
194+
data "aws_iam_policy_document" "s3_audit_kms_key_policy" {
195+
#checkov:skip=CKV_AWS_111: Root user needs full KMS key management
196+
#checkov:skip=CKV_AWS_356: Root user needs full KMS key management
197+
#checkov:skip=CKV_AWS_109: Root user needs full KMS key management
198+
199+
statement {
200+
sid = "EnableIamUserPermissions"
201+
effect = "Allow"
202+
principals {
203+
type = "AWS"
204+
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
205+
}
206+
actions = ["kms:*"]
207+
resources = ["*"]
208+
}
209+
210+
statement {
211+
sid = "AllowLambdaFullWrite"
212+
effect = "Allow"
213+
principals {
214+
type = "AWS"
215+
identifiers = [aws_iam_role.eligibility_lambda_role.arn]
216+
}
217+
actions = [
175218
"kms:Decrypt",
176219
"kms:Encrypt",
177220
"kms:GenerateDataKey",
178221
"kms:DescribeKey"
179222
]
180-
resources = [
181-
module.s3_audit_bucket.storage_bucket_kms_key_arn
182-
]
223+
resources = ["*"]
183224
}
184225
}
185226

186-
# attach kms decrypt policy kms key
187-
resource "aws_kms_key_policy" "kms_key" {
188-
key_id = module.eligibility_status_table.dynamodb_kms_key_id
189-
policy = data.aws_iam_policy_document.kms_key_policy.json
227+
resource "aws_kms_key_policy" "s3_audit_kms_key" {
228+
key_id = module.s3_audit_bucket.storage_bucket_kms_key_arn
229+
policy = data.aws_iam_policy_document.s3_audit_kms_key_policy.json
190230
}

0 commit comments

Comments
 (0)