-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rules): add size constraint statement (#41)
* feat(rules): add size constraint statement Signed-off-by: Felipe Zipitria <[email protected]> * feat(terratest): add tests to sizeconstraint statement Signed-off-by: Felipe Zipitria <[email protected]> * fix(ci): update go modules to fix terratest in GHA Signed-off-by: Felipe Zipitria <[email protected]>
- Loading branch information
Showing
8 changed files
with
1,062 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
provider "aws" { | ||
region = "eu-west-1" | ||
} | ||
|
||
##### | ||
# Web Application Firewall configuration | ||
##### | ||
module "waf" { | ||
source = "../.." | ||
|
||
name_prefix = var.name_prefix | ||
|
||
allow_default_action = true | ||
|
||
scope = "REGIONAL" | ||
|
||
create_alb_association = false | ||
|
||
visibility_config = { | ||
cloudwatch_metrics_enabled = false | ||
metric_name = "${var.name_prefix}-waf-setup-waf-main-metrics" | ||
sampled_requests_enabled = false | ||
} | ||
|
||
rules = [ | ||
{ | ||
name = "AWSManagedRulesCommonRuleSet-rule-1" | ||
priority = "1" | ||
|
||
override_action = "none" | ||
|
||
visibility_config = { | ||
cloudwatch_metrics_enabled = false | ||
metric_name = "AWSManagedRulesCommonRuleSet-metric" | ||
sampled_requests_enabled = false | ||
} | ||
|
||
managed_rule_group_statement = { | ||
name = "AWSManagedRulesCommonRuleSet" | ||
vendor_name = "AWS" | ||
excluded_rule = [ | ||
"SizeRestrictions_QUERYSTRING", | ||
"SizeRestrictions_BODY", | ||
"GenericRFI_QUERYARGUMENTS" | ||
] | ||
} | ||
}, | ||
{ | ||
name = "block-specific-uri-path" | ||
priority = "2" | ||
action = "block" | ||
|
||
byte_match_statement = { | ||
field_to_match = { | ||
uri_path = "{}" | ||
} | ||
positional_constraint = "STARTS_WITH" | ||
search_string = "/path/to/match" | ||
priority = 0 | ||
type = "NONE" # The text transformation type | ||
} | ||
|
||
visibility_config = { | ||
cloudwatch_metrics_enabled = false | ||
sampled_requests_enabled = false | ||
} | ||
}, | ||
{ | ||
name = "block-if-request-body-contains-hotmail-email" | ||
priority = "3" | ||
action = "block" | ||
|
||
byte_match_statement = { | ||
field_to_match = { | ||
body = "{}" | ||
} | ||
positional_constraint = "CONTAINS" | ||
search_string = "@hotmail.com" | ||
priority = 0 | ||
type = "NONE" # The text transformation type | ||
} | ||
|
||
visibility_config = { | ||
cloudwatch_metrics_enabled = false | ||
sampled_requests_enabled = false | ||
} | ||
}, | ||
{ | ||
name = "block-all-post-requests" | ||
priority = "4" | ||
action = "block" | ||
|
||
byte_match_statement = { | ||
field_to_match = { | ||
method = "{}" | ||
} | ||
positional_constraint = "EXACTLY" | ||
search_string = "post" | ||
priority = 0 | ||
type = "LOWERCASE" # The text transformation type | ||
} | ||
|
||
visibility_config = { | ||
cloudwatch_metrics_enabled = false | ||
sampled_requests_enabled = false | ||
} | ||
}, | ||
{ | ||
# Blocks a single user by checking the username header | ||
name = "block-single-user" | ||
priority = "5" | ||
action = "block" | ||
|
||
byte_match_statement = { | ||
field_to_match = { | ||
single_header = { | ||
name = "Username" | ||
} | ||
} | ||
positional_constraint = "EXACTLY" | ||
search_string = "testuser" | ||
priority = 0 | ||
type = "LOWERCASE" # The text transformation type | ||
} | ||
|
||
visibility_config = { | ||
cloudwatch_metrics_enabled = false | ||
sampled_requests_enabled = false | ||
} | ||
}, | ||
{ | ||
name = "BodySizeConstraint" | ||
priority = 0 | ||
size_constraint_statement = { | ||
field_to_match = { | ||
body = "{}" | ||
} | ||
comparison_operator = "GT" | ||
size = 8192 | ||
priority = 0 | ||
type = "NONE" | ||
|
||
} | ||
|
||
action = "block" | ||
|
||
visibility_config = { | ||
cloudwatch_metrics_enabled = true | ||
metric_name = "BodySizeConstraint" | ||
sampled_requests_enabled = true | ||
} | ||
}, | ||
] | ||
|
||
tags = { | ||
"Environment" = "test" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
output "web_acl_name" { | ||
description = "The name of the WAFv2 WebACL." | ||
value = module.waf.web_acl_name | ||
} | ||
|
||
output "web_acl_arn" { | ||
description = "The ARN of the WAFv2 WebACL." | ||
value = module.waf.web_acl_arn | ||
} | ||
|
||
output "web_acl_capacity" { | ||
description = "The web ACL capacity units (WCUs) currently being used by this web ACL." | ||
value = module.waf.web_acl_capacity | ||
} | ||
|
||
output "web_acl_visibility_config_name" { | ||
description = "The web ACL visibility config name" | ||
value = module.waf.web_acl_visibility_config_name | ||
} | ||
|
||
output "web_acl_rule_names" { | ||
description = "List of created rule names" | ||
value = module.waf.web_acl_rule_names | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
variable "name_prefix" { | ||
description = "A prefix used for naming resources." | ||
type = string | ||
default = "example" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.