-
Notifications
You must be signed in to change notification settings - Fork 22
/
security_hub.tf
140 lines (103 loc) · 4.34 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
136
137
138
139
140
// 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]
}
}
// 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_finding_aggregator" "default" {
provider = aws.audit
linking_mode = var.aws_security_hub.aggregator_linking_mode
specified_regions = var.aws_security_hub.aggregator_linking_mode == "SPECIFIED_REGIONS" ? var.regions.linked_regions : null
depends_on = [aws_securityhub_account.default]
}
resource "aws_securityhub_organization_configuration" "default" {
provider = aws.audit
auto_enable = false
auto_enable_standards = "NONE"
organization_configuration {
configuration_type = "CENTRAL"
}
depends_on = [aws_securityhub_organization_admin_account.default, aws_securityhub_finding_aggregator.default]
}
resource "aws_securityhub_configuration_policy" "default" {
provider = aws.audit
name = "mcaf-lz"
description = "MCAF Landing Zone default configuration policy"
configuration_policy {
service_enabled = true
enabled_standard_arns = local.security_hub_standards_arns
security_controls_configuration {
disabled_control_identifiers = var.aws_security_hub.disabled_control_identifiers
enabled_control_identifiers = var.aws_security_hub.enabled_control_identifiers
}
}
depends_on = [aws_securityhub_organization_configuration.default]
}
resource "aws_securityhub_configuration_policy_association" "root" {
provider = aws.audit
target_id = data.aws_organizations_organization.default.roots[0].id
policy_id = aws_securityhub_configuration_policy.default.id
}
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]
}