@@ -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,39 @@ 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:PutObject"
493+ ]
494+ resources = [
495+ " ${ module . s3_audit_bucket . storage_bucket_arn } /*"
496+ ]
497+ }
498+ }
499+
500+ # Attach external S3 read, move & tagging policy to external write role
501+ resource "aws_iam_role_policy" "external_s3_read_move_policy" {
502+ count = length (aws_iam_role. write_access_role )
503+ name = " S3ReadMoveTagAccess"
504+ role = aws_iam_role. write_access_role [count . index ]. id
505+ policy = data. aws_iam_policy_document . external_s3_read_move_policy_doc . json
506+ }
0 commit comments