/
main.tf
170 lines (144 loc) · 3.7 KB
/
main.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#
# This is our WAF ACL with each rule defined and prioritized accordingly.
#
resource "aws_wafregional_web_acl" "wafregional_acl" {
name = "${var.waf_prefix}-generic-owasp-acl"
metric_name = replace("${var.waf_prefix}genericowaspacl", "/[^0-9A-Za-z]/", "")
default_action {
type = "ALLOW"
}
#
# Note: we are using this but we are not applying body size restrictions because
# uploads could be affected by that.
#
rule {
action {
type = var.rule_size_restriction_action_type
}
priority = 10
rule_id = aws_wafregional_rule.restrict_sizes.id
type = "REGULAR"
}
#
# Reason: we are not implementing an IP blacklist yet.
# So COMMENT rule block below to deactivate this rule
#
rule {
action {
type = var.rule_blacklisted_ips_action_type
}
priority = 20
rule_id = aws_wafregional_rule.detect_blacklisted_ips.id
type = "REGULAR"
}
#
# Reason: the apps do not use auth tokens yet.
# So COMMENT rule block below to deactivate this rule
#
rule {
action {
type = var.rule_auth_tokens_action
}
priority = 30
rule_id = aws_wafregional_rule.detect_bad_auth_tokens.id
type = "REGULAR"
}
rule {
action {
type = var.rule_sqli_action
}
priority = 40
rule_id = aws_wafregional_rule.mitigate_sqli.id
type = "REGULAR"
}
rule {
action {
type = var.rule_xss_action
}
priority = 50
rule_id = aws_wafregional_rule.mitigate_xss.id
type = "REGULAR"
}
rule {
action {
type = var.rule_lfi_rfi_action
}
priority = 60
rule_id = aws_wafregional_rule.detect_rfi_lfi_traversal.id
type = "REGULAR"
}
#
# Reason: we don't have PHP stacks on this project.
# So COMMENT rule block below to deactivate this rule
#
rule {
action {
type = var.rule_php_insecurities_action_type
}
priority = 70
rule_id = aws_wafregional_rule.detect_php_insecure.id
type = "REGULAR"
}
#
# Reason: the apps do not use CSRF tokens.
# So COMMENT rule block below to deactivate this rule
#
rule {
action {
type = var.rule_csrf_action_type
}
priority = 80
rule_id = aws_wafregional_rule.enforce_csrf.id
type = "REGULAR"
}
#
# Reason: this should cover any config files in our web root folder.
#
rule {
action {
type = var.rule_ssi_action_type
}
priority = 90
rule_id = aws_wafregional_rule.detect_ssi.id
type = "REGULAR"
}
#
# Reason: we do not have IP restriction on admin sections.
# So COMMENT rule block below to deactivate this rule
#
rule {
action {
type = var.rule_admin_access_action_type
}
priority = 100
rule_id = aws_wafregional_rule.detect_admin_access.id
type = "REGULAR"
}
# Logging configuration when there are no redacted fields.
dynamic logging_configuration {
for_each = var.enable_logging && length(var.log_redacted_fields) == 0 ? [true] : []
content {
log_destination = var.log_destination_arn
}
}
# Logging configuration when there are redacted fields.
dynamic logging_configuration {
for_each = var.enable_logging && length(var.log_redacted_fields) > 0 ? [true] : []
content {
log_destination = var.log_destination_arn
redacted_fields {
field_to_match = var.log_redacted_fields
}
}
}
tags = var.tags
}
#
# Link the WAF ACL to an ALBs.
#
resource "aws_wafregional_web_acl_association" "acl_alb_association" {
depends_on = [aws_wafregional_web_acl.wafregional_acl]
count = length(var.alb_arn)
resource_arn = var.alb_arn[count.index]
web_acl_id = aws_wafregional_web_acl.wafregional_acl.id
}