Initial support for bypassing URLs on the allowlist (#94)
This commit is contained in:
1 parent
e9f841e1b2
commit
e1527926dc
3 files changed
+66
-8
No files matched your search
@@ -9,7 +9,7 @@ No requirements.
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.9.0 |
|
||||
|
||||
## Modules
|
||||
|
||||
@@ -19,8 +19,11 @@ No modules.
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [aws_wafv2_ip_set.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_ip_set) | resource |
|
||||
| [aws_wafv2_rule_group.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_rule_group) | resource |
|
||||
| [aws_wafv2_ip_set.allowed](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_ip_set) | resource |
|
||||
| [aws_wafv2_ip_set.blocked](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_ip_set) | resource |
|
||||
| [aws_wafv2_regex_pattern_set.bypass_urls](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_regex_pattern_set) | resource |
|
||||
| [aws_wafv2_rule_group.allowed](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_rule_group) | resource |
|
||||
| [aws_wafv2_rule_group.blocked](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_rule_group) | resource |
|
||||
| [aws_wafv2_web_acl.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_web_acl) | resource |
|
||||
| [aws_wafv2_web_acl_association.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_web_acl_association) | resource |
|
||||
|
||||
@@ -28,10 +31,14 @@ No modules.
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_allowed_addresses"></a> [allowed\_addresses](#input\_allowed\_addresses) | n/a | `list(string)` | `[]` | no |
|
||||
| <a name="input_blocked_addresses"></a> [blocked\_addresses](#input\_blocked\_addresses) | n/a | `list(string)` | `[]` | no |
|
||||
| <a name="input_blocked_countries"></a> [blocked\_countries](#input\_blocked\_countries) | n/a | `list(string)` | <pre>[<br> "BI",<br> "BY",<br> "CD",<br> "CF",<br> "CU",<br> "IQ",<br> "IR",<br> "LB",<br> "LY",<br> "SD",<br> "SO",<br> "SS",<br> "SY",<br> "VE",<br> "ZW",<br> "RU"<br>]</pre> | no |
|
||||
| <a name="input_blocked_countries"></a> [blocked\_countries](#input\_blocked\_countries) | n/a | `list(string)` | <pre>[<br/> "BI",<br/> "BY",<br/> "CD",<br/> "CF",<br/> "CU",<br/> "IQ",<br/> "IR",<br/> "LB",<br/> "LY",<br/> "SD",<br/> "SO",<br/> "SS",<br/> "SY",<br/> "VE",<br/> "ZW",<br/> "RU"<br/>]</pre> | no |
|
||||
| <a name="input_bypass_urls"></a> [bypass\_urls](#input\_bypass\_urls) | Optional list of regex patterns for URL paths that bypass the IP allowlist WAF rule.<br/>The patterns must be valid AWS WAF regex strings. | `list(string)` | `[]` | no |
|
||||
| <a name="input_capacity"></a> [capacity](#input\_capacity) | The capacity required to handle the rules. | `number` | `2` | no |
|
||||
| <a name="input_lb_arn"></a> [lb\_arn](#input\_lb\_arn) | n/a | `any` | n/a | yes |
|
||||
| <a name="input_name"></a> [name](#input\_name) | n/a | `any` | n/a | yes |
|
||||
| <a name="input_waf_type"></a> [waf\_type](#input\_waf\_type) | n/a | `string` | `"blocklist"` | no |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
||||
+40
-4
@@ -6,7 +6,7 @@ resource "aws_wafv2_rule_group" "blocked" {
|
||||
count = var.waf_type == "blocklist" ? 1 : 0
|
||||
name = var.name
|
||||
scope = "REGIONAL"
|
||||
capacity = 2
|
||||
capacity = var.capacity
|
||||
|
||||
rule {
|
||||
name = "countries"
|
||||
@@ -69,7 +69,7 @@ resource "aws_wafv2_rule_group" "allowed" {
|
||||
count = var.waf_type == "allowlist" ? 1 : 0
|
||||
name = var.name
|
||||
scope = "REGIONAL"
|
||||
capacity = 2
|
||||
capacity = var.capacity
|
||||
|
||||
rule {
|
||||
name = "specific"
|
||||
@@ -80,8 +80,30 @@ resource "aws_wafv2_rule_group" "allowed" {
|
||||
}
|
||||
|
||||
statement {
|
||||
ip_set_reference_statement {
|
||||
arn = aws_wafv2_ip_set.allowed[0].arn
|
||||
or_statement {
|
||||
# Dynamic bypass regex statements
|
||||
dynamic "statement" {
|
||||
for_each = length(var.bypass_urls) > 0 ? [1] : []
|
||||
content {
|
||||
regex_pattern_set_reference_statement {
|
||||
arn = aws_wafv2_regex_pattern_set.bypass_urls[0].arn
|
||||
|
||||
field_to_match {
|
||||
uri_path {}
|
||||
}
|
||||
|
||||
text_transformation {
|
||||
priority = 0
|
||||
type = "NONE"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
statement {
|
||||
ip_set_reference_statement {
|
||||
arn = aws_wafv2_ip_set.allowed[0].arn
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +172,20 @@ resource "aws_wafv2_ip_set" "allowed" {
|
||||
addresses = var.allowed_addresses
|
||||
}
|
||||
|
||||
resource "aws_wafv2_regex_pattern_set" "bypass_urls" {
|
||||
# Only works for allowlists
|
||||
count = length(var.bypass_urls) > 0 && var.waf_type == "allowlist" ? 1 : 0
|
||||
|
||||
name = var.name
|
||||
scope = "REGIONAL"
|
||||
|
||||
dynamic "regular_expression" {
|
||||
for_each = toset(var.bypass_urls)
|
||||
content {
|
||||
regex_string = regular_expression.value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_wafv2_web_acl_association" "main" {
|
||||
resource_arn = var.lb_arn
|
||||
|
||||
@@ -21,3 +21,18 @@ variable "allowed_addresses" {
|
||||
type = list(string)
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "capacity" {
|
||||
description = "The capacity required to handle the rules."
|
||||
type = number
|
||||
default = 2
|
||||
}
|
||||
|
||||
variable "bypass_urls" {
|
||||
description = <<EOT
|
||||
Optional list of regex patterns for URL paths that bypass the IP allowlist WAF rule.
|
||||
The patterns must be valid AWS WAF regex strings.
|
||||
EOT
|
||||
type = list(string)
|
||||
default = []
|
||||
}
|
||||
Reference in new issue
Block a user