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

Apply IP allow list to CMS application regardless of environment type #1270

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
82 changes: 56 additions & 26 deletions terraform/20-app/waf.cms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,37 @@ resource "aws_wafv2_web_acl" "cms_admin" {
scope = "REGIONAL"

default_action {
allow {}
dynamic "block" {
for_each = [""]
content {
}
}
dynamic "allow" {
for_each = []
content {
}
}
}

dynamic "rule" {
for_each = local.waf_cms_admin.rules

content {
name = rule.value.name
priority = rule.value.priority

override_action {
none {}
}
rule {
name = "ip-allowlist"
priority = 0

statement {
managed_rule_group_statement {
name = rule.value.name
vendor_name = "AWS"
}
}
action {
allow {}
}

visibility_config {
metric_name = rule.value.name
cloudwatch_metrics_enabled = true
sampled_requests_enabled = true
statement {
ip_set_reference_statement {
arn = aws_wafv2_ip_set.ip_allow_list_regional.arn
}
}
}

visibility_config {
metric_name = "${local.prefix}-cms"
cloudwatch_metrics_enabled = true
sampled_requests_enabled = true
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "IPAllowListRule"
sampled_requests_enabled = true
}
}

rule {
Expand Down Expand Up @@ -87,6 +85,38 @@ resource "aws_wafv2_web_acl" "cms_admin" {
sampled_requests_enabled = true
}
}

dynamic "rule" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just moved down

for_each = local.waf_cms_admin.rules

content {
name = rule.value.name
priority = rule.value.priority

override_action {
none {}
}

statement {
managed_rule_group_statement {
name = rule.value.name
vendor_name = "AWS"
}
}

visibility_config {
metric_name = rule.value.name
cloudwatch_metrics_enabled = true
sampled_requests_enabled = true
}
}
}

visibility_config {
metric_name = "${local.prefix}-cms"
cloudwatch_metrics_enabled = true
sampled_requests_enabled = true
}
}

resource "aws_wafv2_web_acl_association" "cms_admin" {
Expand Down
10 changes: 10 additions & 0 deletions terraform/20-app/waf.ip-allow-set.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ resource "aws_wafv2_ip_set" "ip_allow_list" {
formatlist("%s/32", module.vpc.nat_public_ips)
)
}

resource "aws_wafv2_ip_set" "ip_allow_list_regional" {
name = "${local.prefix}-ip-allow-list-regional"
scope = "REGIONAL"
ip_address_version = "IPV4"
addresses = concat(
local.complete_ip_allow_list,
formatlist("%s/32", module.vpc.nat_public_ips)
)
}