@@ -561,3 +561,101 @@ resource "aws_iam_role_policy" "external_secret_read_policy_attachment" {
561561 role = aws_iam_role. write_access_role [count . index ]. id
562562 policy = data. aws_iam_policy_document . secrets_access_policy . json
563563}
564+
565+ # --- Rotation Logic Policies ---
566+ resource "aws_iam_policy" "rotation_secrets_policy" {
567+ name = " rotation_secrets_policy"
568+ description = " Allow Lambda to read/write ONLY the hashing secret"
569+ policy = jsonencode ({
570+ Version = " 2012-10-17" ,
571+ Statement = [
572+ {
573+ Sid = " ManageSecretBits" ,
574+ Effect = " Allow" ,
575+ Action = [
576+ " secretsmanager:DescribeSecret" ,
577+ " secretsmanager:PutSecretValue" ,
578+ " secretsmanager:UpdateSecretVersionStage" ,
579+ " secretsmanager:GetSecretValue"
580+ ],
581+ Resource = module.secrets_manager.aws_hashing_secret_arn
582+ },
583+ {
584+ Sid = " AllowKMSKeyUsage" ,
585+ Effect = " Allow" ,
586+ Action = [
587+ " kms:Decrypt" ,
588+ " kms:GenerateDataKey"
589+ ],
590+ Resource = module.secrets_manager.kms_key_arn
591+ },
592+ {
593+ Sid = " BasicLogging" ,
594+ Effect = " Allow" ,
595+ Action = [
596+ " logs:CreateLogGroup" ,
597+ " logs:CreateLogStream" ,
598+ " logs:PutLogEvents"
599+ ],
600+ Resource = [
601+ " arn:aws:logs:${ var . default_aws_region } :${ data . aws_caller_identity . current . account_id } :log-group:/aws/lambda/${ aws_lambda_function . create_secret_lambda . function_name } :*" ,
602+ " arn:aws:logs:${ var . default_aws_region } :${ data . aws_caller_identity . current . account_id } :log-group:/aws/lambda/${ aws_lambda_function . promote_secret_lambda . function_name } :*"
603+ ]
604+ }
605+ ]
606+ })
607+ }
608+
609+ resource "aws_iam_role_policy_attachment" "attach_rotation_secrets" {
610+ role = aws_iam_role. rotation_lambda_role . name
611+ policy_arn = aws_iam_policy. rotation_secrets_policy . arn
612+ }
613+
614+ resource "aws_iam_policy" "rotation_sfn_policy" {
615+ name = " rotation_sfn_policy"
616+ policy = jsonencode ({
617+ Version = " 2012-10-17" ,
618+ Statement = [
619+ {
620+ Effect = " Allow" ,
621+ Action = " lambda:InvokeFunction" ,
622+ Resource = [
623+ aws_lambda_function.create_secret_lambda.arn,
624+ aws_lambda_function.promote_secret_lambda.arn
625+ ]
626+ },
627+ {
628+ Effect = " Allow" ,
629+ Action = " sns:Publish" ,
630+ Resource = aws_sns_topic.secret_rotation.arn
631+ },
632+ {
633+ Effect = " Allow" ,
634+ Action = [
635+ " kms:Decrypt" ,
636+ " kms:GenerateDataKey"
637+ ],
638+ Resource = module.secrets_manager.rotation_sns_key_arn
639+ },
640+ {
641+ Effect = " Allow" ,
642+ Action = [
643+ " logs:CreateLogDelivery" ,
644+ " logs:GetLogDelivery" ,
645+ " logs:UpdateLogDelivery" ,
646+ " logs:DeleteLogDelivery" ,
647+ " logs:ListLogDeliveries" ,
648+ " logs:PutResourcePolicy" ,
649+ " logs:DescribeResourcePolicies" ,
650+ " logs:DescribeLogGroups"
651+ ],
652+ Resource = " *"
653+ }
654+ ]
655+ })
656+ }
657+
658+ resource "aws_iam_role_policy_attachment" "attach_rotation_sfn" {
659+ role = aws_iam_role. rotation_sfn_role . name
660+ policy_arn = aws_iam_policy. rotation_sfn_policy . arn
661+ }
0 commit comments