-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from uc-cdis/feat/GPE-1434
adding terraform for AWS WAF
- Loading branch information
Showing
11 changed files
with
230 additions
and
2 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
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,8 @@ | ||
module "aws_waf" { | ||
source = "../modules/waf" | ||
count = var.deploy_waf ? 1 : 0 | ||
vpc_name = var.vpc_name | ||
base_rules = var.base_rules | ||
additional_rules = var.additional_rules | ||
depends_on = [module.cdis_vpc.vpc_id, module.cdis_vpc.vpc_peering_id] | ||
} |
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,52 @@ | ||
resource "aws_wafv2_web_acl" "waf" { | ||
name = "${var.vpc_name}-waf" | ||
description = "WAF per environment for tailored security." | ||
scope = "REGIONAL" | ||
|
||
default_action { | ||
allow {} | ||
} | ||
|
||
dynamic "rule" { | ||
for_each = concat(var.base_rules, var.additional_rules) | ||
content { | ||
name = "AWS-${rule.value.managed_rule_group_name}" | ||
priority = rule.value.priority | ||
override_action { | ||
none {} | ||
} | ||
statement { | ||
managed_rule_group_statement { | ||
vendor_name = "AWS" | ||
name = rule.value.managed_rule_group_name | ||
|
||
dynamic "rule_action_override" { | ||
for_each = length(rule.value.override_to_count) > 0 ? rule.value.override_to_count : [] | ||
content { | ||
action_to_use { | ||
count {} | ||
} | ||
name = rule_action_override.value | ||
} | ||
} | ||
} | ||
} | ||
|
||
visibility_config { | ||
sampled_requests_enabled = true | ||
cloudwatch_metrics_enabled = true | ||
metric_name = "AWS-${rule.value.managed_rule_group_name}" | ||
} | ||
} | ||
} | ||
|
||
tags = { | ||
Environment = "${var.vpc_name}" | ||
} | ||
|
||
visibility_config { | ||
cloudwatch_metrics_enabled = false | ||
metric_name = "WebAclMetrics" | ||
sampled_requests_enabled = false | ||
} | ||
} |
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,8 @@ | ||
## | ||
# Output WAF arn | ||
## | ||
|
||
output "waf_arn" { | ||
description = "WAF arn - annotate the cluster ingress" | ||
value = aws_wafv2_web_acl.waf.arn | ||
} |
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,37 @@ | ||
variable "vpc_name" {} | ||
|
||
variable "base_rules" { | ||
description = "Base AWS Managed Rules" | ||
type = list(object({ | ||
managed_rule_group_name = string | ||
priority = number | ||
override_to_count = list(string) | ||
})) | ||
default = [ | ||
{ | ||
managed_rule_group_name = "AWSManagedRulesAmazonIpReputationList" | ||
priority = 0 | ||
override_to_count = ["AWSManagedReconnaissanceList"] | ||
}, | ||
{ | ||
managed_rule_group_name = "AWSManagedRulesPHPRuleSet" | ||
priority = 1 | ||
override_to_count = ["PHPHighRiskMethodsVariables_HEADER", "PHPHighRiskMethodsVariables_QUERYSTRING", "PHPHighRiskMethodsVariables_BODY"] | ||
}, | ||
{ | ||
managed_rule_group_name = "AWSManagedRulesWordPressRuleSet" | ||
priority = 2 | ||
override_to_count= ["WordPressExploitableCommands_QUERYSTRING", "WordPressExploitablePaths_URIPATH"] | ||
}, | ||
] | ||
} | ||
|
||
variable "additional_rules" { | ||
description = "Additional AWS Managed Rules" | ||
type = list(object({ | ||
managed_rule_group_name = string | ||
priority = number | ||
override_to_count = list(string) | ||
})) | ||
default = [] | ||
} |
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 @@ | ||
{ | ||
"terraform": { | ||
"module_version" : "1.2" | ||
} | ||
} |
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,8 @@ | ||
## | ||
# Output WAF arn | ||
## | ||
|
||
output "waf_arn" { | ||
description = "WAF arn - annotate the cluster ingress" | ||
value = module.aws_waf[0].waf_arn | ||
} |
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,19 @@ | ||
terraform { | ||
backend "s3" { | ||
encrypt = "true" | ||
} | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.0" | ||
} | ||
} | ||
} | ||
|
||
module "aws_waf" { | ||
source = "../modules/waf" | ||
count = var.deploy_waf ? 1 : 0 | ||
vpc_name = var.vpc_name | ||
base_rules = var.base_rules | ||
additional_rules = var.additional_rules | ||
} |
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,41 @@ | ||
variable "deploy_waf" { | ||
default = false | ||
} | ||
|
||
variable "vpc_name" {} | ||
|
||
variable "base_rules" { | ||
description = "Base AWS Managed Rules" | ||
type = list(object({ | ||
managed_rule_group_name = string | ||
priority = number | ||
override_to_count = list(string) | ||
})) | ||
default = [ | ||
{ | ||
managed_rule_group_name = "AWSManagedRulesAmazonIpReputationList" | ||
priority = 0 | ||
override_to_count = ["AWSManagedReconnaissanceList"] | ||
}, | ||
{ | ||
managed_rule_group_name = "AWSManagedRulesPHPRuleSet" | ||
priority = 1 | ||
override_to_count = ["PHPHighRiskMethodsVariables_HEADER", "PHPHighRiskMethodsVariables_QUERYSTRING", "PHPHighRiskMethodsVariables_BODY"] | ||
}, | ||
{ | ||
managed_rule_group_name = "AWSManagedRulesWordPressRuleSet" | ||
priority = 2 | ||
override_to_count= ["WordPressExploitableCommands_QUERYSTRING", "WordPressExploitablePaths_URIPATH"] | ||
}, | ||
] | ||
} | ||
|
||
variable "additional_rules" { | ||
description = "Additional AWS Managed Rules" | ||
type = list(object({ | ||
managed_rule_group_name = string | ||
priority = number | ||
override_to_count = list(string) | ||
})) | ||
default = [] | ||
} |