forked from grendel-consulting/terraform-aws-cdk_bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kms.tf
104 lines (85 loc) · 2.13 KB
/
kms.tf
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
# tfsec:ignore:aws-kms-auto-rotate-keys
resource "aws_kms_key" "staging_key" {
count = local.create_new_key ? 1 : 0
description = "CDK Bootstrap Staging Bucket"
policy = data.aws_iam_policy_document.staging_key[count.index].json
tags = merge({
map-migrated = var.map_server_id
}, var.additional_tags)
}
resource "aws_kms_alias" "cdk_assets_key" {
count = local.create_new_key ? 1 : 0
name = "alias/cdk-${var.qualifier}-assets-key"
target_key_id = aws_kms_key.staging_key[count.index].key_id
}
data "aws_iam_policy_document" "staging_key" {
count = local.create_new_key ? 1 : 0
statement {
sid = "AllowAccount"
effect = "Allow"
principals {
type = "AWS"
identifiers = [data.aws_caller_identity.current.account_id]
}
actions = [
"kms:Create*",
"kms:Describe*",
"kms:Enable*",
"kms:List*",
"kms:Put*",
"kms:Update*",
"kms:Revoke*",
"kms:Disable*",
"kms:Get*",
"kms:Delete*",
"kms:ScheduleKeyDeletion",
"kms:CancelKeyDeletion",
"kms:GenerateDataKey",
"kms:TagResource",
"kms:UntagResource",
]
resources = ["*"]
}
statement {
sid = "AllowLocalService"
effect = "Allow"
principals {
type = "AWS"
identifiers = ["*"]
}
actions = [
"kms:Decrypt",
"kms:DescribeKey",
"kms:Encrypt",
"kms:GenerateDataKey*",
"kms:ReEncrypt*",
]
condition {
test = "StringEquals"
variable = "kms:CallerAccount"
values = [data.aws_caller_identity.current.account_id]
}
condition {
test = "StringEquals"
variable = "kms:ViaService"
values = ["s3.${data.aws_region.current.name}.amazonaws.com"]
}
resources = ["*"]
}
statement {
sid = "AllowFilePublishingRole"
effect = "Allow"
principals {
type = "AWS"
identifiers = [aws_iam_role.file_publishing_role.arn]
}
actions = [
"kms:Decrypt",
"kms:DescribeKey",
"kms:Encrypt",
"kms:GenerateDataKey*",
"kms:ReEncrypt*",
]
resources = ["*"]
}
}