Skip to content

Commit df10f7b

Browse files
authored
feat: Allow more than 5 CIDRs in whitelist_unauthenticated_cidr_blocks (#220)
1 parent 89c5b4e commit df10f7b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

main.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ locals {
104104
)
105105

106106
policies_arn = var.policies_arn != null ? var.policies_arn : ["arn:${data.aws_partition.current.partition}:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"]
107+
108+
# Chunk these into groups of 5, the limit for IPs in an AWS lb listener
109+
whitelist_unauthenticated_cidr_block_chunks = chunklist(
110+
sort(compact(concat(var.allow_github_webhooks ? var.github_webhooks_cidr_blocks : [], var.whitelist_unauthenticated_cidr_blocks))),
111+
5
112+
)
107113
}
108114

109115
data "aws_partition" "current" {}
@@ -257,10 +263,10 @@ module "alb" {
257263

258264
# Forward action for certain CIDR blocks to bypass authentication (eg. GitHub webhooks)
259265
resource "aws_lb_listener_rule" "unauthenticated_access_for_cidr_blocks" {
260-
count = var.allow_unauthenticated_access ? 1 : 0
266+
count = var.allow_unauthenticated_access ? length(local.whitelist_unauthenticated_cidr_block_chunks) : 0
261267

262268
listener_arn = module.alb.https_listener_arns[0]
263-
priority = var.allow_unauthenticated_access_priority
269+
priority = var.allow_unauthenticated_access_priority + count.index
264270

265271
action {
266272
type = "forward"
@@ -269,7 +275,7 @@ resource "aws_lb_listener_rule" "unauthenticated_access_for_cidr_blocks" {
269275

270276
condition {
271277
source_ip {
272-
values = sort(compact(concat(var.allow_github_webhooks ? var.github_webhooks_cidr_blocks : [], var.whitelist_unauthenticated_cidr_blocks)))
278+
values = local.whitelist_unauthenticated_cidr_block_chunks[count.index]
273279
}
274280
}
275281
}

0 commit comments

Comments
 (0)