-
Notifications
You must be signed in to change notification settings - Fork 21
/
security_hub.tf
135 lines (98 loc) · 4.06 KB
/
security_hub.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// AWS Security Hub - Management account configuration and enrollment
resource "aws_securityhub_organization_admin_account" "default" {
admin_account_id = data.aws_caller_identity.audit.account_id
depends_on = [aws_securityhub_account.default]
}
resource "aws_securityhub_account" "management" {
control_finding_generator = var.aws_security_hub.control_finding_generator
depends_on = [aws_securityhub_organization_configuration.default]
}
resource "aws_securityhub_member" "management" {
provider = aws.audit
account_id = data.aws_caller_identity.management.account_id
depends_on = [aws_securityhub_account.management]
lifecycle {
ignore_changes = [invite]
}
}
resource "aws_securityhub_standards_subscription" "management" {
for_each = toset(local.security_hub_standards_arns)
standards_arn = each.value
depends_on = [aws_securityhub_account.default]
}
// AWS Security Hub - Audit account configuration and enrollment
resource "aws_securityhub_account" "default" {
provider = aws.audit
control_finding_generator = var.aws_security_hub.control_finding_generator
}
resource "aws_securityhub_organization_configuration" "default" {
provider = aws.audit
auto_enable = var.aws_security_hub.auto_enable_new_accounts
auto_enable_standards = var.aws_security_hub.auto_enable_default_standards ? "DEFAULT" : "NONE"
depends_on = [aws_securityhub_organization_admin_account.default]
}
resource "aws_securityhub_product_subscription" "default" {
for_each = toset(var.aws_security_hub.product_arns)
provider = aws.audit
product_arn = each.value
depends_on = [aws_securityhub_account.default]
}
resource "aws_securityhub_standards_subscription" "default" {
for_each = toset(local.security_hub_standards_arns)
provider = aws.audit
standards_arn = each.value
depends_on = [aws_securityhub_account.default]
}
resource "aws_cloudwatch_event_rule" "security_hub_findings" {
provider = aws.audit
name = "LandingZone-SecurityHubFindings"
description = "Rule for getting SecurityHub findings"
event_pattern = file("${path.module}/files/event_bridge/security_hub_findings.json.tpl")
tags = var.tags
}
resource "aws_cloudwatch_event_target" "security_hub_findings" {
provider = aws.audit
arn = aws_sns_topic.security_hub_findings.arn
rule = aws_cloudwatch_event_rule.security_hub_findings.name
target_id = "SendToSNS"
}
resource "aws_sns_topic" "security_hub_findings" {
provider = aws.audit
name = "LandingZone-SecurityHubFindings"
http_success_feedback_role_arn = aws_iam_role.sns_feedback.arn
http_failure_feedback_role_arn = aws_iam_role.sns_feedback.arn
kms_master_key_id = module.kms_key_audit.id
tags = var.tags
}
resource "aws_sns_topic_policy" "security_hub_findings" {
provider = aws.audit
arn = aws_sns_topic.security_hub_findings.arn
policy = templatefile("${path.module}/files/sns/security_hub_topic_policy.json.tpl", {
account_id = data.aws_caller_identity.audit.account_id
services_allowed_publish = jsonencode("events.amazonaws.com")
sns_topic = aws_sns_topic.security_hub_findings.arn
})
}
resource "aws_sns_topic_subscription" "security_hub_findings" {
for_each = var.aws_security_hub_sns_subscription
provider = aws.audit
endpoint = each.value.endpoint
endpoint_auto_confirms = length(regexall("http", each.value.protocol)) > 0
protocol = each.value.protocol
topic_arn = aws_sns_topic.security_hub_findings.arn
}
// AWS Security Hub - Logging account enrollment
resource "aws_securityhub_member" "logging" {
provider = aws.audit
account_id = data.aws_caller_identity.logging.account_id
lifecycle {
ignore_changes = [invite]
}
depends_on = [aws_securityhub_organization_configuration.default]
}
resource "aws_securityhub_standards_subscription" "logging" {
for_each = toset(local.security_hub_standards_arns)
provider = aws.logging
standards_arn = each.value
depends_on = [aws_securityhub_account.default]
}