|
2 | 2 |
|
3 | 3 | Terraform module with create vpc and subnet resources on AWS.
|
4 | 4 |
|
5 |
| -## Usage |
| 5 | +## Custom Rules Usage |
6 | 6 |
|
7 | 7 | ```terraform
|
8 |
| -module "waf" { |
9 |
| - source = "git::ssh://git@github.com:oozou/terraform-aws-waf.git" |
10 |
| - name = "test-waf" |
11 |
| - prefix = "oozou" |
12 |
| - is_enable_default_rule = true |
13 |
| - is_enable_sampled_requests = false |
14 |
| - is_enable_cloudwatch_metrics = false |
15 |
| - is_create_logging_configuration = true |
16 |
| - scope = "CLOUDFRONT" |
17 |
| - environment = "dev" |
18 |
| - managed_rules = [ |
19 |
| - { |
20 |
| - name = "AWSManagedRulesAdminProtectionRuleSet", |
21 |
| - priority = 60 |
22 |
| - override_action = "none" |
23 |
| - excluded_rules = [] |
24 |
| - } |
25 |
| - ] |
26 |
| - ip_sets_rule = [ |
27 |
| - { |
28 |
| - name = "block-ip-set" |
29 |
| - priority = 6 |
30 |
| - action = "block" |
31 |
| - ip_address_version = "IPV4" |
32 |
| - ip_set = ["10.0.1.1/32"] |
33 |
| - } |
34 |
| - ] |
35 |
| - ip_rate_based_rule = { |
36 |
| - name : "ip-rate-limit", |
37 |
| - priority : 7, |
38 |
| - action : "block", |
39 |
| - limit : 100 |
40 |
| - } |
41 |
| - redacted_fields = [ |
42 |
| - { |
43 |
| - single_header = { |
44 |
| - name = "user-agent" |
| 8 | +waf_custom_rules = [ |
| 9 | + { |
| 10 | + name = "match-originate-from-an-ip-addresses-in-rule" # |
| 11 | + priority = 10 ## |
| 12 | + action = "count" # {count, allow, block} |
| 13 | + expression_type = "match-statement" ## |
| 14 | + statements = [ ## |
| 15 | + { |
| 16 | + inspect = "originate-from-an-ip-addresses-in" ## |
| 17 | + ip_set_key = "oozou-vpn-ipv4-set" # Match above |
45 | 18 | }
|
46 |
| - } |
47 |
| - ] |
48 |
| -
|
49 |
| - logging_filter = { |
50 |
| - default_behavior = "DROP" |
51 |
| - filter = [ |
52 |
| - { |
53 |
| - behavior = "KEEP" |
54 |
| - requirement = "MEETS_ANY" |
55 |
| - condition = [ |
56 |
| - { |
57 |
| - action_condition = { |
58 |
| - action = "ALLOW" |
59 |
| - } |
60 |
| - }, |
61 |
| - ] |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + name = "match-originate-from-a-country-in-rule" # |
| 23 | + priority = 20 ## |
| 24 | + action = "count" # {count, allow, block} |
| 25 | + expression_type = "match-statement" ## |
| 26 | + statements = [ ## |
| 27 | + { |
| 28 | + inspect = "originate-from-a-country-in" ## |
| 29 | + country_codes = ["TH"] |
| 30 | + } |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + name = "match-has-a-label-rule" # |
| 35 | + priority = 30 ## |
| 36 | + action = "count" # {count, allow, block} |
| 37 | + expression_type = "match-statement" ## |
| 38 | + statements = [ ## |
| 39 | + { |
| 40 | + inspect = "has-a-label" ## |
| 41 | + scope = "LABEL" |
| 42 | + key = "awswaf:managed:aws:core-rule-set:GenericLFI_URIPath" |
| 43 | + } |
| 44 | + ] |
| 45 | + }, |
| 46 | + /* -------------------------------------------------------------------------- */ |
| 47 | + /* Strgin Match Condition Example */ |
| 48 | + /* -------------------------------------------------------------------------- */ |
| 49 | + { |
| 50 | + name = "match-request-component-single-header-rule" # |
| 51 | + priority = 40 ## |
| 52 | + action = "count" # {count, allow, block} |
| 53 | + expression_type = "match-statement" ## |
| 54 | + statements = [ ## |
| 55 | + { |
| 56 | + inspect = "single-header" ## |
| 57 | + header_name = "host" |
| 58 | + positional_constraint = "CONTAINS" |
| 59 | + search_string = "STRING_TO_SEARCH" |
| 60 | + } |
| 61 | + ] |
| 62 | + }, |
| 63 | + { |
| 64 | + ## Not available (just for test case) |
| 65 | + name = "match-request-component-all-headers-rule" # |
| 66 | + priority = 41 ## |
| 67 | + action = "count" # {count, allow, block} |
| 68 | + expression_type = "match-statement" ## |
| 69 | + statements = [ ## |
| 70 | + { |
| 71 | + inspect = "all-headers" ## |
| 72 | + positional_constraint = "CONTAINS" |
| 73 | + search_string = "STRING_TO_SEARCH" |
| 74 | + } |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + ## Not available (just for test case) |
| 79 | + name = "match-request-component-cookies-rule" # |
| 80 | + priority = 42 ## |
| 81 | + action = "count" # {count, allow, block} |
| 82 | + expression_type = "match-statement" ## |
| 83 | + statements = [ ## |
| 84 | + { |
| 85 | + inspect = "cookies" ## |
| 86 | + positional_constraint = "CONTAINS" |
| 87 | + search_string = "STRING_TO_SEARCH" |
| 88 | + } |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + name = "match-request-component-single-query-parameter-rule" # |
| 93 | + priority = 43 ## |
| 94 | + action = "count" # {count, allow, block} |
| 95 | + expression_type = "match-statement" ## |
| 96 | + statements = [ ## |
| 97 | + { |
| 98 | + inspect = "single-query-parameter" ## |
| 99 | + positional_constraint = "CONTAINS" |
| 100 | + search_string = "STRING_TO_SEARCH" |
| 101 | + query_string_name = "user" |
| 102 | + } |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + name = "match-request-component-all-query-parameters-rule" # |
| 107 | + priority = 44 ## |
| 108 | + action = "count" # {count, allow, block} |
| 109 | + expression_type = "match-statement" ## |
| 110 | + statements = [ ## |
| 111 | + { |
| 112 | + inspect = "all-query-parameters" ## |
| 113 | + positional_constraint = "CONTAINS" |
| 114 | + search_string = "STRING_TO_SEARCH" |
| 115 | + } |
| 116 | + ] |
| 117 | + }, |
| 118 | + { |
| 119 | + name = "match-request-component-uri-path-rule" # |
| 120 | + priority = 45 ## |
| 121 | + action = "count" # {count, allow, block} |
| 122 | + expression_type = "match-statement" ## |
| 123 | + statements = [ ## |
| 124 | + { |
| 125 | + inspect = "uri-path" ## |
| 126 | + positional_constraint = "CONTAINS" |
| 127 | + search_string = "STRING_TO_SEARCH" |
| 128 | + } |
| 129 | + ] |
| 130 | + }, |
| 131 | + { |
| 132 | + name = "match-request-component-query-string-rule" # |
| 133 | + priority = 46 ## |
| 134 | + action = "count" # {count, allow, block} |
| 135 | + expression_type = "match-statement" ## |
| 136 | + statements = [ ## |
| 137 | + { |
| 138 | + inspect = "query-string" ## |
| 139 | + positional_constraint = "CONTAINS" |
| 140 | + search_string = "STRING_TO_SEARCH" |
| 141 | + } |
| 142 | + ] |
| 143 | + }, |
| 144 | + ## Not available (just for test case) |
| 145 | + { |
| 146 | + name = "match-request-component-body-rule" # |
| 147 | + priority = 47 ## |
| 148 | + action = "count" # {count, allow, block} |
| 149 | + expression_type = "match-statement" ## |
| 150 | + statements = [ ## |
| 151 | + { |
| 152 | + inspect = "body" ## |
| 153 | + positional_constraint = "CONTAINS" |
| 154 | + search_string = "STRING_TO_SEARCH" |
| 155 | + } |
| 156 | + ] |
| 157 | + }, |
| 158 | + { |
| 159 | + ## Not available (just for test case) |
| 160 | + name = "match-request-component-json-body-rule" # |
| 161 | + priority = 48 ## |
| 162 | + action = "count" # {count, allow, block} |
| 163 | + expression_type = "match-statement" ## |
| 164 | + statements = [ ## |
| 165 | + { |
| 166 | + inspect = "json-body" ## |
| 167 | + positional_constraint = "CONTAINS" |
| 168 | + search_string = "STRING_TO_SEARCH" |
| 169 | + } |
| 170 | + ] |
| 171 | + }, |
| 172 | + { |
| 173 | + name = "match-request-component-http-method-rule" # |
| 174 | + priority = 49 ## |
| 175 | + action = "count" # {count, allow, block} |
| 176 | + expression_type = "match-statement" ## |
| 177 | + statements = [ ## |
| 178 | + { |
| 179 | + inspect = "http-method" ## |
| 180 | + positional_constraint = "CONTAINS" |
| 181 | + search_string = "post" |
| 182 | + } |
| 183 | + ] |
| 184 | + }, |
| 185 | + /* -------------------------------------------------------------------------- */ |
| 186 | + /* And Statement */ |
| 187 | + /* -------------------------------------------------------------------------- */ |
| 188 | + { |
| 189 | + name = "match-request-component-http-method-rule" # |
| 190 | + priority = 50 ## |
| 191 | + action = "count" # {count, allow, block} |
| 192 | + expression_type = "and-statements" ## |
| 193 | + statements = [ ## |
| 194 | + { |
| 195 | + inspect = "http-method" ## |
| 196 | + is_negated_statement = false |
| 197 | + positional_constraint = "CONTAINS" |
| 198 | + search_string = "post" |
| 199 | + }, |
| 200 | + { |
| 201 | + inspect = "single-header" ## |
| 202 | + header_name = "host" |
| 203 | + is_negated_statement = true |
| 204 | + positional_constraint = "CONTAINS" |
| 205 | + search_string = "STRING_TO_SEARCH" |
| 206 | + }, |
| 207 | + { |
| 208 | + inspect = "originate-from-an-ip-addresses-in" ## |
| 209 | + ip_set_key = "oozou-vpn-ipv4-set" |
| 210 | + }, |
| 211 | + { |
| 212 | + inspect = "originate-from-a-country-in" ## |
| 213 | + country_codes = ["TH"] |
62 | 214 | }
|
63 | 215 | ]
|
64 |
| - } |
65 |
| - association_resources = "arn:xxxxx" |
66 |
| - tags = { |
67 |
| - "Custom-Tag" = "1" |
68 |
| - } |
69 |
| -} |
| 216 | + }, |
| 217 | +] |
70 | 218 | ```
|
71 | 219 |
|
72 | 220 | <!-- BEGIN_TF_DOCS -->
|
|
0 commit comments