Skip to content

Commit 83e1fcb

Browse files
committed
Updated external write role with policies for audit copy
1 parent 3fe53ad commit 83e1fcb

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

infrastructure/stacks/api-layer/iam_policies.tf

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ data "aws_iam_policy_document" "s3_audit_kms_key_policy" {
341341
#checkov:skip=CKV_AWS_356: Root user needs full KMS key management
342342
#checkov:skip=CKV_AWS_109: Root user needs full KMS key management
343343

344+
# Allow root user to have full control
344345
statement {
345346
sid = "EnableIamUserPermissions"
346347
effect = "Allow"
@@ -351,12 +352,20 @@ data "aws_iam_policy_document" "s3_audit_kms_key_policy" {
351352
actions = ["kms:*"]
352353
resources = ["*"]
353354
}
355+
356+
# Allow Lambda, Firehose, and external write roles to use the KMS key
354357
statement {
355-
sid = "AllowLambdaFullWrite"
358+
sid = "AllowAuditKeyAccess"
356359
effect = "Allow"
357360
principals {
358361
type = "AWS"
359-
identifiers = [aws_iam_role.eligibility_lambda_role.arn, aws_iam_role.eligibility_audit_firehose_role.arn]
362+
identifiers = concat(
363+
[
364+
aws_iam_role.eligibility_lambda_role.arn,
365+
aws_iam_role.eligibility_audit_firehose_role.arn
366+
],
367+
aws_iam_role.write_access_role[*].arn
368+
)
360369
}
361370
actions = [
362371
"kms:Decrypt",
@@ -459,3 +468,40 @@ resource "aws_kms_key_policy" "sns_encryption_key_policy" {
459468
]
460469
})
461470
}
471+
472+
# Policy doc for external write role to read, move, and tag objects in S3
473+
data "aws_iam_policy_document" "external_s3_read_move_policy_doc" {
474+
statement {
475+
sid = "ListBucket"
476+
actions = [
477+
"s3:ListBucket",
478+
"s3:ListBucketVersions"
479+
]
480+
resources = [
481+
module.s3_audit_bucket.storage_bucket_arn
482+
]
483+
}
484+
485+
statement {
486+
sid = "ReadMoveTagObjects"
487+
actions = [
488+
"s3:GetObject",
489+
"s3:GetObjectVersion",
490+
"s3:GetObjectTagging",
491+
"s3:PutObjectTagging",
492+
"s3:DeleteObject",
493+
"s3:PutObject"
494+
]
495+
resources = [
496+
"${module.s3_audit_bucket.storage_bucket_arn}/*"
497+
]
498+
}
499+
}
500+
501+
# Attach external S3 read, move & tagging policy to external write role
502+
resource "aws_iam_role_policy" "external_s3_read_move_policy" {
503+
count = length(aws_iam_role.write_access_role)
504+
name = "S3ReadMoveTagAccess"
505+
role = aws_iam_role.write_access_role[count.index].id
506+
policy = data.aws_iam_policy_document.external_s3_read_move_policy_doc.json
507+
}

0 commit comments

Comments
 (0)