-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencryption.tf
65 lines (57 loc) · 2.16 KB
/
encryption.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
resource "aws_kms_alias" "this" {
name = "alias/${local.resource_name}"
target_key_id = aws_kms_key.this.id
}
resource "aws_kms_key" "this" {
description = "Encryption key for service ${local.resource_name}"
enable_key_rotation = true
is_enabled = true
tags = local.tags
policy = data.aws_iam_policy_document.encryption_key.json
}
data "aws_iam_policy_document" "encryption_key" {
#bridgecrew:skip=CKV_AWS_109: Skipping "Permissions management without constraints". False positive as this is attached as a key policy and is implicitly constrained by the key.
#bridgecrew:skip=CKV_AWS_111: Skipping "Write IAM policies without constraints". False positive as this is attached as a key policy and is implicitly constrained by the key.
#bridgecrew:skip=CKV_AWS_356: "Ensure no IAM policies documents allow "*" as a statement's resource for restrictable actions". False positive as this is attached as a key policy and implicitly constrained by the key.
statement {
sid = "Enable IAM User permissions"
effect = "Allow"
resources = ["*"]
actions = ["kms:*"]
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
}
}
statement {
sid = "Enable Cloudwatch Log encryption"
effect = "Allow"
resources = ["*"]
actions = [
"kms:Encrypt*",
"kms:Decrypt*",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:Describe*"
]
principals {
type = "Service"
identifiers = ["logs.${data.aws_region.this.name}.amazonaws.com"]
}
condition {
test = "ArnEquals"
variable = "kms:EncryptionContext:aws:logs:arn"
values = ["arn:aws:logs:${data.aws_region.this.name}:${data.aws_caller_identity.current.account_id}:*"]
}
}
statement {
sid = "Enable App Decrypt secrets"
effect = "Allow"
resources = ["*"]
actions = ["kms:Decrypt"]
principals {
type = "AWS"
identifiers = [aws_iam_role.execution.arn]
}
}
}