Skip to content

Commit

Permalink
Merge pull request #11 from unity-sds/431-lockdown-ecs-alb-shared-ser…
Browse files Browse the repository at this point in the history
…vices

Lockdown ECS ALB to only allow Shared Services connections
  • Loading branch information
jpl-btlunsfo authored Jan 22, 2025
2 parents 62fb117 + d0043c4 commit ff8fc11
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions terraform-unity/networking.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Create an Application Load Balancer (ALB)
resource "aws_lb" "httpd_alb" {
name = "${var.project}-${var.venue}-httpd-alb"
internal = false
internal = true
load_balancer_type = "application"
security_groups = [aws_security_group.ecs_alb_sg.id]
subnets = local.public_subnet_ids
subnets = local.subnet_ids
enable_deletion_protection = false
preserve_host_header = true
tags = {
Expand Down Expand Up @@ -110,16 +110,6 @@ resource "aws_vpc_security_group_ingress_rule" "ecs_alb_ingress_sg_rule" {
referenced_security_group_id = aws_security_group.ecs_alb_sg.id
}

# Add a new ingress rule to the ECS ALB's security group, opening it up to other connections
#tfsec:ignore:AVD-AWS-0107
resource "aws_vpc_security_group_ingress_rule" "alb_all_ingress_sg_rule" {
security_group_id = aws_security_group.ecs_alb_sg.id
to_port = 8080
from_port = 8080
ip_protocol = "tcp"
cidr_ipv4 = "0.0.0.0/0"
}

# Add a new egress rule to the ECS's security group, allowing ECS to fetch the container images/proxy
resource "aws_vpc_security_group_egress_rule" "ecs_egress_sg_rule" {
security_group_id = aws_security_group.ecs_sg.id
Expand All @@ -137,3 +127,23 @@ resource "aws_vpc_security_group_egress_rule" "ecs_alb_egress_sg_rule" {
ip_protocol = "tcp"
cidr_ipv4 = "0.0.0.0/0"
}

data "aws_ssm_parameter" "shared-services_security_group" {
name = "arn:aws:ssm:${data.aws_ssm_parameter.shared_service_region.value}:${data.aws_ssm_parameter.shared_service_account_id.value}:parameter/unity/shared-services/network/httpd_security_group"
}

resource "aws_vpc_security_group_ingress_rule" "ecs_alb_sg_ingress_rule" {
security_group_id = aws_security_group.ecs_alb_sg.id
from_port = 8080
to_port = 8080
ip_protocol = "tcp"
referenced_security_group_id = data.aws_ssm_parameter.shared-services_security_group.value
}

resource "aws_vpc_security_group_egress_rule" "ecs_sg_egress_rule" {
security_group_id = aws_security_group.ecs_sg.id
from_port = 0
to_port = 65535
ip_protocol = "tcp"
referenced_security_group_id = data.aws_security_group.mc_alb_sg.id
}

0 comments on commit ff8fc11

Please sign in to comment.