Skip to content

Commit 442484c

Browse files
committed
feat: block HTTPS reqeusts except POST
1 parent 14143c4 commit 442484c

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

modules/alb/main.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ resource "aws_lb" "this" {
33
internal = var.load_balancer_internal
44
load_balancer_type = var.load_balancer_type
55
security_groups = [aws_security_group.this.id]
6-
# subnet-1 , subnet-2
7-
subnets = var.public_subnet_ids
6+
subnets = var.public_subnet_ids
87
}
98

109
resource "aws_security_group" "this" {

modules/ecs/main.tf

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ resource "aws_ecs_cluster" "this" {
22
name = var.cluster_name
33
}
44

5-
# extract to iam
65
resource "random_pet" "name" {
76
length = 1
87
separator = "-"
@@ -22,7 +21,6 @@ resource "aws_iam_instance_profile" "this" {
2221
name = "${local.iam_instance_profile_name_prefix}-${random_pet.name.id}"
2322
role = aws_iam_role.instace_role.name
2423
}
25-
#
2624

2725
resource "aws_launch_template" "this" {
2826
name_prefix = var.launch_template_name_prefix
@@ -36,7 +34,6 @@ echo ECS_CLUSTER=${aws_ecs_cluster.this.name} >> /etc/ecs/ecs.config
3634
EOF
3735
)
3836

39-
4037
network_interfaces {
4138
associate_public_ip_address = true
4239
subnet_id = var.private_subnet_ids[0]
@@ -52,7 +49,6 @@ EOF
5249
}
5350
}
5451

55-
5652
resource "aws_autoscaling_group" "this" {
5753
desired_capacity = var.auto_scaling_group_desired_capacity
5854
max_size = var.auto_scaling_group_max_size
@@ -98,6 +94,7 @@ resource "aws_ecs_service" "this" {
9894
}
9995

10096
depends_on = [
97+
aws_lb_listener_rule.events_post_rule,
10198
aws_lb_listener_rule.default_rule,
10299
]
103100
}
@@ -142,8 +139,6 @@ resource "aws_cloudwatch_log_group" "this" {
142139
retention_in_days = 14
143140
}
144141

145-
146-
147142
resource "aws_security_group" "this" {
148143
name = "${var.service_name}-ecs-sg"
149144
description = "${var.service_name} ecs security group"
@@ -200,13 +195,19 @@ resource "aws_lb_target_group" "ip_target" {
200195
}
201196
}
202197

203-
resource "aws_lb_listener_rule" "default_rule" {
198+
resource "aws_lb_listener_rule" "events_post_rule" {
204199
listener_arn = var.endpoint_details.lb_listener_arn
205200
priority = 10
206201

207202
condition {
208-
host_header {
209-
values = [var.endpoint_details.domain_url]
203+
path_pattern {
204+
values = ["/events"]
205+
}
206+
}
207+
208+
condition {
209+
http_request_method {
210+
values = ["POST"]
210211
}
211212
}
212213

@@ -215,3 +216,23 @@ resource "aws_lb_listener_rule" "default_rule" {
215216
target_group_arn = aws_lb_target_group.ip_target[0].arn
216217
}
217218
}
219+
220+
resource "aws_lb_listener_rule" "default_rule" {
221+
listener_arn = var.endpoint_details.lb_listener_arn
222+
priority = 20
223+
224+
condition {
225+
path_pattern {
226+
values = ["/*"]
227+
}
228+
}
229+
230+
action {
231+
type = "fixed-response"
232+
fixed_response {
233+
content_type = "text/plain"
234+
message_body = "Not Found"
235+
status_code = "404"
236+
}
237+
}
238+
}

modules/network/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ variable "private_subnet_cidrs" {
1616
default = ["10.0.3.0/24", "10.0.4.0/24"]
1717
}
1818

19+
variable "region" {
20+
description = "Region for creating resources"
21+
type = string
22+
default = "us-east-1"
23+
}
24+
1925
variable "availability_zones" {
2026
description = "List of Availability zone where the subnet must reside."
2127
type = list(string)

0 commit comments

Comments
 (0)