@@ -473,21 +473,12 @@ resource "aws_kms_key" "auth_code_store_signing_key" {
473
473
key_usage = " ENCRYPT_DECRYPT"
474
474
customer_master_key_spec = " SYMMETRIC_DEFAULT"
475
475
enable_key_rotation = true
476
- policy = jsonencode ({
477
- Version = " 2012-10-17"
478
- Id = " key-policy-dynamodb" ,
479
- Statement = [
480
- {
481
- Sid = " Allow IAM to manage this key" ,
482
- Effect = " Allow" ,
483
- Principal = { AWS = " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" }
484
- Action = [
485
- " kms:*"
486
- ],
487
- Resource = " *"
488
- }
489
- ]
490
- })
476
+ policy = data. aws_iam_policy_document . auth_dynamo_table_encryption_key_access_policy . json
477
+ }
478
+
479
+ resource "aws_kms_alias" "auth_code_store_signing_key_alias" {
480
+ name = " alias/${ var . environment } -auth-code-store-table-encryption-key"
481
+ target_key_id = aws_kms_key. auth_code_store_signing_key . key_id
491
482
}
492
483
493
484
# Authorization Token endpoint Signing KMS key
@@ -510,21 +501,12 @@ resource "aws_kms_key" "access_token_store_signing_key" {
510
501
key_usage = " ENCRYPT_DECRYPT"
511
502
customer_master_key_spec = " SYMMETRIC_DEFAULT"
512
503
enable_key_rotation = true
513
- policy = jsonencode ({
514
- Version = " 2012-10-17"
515
- Id = " key-policy-dynamodb" ,
516
- Statement = [
517
- {
518
- Sid = " Allow IAM to manage this key" ,
519
- Effect = " Allow" ,
520
- Principal = { AWS = " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" }
521
- Action = [
522
- " kms:*"
523
- ],
524
- Resource = " *"
525
- }
526
- ]
527
- })
504
+ policy = data. aws_iam_policy_document . auth_dynamo_table_encryption_key_access_policy . json
505
+ }
506
+
507
+ resource "aws_kms_alias" "access_token_store_signing_key_alias" {
508
+ name = " alias/${ var . environment } -access-token-store-table-encryption-key"
509
+ target_key_id = aws_kms_key. access_token_store_signing_key . key_id
528
510
}
529
511
530
512
resource "aws_kms_key" "bulk_email_users_encryption_key" {
@@ -533,21 +515,12 @@ resource "aws_kms_key" "bulk_email_users_encryption_key" {
533
515
key_usage = " ENCRYPT_DECRYPT"
534
516
customer_master_key_spec = " SYMMETRIC_DEFAULT"
535
517
enable_key_rotation = true
536
- policy = jsonencode ({
537
- Version = " 2012-10-17"
538
- Id = " key-policy-dynamodb" ,
539
- Statement = [
540
- {
541
- Sid = " Allow IAM to manage this key" ,
542
- Effect = " Allow" ,
543
- Principal = { AWS = " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" }
544
- Action = [
545
- " kms:*"
546
- ],
547
- Resource = " *"
548
- }
549
- ]
550
- })
518
+ policy = data. aws_iam_policy_document . auth_dynamo_table_encryption_key_access_policy . json
519
+ }
520
+
521
+ resource "aws_kms_alias" "bulk_email_users_encryption_key_alias" {
522
+ name = " alias/${ var . environment } -bulk-email-users-table-encryption-key"
523
+ target_key_id = aws_kms_key. bulk_email_users_encryption_key . key_id
551
524
}
552
525
553
526
resource "aws_kms_key" "account_modifiers_table_encryption_key" {
@@ -556,21 +529,12 @@ resource "aws_kms_key" "account_modifiers_table_encryption_key" {
556
529
key_usage = " ENCRYPT_DECRYPT"
557
530
customer_master_key_spec = " SYMMETRIC_DEFAULT"
558
531
enable_key_rotation = true
559
- policy = jsonencode ({
560
- Version = " 2012-10-17"
561
- Id = " key-policy-dynamodb" ,
562
- Statement = [
563
- {
564
- Sid = " Allow IAM to manage this key" ,
565
- Effect = " Allow" ,
566
- Principal = { AWS = " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" }
567
- Action = [
568
- " kms:*"
569
- ],
570
- Resource = " *"
571
- }
572
- ]
573
- })
532
+ policy = data. aws_iam_policy_document . auth_dynamo_table_encryption_key_access_policy . json
533
+ }
534
+
535
+ resource "aws_kms_alias" "account_modifiers_table_encryption_key_alias" {
536
+ name = " alias/${ var . environment } -account-modifiers-table-encryption-key"
537
+ target_key_id = aws_kms_key. account_modifiers_table_encryption_key . key_id
574
538
}
575
539
576
540
resource "aws_kms_key" "user_credentials_table_encryption_key" {
@@ -579,21 +543,12 @@ resource "aws_kms_key" "user_credentials_table_encryption_key" {
579
543
key_usage = " ENCRYPT_DECRYPT"
580
544
customer_master_key_spec = " SYMMETRIC_DEFAULT"
581
545
enable_key_rotation = true
582
- policy = jsonencode ({
583
- Version = " 2012-10-17"
584
- Id = " key-policy-dynamodb" ,
585
- Statement = [
586
- {
587
- Sid = " Allow IAM to manage this key" ,
588
- Effect = " Allow" ,
589
- Principal = { AWS = " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" }
590
- Action = [
591
- " kms:*"
592
- ],
593
- Resource = " *"
594
- }
595
- ]
596
- })
546
+ policy = data. aws_iam_policy_document . auth_dynamo_table_encryption_key_access_policy . json
547
+ }
548
+
549
+ resource "aws_kms_alias" "user_credentials_table_encryption_key_alias" {
550
+ name = " alias/${ var . environment } -user-credentials-table-encryption-key"
551
+ target_key_id = aws_kms_key. user_credentials_table_encryption_key . key_id
597
552
}
598
553
599
554
resource "aws_kms_key" "common_passwords_table_encryption_key" {
@@ -602,21 +557,12 @@ resource "aws_kms_key" "common_passwords_table_encryption_key" {
602
557
key_usage = " ENCRYPT_DECRYPT"
603
558
customer_master_key_spec = " SYMMETRIC_DEFAULT"
604
559
enable_key_rotation = true
605
- policy = jsonencode ({
606
- Version = " 2012-10-17"
607
- Id = " key-policy-dynamodb" ,
608
- Statement = [
609
- {
610
- Sid = " Allow IAM to manage this key" ,
611
- Effect = " Allow" ,
612
- Principal = { AWS = " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" }
613
- Action = [
614
- " kms:*"
615
- ],
616
- Resource = " *"
617
- }
618
- ]
619
- })
560
+ policy = data. aws_iam_policy_document . auth_dynamo_table_encryption_key_access_policy . json
561
+ }
562
+
563
+ resource "aws_kms_alias" "common_passwords_table_encryption_key_alias" {
564
+ name = " alias/${ var . environment } -common-passwords-table-encryption-key"
565
+ target_key_id = aws_kms_key. common_passwords_table_encryption_key . key_id
620
566
}
621
567
622
568
resource "aws_kms_key" "doc_app_credential_table_encryption_key" {
@@ -628,6 +574,11 @@ resource "aws_kms_key" "doc_app_credential_table_encryption_key" {
628
574
policy = data. aws_iam_policy_document . cross_account_doc_app_credential_table_encryption_key_policy . json
629
575
}
630
576
577
+ resource "aws_kms_alias" "doc_app_credential_table_encryption_key_alias" {
578
+ name = " alias/${ var . environment } -doc-app-credential-table-encryption-key"
579
+ target_key_id = aws_kms_key. doc_app_credential_table_encryption_key . key_id
580
+ }
581
+
631
582
data "aws_iam_policy_document" "cross_account_doc_app_credential_table_encryption_key_policy" {
632
583
statement {
633
584
sid = " DefaultAccessPolicy"
@@ -726,6 +677,34 @@ data "aws_iam_policy_document" "cross_account_table_encryption_key_access_policy
726
677
identifiers = [var . orchestration_account_id ]
727
678
}
728
679
}
680
+
681
+ dynamic "statement" {
682
+ for_each = var. environment != " production" && var. environment != " integration" && var. environment != " staging" ? [" 1" ] : []
683
+ content {
684
+ sid = " Allow Auth access to dynamo table encryption key"
685
+ effect = " Allow"
686
+
687
+ actions = [
688
+ " kms:Encrypt" ,
689
+ " kms:Decrypt" ,
690
+ " kms:ReEncrypt*" ,
691
+ " kms:GenerateDataKey*" ,
692
+ " kms:CreateGrant" ,
693
+ " kms:DescribeKey" ,
694
+ ]
695
+ principals {
696
+ type = " AWS"
697
+ identifiers = [
698
+ format (
699
+ " arn:%s:iam::%s:root" ,
700
+ data. aws_partition . current . partition ,
701
+ var. auth_new_account_id
702
+ )
703
+ ]
704
+ }
705
+ resources = [" *" ]
706
+ }
707
+ }
729
708
}
730
709
731
710
resource "aws_kms_key" "user_profile_table_encryption_key" {
@@ -750,21 +729,12 @@ resource "aws_kms_key" "email_check_result_encryption_key" {
750
729
key_usage = " ENCRYPT_DECRYPT"
751
730
customer_master_key_spec = " SYMMETRIC_DEFAULT"
752
731
enable_key_rotation = true
753
- policy = jsonencode ({
754
- Version = " 2012-10-17"
755
- Id = " key-policy-dynamodb" ,
756
- Statement = [
757
- {
758
- Sid = " Allow IAM to manage this key" ,
759
- Effect = " Allow" ,
760
- Principal = { AWS = " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" }
761
- Action = [
762
- " kms:*"
763
- ],
764
- Resource = " *"
765
- }
766
- ]
767
- })
732
+ policy = data. aws_iam_policy_document . auth_dynamo_table_encryption_key_access_policy . json
733
+ }
734
+
735
+ resource "aws_kms_alias" "email_check_result_encryption_key_alias" {
736
+ name = " alias/${ var . environment } -email-check-result-table-encryption-key"
737
+ target_key_id = aws_kms_key. email_check_result_encryption_key . key_id
768
738
}
769
739
770
740
resource "aws_kms_key" "pending_email_check_queue_encryption_key" {
@@ -803,23 +773,7 @@ resource "aws_kms_key" "authentication_attempt_encryption_key" {
803
773
key_usage = " ENCRYPT_DECRYPT"
804
774
customer_master_key_spec = " SYMMETRIC_DEFAULT"
805
775
enable_key_rotation = true
806
-
807
- policy = jsonencode ({
808
- Version = " 2012-10-17"
809
- Id = " key-policy-dynamodb" ,
810
- Statement = [
811
- {
812
- Sid = " Allow IAM to manage this key" ,
813
- Effect = " Allow" ,
814
- Principal = { AWS = " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" }
815
- Action = [
816
- " kms:*"
817
- ],
818
- Resource = " *"
819
- }
820
- ]
821
- })
822
-
776
+ policy = data. aws_iam_policy_document . auth_dynamo_table_encryption_key_access_policy . json
823
777
}
824
778
825
779
resource "aws_kms_alias" "authentication_attempt_encryption_key_alias" {
@@ -833,23 +787,7 @@ resource "aws_kms_key" "auth_session_table_encryption_key" {
833
787
key_usage = " ENCRYPT_DECRYPT"
834
788
customer_master_key_spec = " SYMMETRIC_DEFAULT"
835
789
enable_key_rotation = true
836
-
837
- policy = jsonencode ({
838
- Version = " 2012-10-17"
839
- Id = " key-policy-dynamodb" ,
840
- Statement = [
841
- {
842
- Sid = " Allow IAM to manage this key" ,
843
- Effect = " Allow" ,
844
- Principal = { AWS = " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" }
845
- Action = [
846
- " kms:*"
847
- ],
848
- Resource = " *"
849
- }
850
- ]
851
- })
852
-
790
+ policy = data. aws_iam_policy_document . auth_dynamo_table_encryption_key_access_policy . json
853
791
}
854
792
855
793
resource "aws_kms_alias" "auth_session_table_encryption_key_alias" {
@@ -864,30 +802,65 @@ resource "aws_kms_key" "id_reverification_state_table_encryption_key" {
864
802
key_usage = " ENCRYPT_DECRYPT"
865
803
customer_master_key_spec = " SYMMETRIC_DEFAULT"
866
804
enable_key_rotation = true
867
-
868
- policy = jsonencode ({
869
- Version = " 2012-10-17"
870
- Id = " key-policy-dynamodb" ,
871
- Statement = [
872
- {
873
- Sid = " Allow IAM to manage this key" ,
874
- Effect = " Allow" ,
875
- Principal = { AWS = " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" }
876
- Action = [
877
- " kms:*"
878
- ],
879
- Resource = " *"
880
- }
881
- ]
882
- })
883
-
805
+ policy = data. aws_iam_policy_document . auth_dynamo_table_encryption_key_access_policy . json
884
806
}
885
807
886
808
resource "aws_kms_alias" "id_reverification_state_table_encryption_key_alias" {
887
809
name = " alias/${ var . environment } -id-reverification-state-table-encryption-key"
888
810
target_key_id = aws_kms_key. id_reverification_state_table_encryption_key . key_id
889
811
}
890
812
813
+ # # KMS Key policy to Allow access to the KMS key for the new authentication AWS account to access DynamoDB table
814
+
815
+
816
+ data "aws_iam_policy_document" "auth_dynamo_table_encryption_key_access_policy" {
817
+ # checkov:skip=CKV_AWS_109:Root requires all kms:* actions access
818
+ # checkov:skip=CKV_AWS_111:Root requires all kms:* actions access
819
+ # checkov:skip=CKV_AWS_356:Policy cannot self-reference the kms key, so resources wildcard is required
820
+ statement {
821
+ sid = " DefaultAccessPolicy"
822
+ effect = " Allow"
823
+
824
+ actions = [
825
+ " kms:*"
826
+ ]
827
+ resources = [" *" ]
828
+
829
+ principals {
830
+ type = " AWS"
831
+ identifiers = [" arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" ]
832
+ }
833
+ }
834
+
835
+ dynamic "statement" {
836
+ for_each = var. environment != " production" && var. environment != " integration" && var. environment != " staging" ? [" 1" ] : []
837
+ content {
838
+ sid = " Allow Auth access to dynamo table encryption key"
839
+ effect = " Allow"
840
+
841
+ actions = [
842
+ " kms:Encrypt" ,
843
+ " kms:Decrypt" ,
844
+ " kms:ReEncrypt*" ,
845
+ " kms:GenerateDataKey*" ,
846
+ " kms:CreateGrant" ,
847
+ " kms:DescribeKey" ,
848
+ ]
849
+ principals {
850
+ type = " AWS"
851
+ identifiers = [
852
+ format (
853
+ " arn:%s:iam::%s:root" ,
854
+ data. aws_partition . current . partition ,
855
+ var. auth_new_account_id
856
+ )
857
+ ]
858
+ }
859
+ resources = [" *" ]
860
+ }
861
+ }
862
+ }
863
+
891
864
# # Frontend KMS key for signing JWT tokens
892
865
resource "aws_kms_key" "authentication_encryption_key" {
893
866
description = " KMS encryption key for decrypting requests from Orchestration"
0 commit comments