-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathkms.tf
More file actions
115 lines (113 loc) · 3.28 KB
/
kms.tf
File metadata and controls
115 lines (113 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# KMS CMK to encrypt/decrypt secrets
resource "aws_kms_key" "secrets_cmk" {
#checkov:skip=CKV_AWS_111: Root user needs full KMS key management
#checkov:skip=CKV_AWS_356: Root user needs full KMS key management
#checkov:skip=CKV_AWS_109: Root user needs full KMS key management
description = "CMK for Secrets Manager - ${var.project_name}-${var.environment}"
enable_key_rotation = true
deletion_window_in_days = 30
policy = jsonencode({
Version = "2012-10-17"
Statement = [
# Allow your account root full control
{
Sid = "AllowAccountAdminsFullAccess"
Effect = "Allow"
Principal = { AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root" }
Action = "kms:*"
Resource = "*"
},
# Allow Secrets Manager service to use the key
{
Sid = "AllowSecretsManagerServiceUse"
Effect = "Allow"
Principal = { Service = "secretsmanager.amazonaws.com" }
Action = [
"kms:Encrypt",
"kms:Decrypt",
"kms:GenerateDataKey",
"kms:GenerateDataKeyWithoutPlaintext",
"kms:DescribeKey"
]
Resource = "*"
},
# Allow external role to decrypt for reading the secret
{
Sid = "AllowExternalRoleDecrypt"
Effect = "Allow"
Principal = { AWS = var.external_write_access_role_arn }
Action = [
"kms:Decrypt",
"kms:DescribeKey"
]
Resource = "*"
},
# Allow Lambda role to decrypt for reading the secret
{
Sid = "AllowLambdaRoleDecrypt"
Effect = "Allow"
Principal = { AWS = var.eligibility_lambda_role_arn }
Action = [
"kms:Decrypt",
"kms:DescribeKey"
]
Resource = "*"
}
]
})
tags = var.tags
}
resource "aws_kms_key" "rotation_sns_cmk" {
description = "KMS key for SNS topic encryption (CLI Login Notifications)"
deletion_window_in_days = 14
enable_key_rotation = true
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "Enable IAM User Permissions"
Effect = "Allow"
Principal = {
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
}
Action = "kms:*"
Resource = "*"
},
{
Sid = "Allow SNS and EventBridge Usage"
Effect = "Allow"
Principal = {
Service = [
"sns.amazonaws.com",
"events.amazonaws.com"
]
}
Action = [
"kms:Decrypt",
"kms:GenerateDataKey"
]
Resource = "*"
},
{
Sid = "Allow CloudWatch Logs Encryption"
Effect = "Allow"
Principal = {
Service = "logs.${var.region}.amazonaws.com"
}
Action = [
"kms:Encrypt*",
"kms:Decrypt*",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:Describe*"
]
Resource = "*"
Condition = {
ArnLike = {
"kms:EncryptionContext:aws:logs:arn": "arn:aws:logs:${var.region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/stepfunctions/SecretRotationWorkflow"
}
}
}
]
})
}