Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds geo_allowlist_statement_rules action #59

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Available targets:
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| <a name="input_geo_allowlist_statement_rules"></a> [geo\_allowlist\_statement\_rules](#input\_geo\_allowlist\_statement\_rules) | A rule statement used to identify a list of allowed countries which should not be blocked by the WAF.<br><br>name:<br> A friendly name of the rule.<br>priority:<br> If you define more than one Rule in a WebACL,<br> AWS WAF evaluates each request against the rules in order based on the value of priority.<br> AWS WAF processes rules with lower priority first.<br><br>captcha\_config:<br> Specifies how AWS WAF should handle CAPTCHA evaluations.<br><br> immunity\_time\_property:<br> Defines custom immunity time.<br><br> immunity\_time:<br> The amount of time, in seconds, that a CAPTCHA or challenge timestamp is considered valid by AWS WAF. The default setting is 300.<br><br>rule\_label:<br> A List of labels to apply to web requests that match the rule match statement<br><br>statement:<br> country\_codes:<br> A list of two-character country codes.<br> forwarded\_ip\_config:<br> fallback\_behavior:<br> The match status to assign to the web request if the request doesn't have a valid IP address in the specified position.<br> Possible values: `MATCH`, `NO_MATCH`<br> header\_name:<br> The name of the HTTP header to use for the IP address.<br><br>visibility\_config:<br> Defines and enables Amazon CloudWatch metrics and web request sample collection.<br><br> cloudwatch\_metrics\_enabled:<br> Whether the associated resource sends metrics to CloudWatch.<br> metric\_name:<br> A friendly name of the CloudWatch metric.<br> sampled\_requests\_enabled:<br> Whether AWS WAF should store a sampling of the web requests that match the rules. | <pre>list(object({<br> name = string<br> priority = number<br> captcha_config = optional(object({<br> immunity_time_property = object({<br> immunity_time = number<br> })<br> }), null)<br> rule_label = optional(list(string), null)<br> statement = any<br> visibility_config = optional(object({<br> cloudwatch_metrics_enabled = optional(bool)<br> metric_name = string<br> sampled_requests_enabled = optional(bool)<br> }), null)<br> }))</pre> | `null` | no |
| <a name="input_geo_allowlist_statement_rules"></a> [geo\_allowlist\_statement\_rules](#input\_geo\_allowlist\_statement\_rules) | A rule statement used to identify a list of allowed countries which should not be blocked by the WAF.<br><br>action:<br> The action that AWS WAF should take on a web request when it matches the rule's statement.<br>name:<br> A friendly name of the rule.<br>priority:<br> If you define more than one Rule in a WebACL,<br> AWS WAF evaluates each request against the rules in order based on the value of priority.<br> AWS WAF processes rules with lower priority first.<br><br>captcha\_config:<br> Specifies how AWS WAF should handle CAPTCHA evaluations.<br><br> immunity\_time\_property:<br> Defines custom immunity time.<br><br> immunity\_time:<br> The amount of time, in seconds, that a CAPTCHA or challenge timestamp is considered valid by AWS WAF. The default setting is 300.<br><br>rule\_label:<br> A List of labels to apply to web requests that match the rule match statement<br><br>statement:<br> country\_codes:<br> A list of two-character country codes.<br> forwarded\_ip\_config:<br> fallback\_behavior:<br> The match status to assign to the web request if the request doesn't have a valid IP address in the specified position.<br> Possible values: `MATCH`, `NO_MATCH`<br> header\_name:<br> The name of the HTTP header to use for the IP address.<br><br>visibility\_config:<br> Defines and enables Amazon CloudWatch metrics and web request sample collection.<br><br> cloudwatch\_metrics\_enabled:<br> Whether the associated resource sends metrics to CloudWatch.<br> metric\_name:<br> A friendly name of the CloudWatch metric.<br> sampled\_requests\_enabled:<br> Whether AWS WAF should store a sampling of the web requests that match the rules. | <pre>list(object({<br> name = string<br> priority = number<br> action = string<br> captcha_config = optional(object({<br> immunity_time_property = object({<br> immunity_time = number<br> })<br> }), null)<br> rule_label = optional(list(string), null)<br> statement = any<br> visibility_config = optional(object({<br> cloudwatch_metrics_enabled = optional(bool)<br> metric_name = string<br> sampled_requests_enabled = optional(bool)<br> }), null)<br> }))</pre> | `null` | no |
| <a name="input_geo_match_statement_rules"></a> [geo\_match\_statement\_rules](#input\_geo\_match\_statement\_rules) | A rule statement used to identify web requests based on country of origin.<br><br>action:<br> The action that AWS WAF should take on a web request when it matches the rule's statement.<br>name:<br> A friendly name of the rule.<br>priority:<br> If you define more than one Rule in a WebACL,<br> AWS WAF evaluates each request against the rules in order based on the value of priority.<br> AWS WAF processes rules with lower priority first.<br><br>captcha\_config:<br> Specifies how AWS WAF should handle CAPTCHA evaluations.<br><br> immunity\_time\_property:<br> Defines custom immunity time.<br><br> immunity\_time:<br> The amount of time, in seconds, that a CAPTCHA or challenge timestamp is considered valid by AWS WAF. The default setting is 300.<br><br>rule\_label:<br> A List of labels to apply to web requests that match the rule match statement<br><br>statement:<br> country\_codes:<br> A list of two-character country codes.<br> forwarded\_ip\_config:<br> fallback\_behavior:<br> The match status to assign to the web request if the request doesn't have a valid IP address in the specified position.<br> Possible values: `MATCH`, `NO_MATCH`<br> header\_name:<br> The name of the HTTP header to use for the IP address.<br><br>visibility\_config:<br> Defines and enables Amazon CloudWatch metrics and web request sample collection.<br><br> cloudwatch\_metrics\_enabled:<br> Whether the associated resource sends metrics to CloudWatch.<br> metric\_name:<br> A friendly name of the CloudWatch metric.<br> sampled\_requests\_enabled:<br> Whether AWS WAF should store a sampling of the web requests that match the rules. | <pre>list(object({<br> name = string<br> priority = number<br> action = string<br> captcha_config = optional(object({<br> immunity_time_property = object({<br> immunity_time = number<br> })<br> }), null)<br> rule_label = optional(list(string), null)<br> statement = any<br> visibility_config = optional(object({<br> cloudwatch_metrics_enabled = optional(bool)<br> metric_name = string<br> sampled_requests_enabled = optional(bool)<br> }), null)<br> }))</pre> | `null` | no |
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
| <a name="input_ip_set_reference_statement_rules"></a> [ip\_set\_reference\_statement\_rules](#input\_ip\_set\_reference\_statement\_rules) | A rule statement used to detect web requests coming from particular IP addresses or address ranges.<br><br>action:<br> The action that AWS WAF should take on a web request when it matches the rule's statement.<br>name:<br> A friendly name of the rule.<br>priority:<br> If you define more than one Rule in a WebACL,<br> AWS WAF evaluates each request against the rules in order based on the value of priority.<br> AWS WAF processes rules with lower priority first.<br><br>captcha\_config:<br> Specifies how AWS WAF should handle CAPTCHA evaluations.<br><br> immunity\_time\_property:<br> Defines custom immunity time.<br><br> immunity\_time:<br> The amount of time, in seconds, that a CAPTCHA or challenge timestamp is considered valid by AWS WAF. The default setting is 300.<br><br>rule\_label:<br> A List of labels to apply to web requests that match the rule match statement<br><br>statement:<br> arn:<br> The ARN of the IP Set that this statement references.<br> ip\_set:<br> Defines a new IP Set<br><br> description:<br> A friendly description of the IP Set<br> addresses:<br> Contains an array of strings that specifies zero or more IP addresses or blocks of IP addresses.<br> All addresses must be specified using Classless Inter-Domain Routing (CIDR) notation.<br> ip\_address\_version:<br> Specify `IPV4` or `IPV6`<br> ip\_set\_forwarded\_ip\_config:<br> fallback\_behavior:<br> The match status to assign to the web request if the request doesn't have a valid IP address in the specified position.<br> Possible values: `MATCH`, `NO_MATCH`<br> header\_name:<br> The name of the HTTP header to use for the IP address.<br> position:<br> The position in the header to search for the IP address.<br> Possible values include: `FIRST`, `LAST`, or `ANY`.<br><br>visibility\_config:<br> Defines and enables Amazon CloudWatch metrics and web request sample collection.<br><br> cloudwatch\_metrics\_enabled:<br> Whether the associated resource sends metrics to CloudWatch.<br> metric\_name:<br> A friendly name of the CloudWatch metric.<br> sampled\_requests\_enabled:<br> Whether AWS WAF should store a sampling of the web requests that match the rules. | <pre>list(object({<br> name = string<br> priority = number<br> action = string<br> captcha_config = optional(object({<br> immunity_time_property = object({<br> immunity_time = number<br> })<br> }), null)<br> rule_label = optional(list(string), null)<br> statement = any<br> visibility_config = optional(object({<br> cloudwatch_metrics_enabled = optional(bool)<br> metric_name = string<br> sampled_requests_enabled = optional(bool)<br> }), null)<br> }))</pre> | `null` | no |
Expand Down
16 changes: 16 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ module "waf" {
{
name = "rule-90"
priority = 90
action = "count"

statement = {
country_codes = ["US"]
Expand All @@ -313,6 +314,21 @@ module "waf" {
sampled_requests_enabled = false
metric_name = "rule-90-metric"
}
},
{
name = "rule-95"
priority = 95
action = "block"

statement = {
country_codes = ["US"]
}

visibility_config = {
cloudwatch_metrics_enabled = false
sampled_requests_enabled = false
metric_name = "rule-95-metric"
}
}
]

Expand Down
11 changes: 9 additions & 2 deletions rules.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ locals {
for rule in flatten(var.geo_allowlist_statement_rules) :
format("%s-%s",
lookup(rule, "name", null) != null ? rule.name : format("%s-geo-allowlist-%d", module.this.id, rule.priority),
"block",
rule.action,
) => rule
} : {}

Expand Down Expand Up @@ -271,7 +271,14 @@ resource "aws_wafv2_web_acl" "default" {
priority = rule.value.priority

action {
block {}
dynamic "block" {
for_each = rule.value.action == "block" ? [1] : []
content {}
}
dynamic "count" {
for_each = rule.value.action == "count" ? [1] : []
content {}
}
}

# `geo_allowlist_statement_rules` is a special case where we use `not_statement` to wrap our `statement` block to support
Expand Down
3 changes: 3 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ variable "geo_allowlist_statement_rules" {
type = list(object({
name = string
priority = number
action = string
captcha_config = optional(object({
immunity_time_property = object({
immunity_time = number
Expand All @@ -171,6 +172,8 @@ variable "geo_allowlist_statement_rules" {
description = <<-DOC
A rule statement used to identify a list of allowed countries which should not be blocked by the WAF.

action:
The action that AWS WAF should take on a web request when it matches the rule's statement.
name:
A friendly name of the rule.
priority:
Expand Down