Skip to content

Commit

Permalink
Merge pull request #1270 from UKHSA-Internal/task/add-ip-allow-list-t…
Browse files Browse the repository at this point in the history
…o-cms/CDD-2513

Apply IP allow list to CMS application regardless of environment type
  • Loading branch information
A-Ashiq authored Mar 3, 2025
2 parents 7e6a7ce + f20b29b commit 6d52cba
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 26 deletions.
86 changes: 60 additions & 26 deletions terraform/20-app/waf.cms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,42 @@ resource "aws_wafv2_web_acl" "cms_admin" {
description = "Web ACL for CMS application"
scope = "REGIONAL"

default_action {
allow {}
lifecycle {
create_before_destroy = true
}

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

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

override_action {
none {}
default_action {
dynamic "block" {
for_each = [""]
content {
}

statement {
managed_rule_group_statement {
name = rule.value.name
vendor_name = "AWS"
}
}
dynamic "allow" {
for_each = []
content {
}
}
}

visibility_config {
metric_name = rule.value.name
cloudwatch_metrics_enabled = true
sampled_requests_enabled = true
rule {
name = "ip-allowlist"
priority = 0

action {
allow {}
}

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 +89,38 @@ resource "aws_wafv2_web_acl" "cms_admin" {
sampled_requests_enabled = true
}
}

dynamic "rule" {
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)
)
}

0 comments on commit 6d52cba

Please sign in to comment.