This repository has been archived by the owner on Jun 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
waf.tf
180 lines (165 loc) · 4.32 KB
/
waf.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
170
171
172
173
174
175
176
177
178
179
resource "aws_waf_web_acl" "waf_acl" {
count = var.enabled ? 1 : 0
name = "${var.waf_prefix}-generic-owasp-acl"
metric_name = "${var.waf_prefix}genericowaspacl"
# Dynamic block to allow optional configuration of logging_configuration
dynamic "logging_configuration" {
iterator = x
for_each = aws_kinesis_firehose_delivery_stream.log_stream[*].arn
content {
log_destination = x.value
}
}
default_action {
type = "ALLOW"
}
# sql injection
dynamic "rules" {
iterator = x
for_each = local.is_sqli_enabled == 1 ? ["enabled"] : []
content {
action {
type = var.rule_sqli
}
priority = var.rule_sqli_priority
rule_id = aws_waf_rule.mitigate_sqli[0].id
type = "REGULAR"
}
}
# authorization tokens
dynamic "rules" {
iterator = x
for_each = local.is_auth_tokens_enabled == 1 ? ["enabled"] : []
content {
action {
type = var.rule_auth_tokens
}
priority = var.rule_auth_tokens_priority
rule_id = aws_waf_rule.detect_bad_auth_tokens[0].id
type = "REGULAR"
}
}
# corss site scripting
dynamic "rules" {
iterator = x
for_each = local.is_xss_enabled == 1 ? ["enabled"] : []
content {
action {
type = var.rule_xss
}
priority = var.rule_xss_priority
rule_id = aws_waf_rule.mitigate_xss[0].id
type = "REGULAR"
}
}
# path traversal (rfi-lfi)
dynamic "rules" {
iterator = x
for_each = local.is_rfi_lfi_enabled == 1 ? ["enabled"] : []
content {
action {
type = var.rule_rfi_lfi
}
priority = var.rule_rfi_lfi_priority
rule_id = aws_waf_rule.detect_rfi_lfi_traversal[0].id
type = "REGULAR"
}
}
# php
dynamic "rules" {
iterator = x
for_each = local.is_php_enabled == 1 ? ["enabled"] : []
content {
action {
type = var.rule_php
}
priority = var.rule_php_priority
rule_id = aws_waf_rule.detect_php_insecure[0].id
type = "REGULAR"
}
}
# size constraints
dynamic "rules" {
iterator = x
for_each = local.is_size_constraints_enabled == 1 ? ["enabled"] : []
content {
action {
type = var.rule_size_constraints
}
priority = var.rule_size_constraints_priority
rule_id = aws_waf_rule.restrict_sizes[0].id
type = "REGULAR"
}
}
# cross site request forgery
dynamic "rules" {
iterator = x
for_each = local.is_csrf_enabled == 1 ? ["enabled"] : []
content {
action {
type = var.rule_csrf
}
priority = var.rule_csrf_priority
rule_id = aws_waf_rule.enforce_csrf[0].id
type = "REGULAR"
}
}
# server side includes
dynamic "rules" {
iterator = x
for_each = local.is_ssi_enabled == 1 ? ["enabled"] : []
content {
action {
type = var.rule_ssi
}
priority = var.rule_ssi_priority
rule_id = aws_waf_rule.detect_ssi[0].id
type = "REGULAR"
}
}
# ip blacklist
dynamic "rules" {
iterator = x
for_each = local.is_ip_blacklist_enabled == 1 ? ["enabled"] : []
content {
action {
type = var.rule_ip_blacklist
}
priority = var.rule_ip_blacklist_priority
rule_id = aws_waf_rule.detect_blacklisted_ips[0].id
type = "REGULAR"
}
}
# rate limiting
dynamic "rules" {
iterator = x
for_each = local.is_rate_limit_enabled == 1 ? ["enabled"] : []
content {
action {
type = var.rule_rate_limit
}
priority = var.rule_rate_limit_priority
rule_id = aws_waf_rate_based_rule.rate_limit[0].id
type = "RATE_BASED"
}
}
# country of origin
dynamic "rules" {
iterator = x
for_each = local.is_country_of_origin_enabled == 1 ? ["enabled"] : []
content {
action {
type = var.rule_country_of_origin
}
priority = var.rule_country_of_origin_priority
rule_id = aws_waf_rule.country_of_origin_filter[0].id
type = "REGULAR"
}
}
}
resource "aws_wafregional_web_acl_association" "acl_cloudfront_association" {
depends_on = [aws_waf_web_acl.waf_acl]
count = var.enabled == 1 ? length(var.cloudfront_arns) : 0
resource_arn = element(var.cloudfront_arns, count.index)
web_acl_id = aws_waf_web_acl.waf_acl[0].id
}