-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkms.tf
97 lines (83 loc) · 2.28 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
resource "aws_kms_key" "demo_cloudtrail_bucket_key" {
description = "Used to encrypt CloudTrail logs"
deletion_window_in_days = 1
enable_key_rotation = true
policy = data.aws_iam_policy_document.demo_cloudtrail_bucket_key_policy.json
}
resource "aws_kms_alias" "demo_cloudtrail_bucket_key_alias" {
name = "alias/demo_cloudtrail_bucket_key_alias"
target_key_id = aws_kms_key.demo_cloudtrail_bucket_key.key_id
}
data "aws_iam_policy_document" "demo_cloudtrail_bucket_key_policy" {
policy_id = "Key policy created for CloudTrail log encryption"
statement {
sid = "Allow CloudTrail to describe key"
principals {
type = "Service"
identifiers = ["cloudtrail.amazonaws.com"]
}
actions = [
"kms:DescribeKey",
"kms:GenerateDataKey*",
"kms:Decrypt"
]
resources = ["*"]
}
statement {
sid = "Allow S3 to encrypt messages for publishing to SNS topic"
principals {
type = "Service"
identifiers = ["s3.amazonaws.com"]
}
actions = [
"kms:GenerateDataKey*",
"kms:Decrypt"
]
resources = ["*"]
}
statement {
sid = "KMS access from source account"
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.demo_account_id}:root"]
}
actions = ["kms:*"]
resources = ["*"]
}
statement {
sid = "Allow CloudTrail to encrypt logs"
principals {
type = "Service"
identifiers = ["cloudtrail.amazonaws.com"]
}
actions = ["kms:GenerateDataKey*"]
resources = ["*"]
condition {
test = "StringLike"
variable = "kms:EncryptionContext:aws:cloudtrail:arn"
values = ["arn:aws:cloudtrail:*:${var.demo_account_id}:trail/*"]
}
}
statement {
sid = "Allow principals in the account to decrypt log files"
principals {
type = "AWS"
identifiers = ["*"]
}
actions = [
"kms:Decrypt",
"kms:ReEncryptFrom"
]
resources = ["*"]
condition {
test = "StringEquals"
variable = "kms:CallerAccount"
values = ["${var.demo_account_id}"]
}
condition {
test = "StringLike"
variable = "kms:EncryptionContext:aws:cloudtrail:arn"
values = ["arn:aws:cloudtrail:*:${var.demo_account_id}:trail/*"]
}
}
}