Skip to content

Commit 5e4bffe

Browse files
committed
updated kms key and policy for #42
1 parent a97b23e commit 5e4bffe

File tree

1 file changed

+20
-46
lines changed

1 file changed

+20
-46
lines changed

kms.tf

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,51 @@ resource "aws_kms_key" "encryption_secret" {
99
}
1010
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_alias
1111
resource "aws_kms_alias" "encryption_secret" {
12-
name = "alias/${var.name}-elasticache-in-transit"
12+
name = "alias/${var.name}-encryption-secret"
1313
target_key_id = aws_kms_key.encryption_secret.key_id
1414
}
1515
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key_policy
1616
resource "aws_kms_key_policy" "encryption_secret_policy" {
1717
key_id = aws_kms_key.encryption_secret.id
1818
policy = jsonencode({
19-
Id = "${var.name}-encryption-secret"
19+
Id = "${var.name}-encryption-secret"
20+
Version = "2012-10-17"
2021
Statement = [
2122
{
22-
Action = [
23-
"kms:Create*",
24-
"kms:Describe*",
25-
"kms:Enable*",
26-
"kms:List*",
27-
"kms:Put*",
28-
"kms:Update*",
29-
"kms:Revoke*",
30-
"kms:Disable*",
31-
"kms:Get*",
32-
"kms:Delete*",
33-
"kms:ScheduleKeyDeletion",
34-
"kms:CancelKeyDeletion"
35-
]
23+
Sid = "Enable IAM User Permissions"
3624
Effect = "Allow"
3725
Principal = {
38-
AWS = "${local.principal_root_arn}"
26+
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
3927
}
28+
Action = "kms:*"
4029
Resource = "*"
41-
Sid = "Enable IAM User Permissions"
42-
Condition = {
43-
StringEquals = {
44-
"kms:CallerAccount" = "${data.aws_caller_identity.current.account_id}"
45-
}
46-
}
4730
},
4831
{
49-
Sid = "AllowSecretsManagerUse"
32+
Sid = "Allow access through AWS Secrets Manager for all principals in the account that are authorized to use AWS Secrets Manager"
5033
Effect = "Allow"
34+
Principal = {
35+
AWS = ["*"]
36+
}
5137
Action = [
5238
"kms:Encrypt",
5339
"kms:Decrypt",
5440
"kms:ReEncrypt*",
41+
"kms:CreateGrant",
42+
"kms:DescribeKey",
5543
"kms:GenerateDataKey*"
5644
]
5745
Resource = "*"
58-
Principal = {
59-
Service = "secretsmanager.amazonaws.com"
46+
Condition = {
47+
StringEquals = {
48+
"kms:CallerAccount" = "${data.aws_caller_identity.current.account_id}"
49+
"kms:ViaService" = "secretsmanager.${var.region}.amazonaws.com"
50+
}
6051
}
6152
}
6253
]
6354
})
6455
}
56+
6557
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key
6658
resource "aws_kms_key" "encryption_rest" {
6759
enable_key_rotation = true
@@ -73,7 +65,7 @@ resource "aws_kms_key" "encryption_rest" {
7365
}
7466
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_alias
7567
resource "aws_kms_alias" "encryption_rest" {
76-
name = "alias/${var.name}-elasticache-at-rest"
68+
name = "alias/${var.name}-encryption-rest"
7769
target_key_id = aws_kms_key.encryption_rest.key_id
7870
}
7971
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key_policy
@@ -83,31 +75,13 @@ resource "aws_kms_key_policy" "encryption_rest_policy" {
8375
Id = "${var.name}-encryption-rest"
8476
Statement = [
8577
{
86-
Action = [
87-
"kms:Create*",
88-
"kms:Describe*",
89-
"kms:Enable*",
90-
"kms:List*",
91-
"kms:Put*",
92-
"kms:Update*",
93-
"kms:Revoke*",
94-
"kms:Disable*",
95-
"kms:Get*",
96-
"kms:Delete*",
97-
"kms:ScheduleKeyDeletion",
98-
"kms:CancelKeyDeletion"
99-
]
78+
Action = ["kms:*"]
10079
Effect = "Allow"
10180
Principal = {
10281
AWS = "${local.principal_root_arn}"
10382
}
10483
Resource = "*"
10584
Sid = "Enable IAM User Permissions"
106-
Condition = {
107-
StringEquals = {
108-
"kms:CallerAccount" = "${data.aws_caller_identity.current.account_id}"
109-
}
110-
}
11185
},
11286
{
11387
Sid = "Allow ElastiCache to use the key"

0 commit comments

Comments
 (0)