Skip to content

Commit d98b55a

Browse files
mattgodboltclaude
andauthored
Separate conan traffic to dedicated internal ALB (#1868)
Co-authored-by: Claude <[email protected]>
1 parent 5503e12 commit d98b55a

File tree

4 files changed

+76
-18
lines changed

4 files changed

+76
-18
lines changed

terraform/alb.tf

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ resource "aws_alb" "GccExplorerApp" {
1616
}
1717
}
1818

19+
resource "aws_alb" "InternalServices" {
20+
idle_timeout = 60
21+
internal = false
22+
name = "InternalServices"
23+
security_groups = [
24+
aws_security_group.InternalServicesAlb.id
25+
]
26+
subnets = local.all_subnet_ids
27+
28+
enable_deletion_protection = false
29+
30+
access_logs {
31+
bucket = aws_s3_bucket.compiler-explorer-logs.bucket
32+
prefix = "elb-internal"
33+
enabled = true
34+
}
35+
}
36+
1937
resource "aws_alb_listener" "compiler-explorer-alb-listen-http" {
2038
lifecycle {
2139
# Ignore changes to the default_action since it's managed by blue-green deployment
@@ -239,7 +257,7 @@ resource "aws_alb_listener" "ceconan-alb-listen-http" {
239257
target_group_arn = aws_alb_target_group.conan.arn
240258
}
241259

242-
load_balancer_arn = aws_alb.GccExplorerApp.arn
260+
load_balancer_arn = aws_alb.InternalServices.arn
243261
port = 1080
244262
protocol = "HTTP"
245263
}
@@ -249,7 +267,7 @@ resource "aws_alb_listener" "ceconan-alb-listen-https" {
249267
type = "forward"
250268
target_group_arn = aws_alb_target_group.conan.arn
251269
}
252-
load_balancer_arn = aws_alb.GccExplorerApp.arn
270+
load_balancer_arn = aws_alb.InternalServices.arn
253271
port = 1443
254272
protocol = "HTTPS"
255273
ssl_policy = "ELBSecurityPolicy-2015-05"

terraform/cloudfront_conan.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ resource "aws_cloudfront_distribution" "conan-compiler-explorer-com" {
44
origin_id = "S3-compiler-explorer"
55
}
66
origin {
7-
domain_name = aws_alb.GccExplorerApp.dns_name
8-
origin_id = "GccExplorerApp"
7+
domain_name = aws_alb.InternalServices.dns_name
8+
origin_id = "InternalServices"
99
custom_origin_config {
1010
http_port = 1080
1111
https_port = 1443
@@ -77,7 +77,7 @@ resource "aws_cloudfront_distribution" "conan-compiler-explorer-com" {
7777
"*"
7878
]
7979
}
80-
target_origin_id = "GccExplorerApp"
80+
target_origin_id = "InternalServices"
8181
viewer_protocol_policy = "redirect-to-https"
8282
compress = true
8383
}

terraform/s3.tf

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ resource "aws_s3_bucket_lifecycle_configuration" "compiler-explorer-logs" {
109109
dynamic "rule" {
110110
# Keep only one month of these logs (See the privacy policy in the compiler explorer project)
111111
for_each = {
112-
cloudfront = "cloudfront"
113-
elb = "elb"
112+
cloudfront = "cloudfront"
113+
elb = "elb"
114+
elb-internal = "elb-internal"
114115
}
115116
content {
116117
id = "delete_${rule.value}_per_log_policy"
@@ -202,9 +203,12 @@ data "aws_iam_policy_document" "compiler-explorer-logs-s3-policy" {
202203
identifiers = ["arn:aws:iam::127311923021:root"]
203204
type = "AWS"
204205
}
205-
sid = "Allow ELB to write logs"
206-
actions = ["s3:PutObject"]
207-
resources = ["${aws_s3_bucket.compiler-explorer-logs.arn}/elb/*"]
206+
sid = "Allow ELB to write logs"
207+
actions = ["s3:PutObject"]
208+
resources = [
209+
"${aws_s3_bucket.compiler-explorer-logs.arn}/elb/*",
210+
"${aws_s3_bucket.compiler-explorer-logs.arn}/elb-internal/*"
211+
]
208212
}
209213
}
210214

terraform/security.tf

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ resource "aws_security_group_rule" "CE_ConanHttpFromAlb" {
6767
type = "ingress"
6868
from_port = 1080
6969
to_port = 1080
70-
source_security_group_id = aws_security_group.CompilerExplorerAlb.id
70+
source_security_group_id = aws_security_group.InternalServicesAlb.id
7171
protocol = "tcp"
72-
description = "Allow HTTP access from the ALB"
72+
description = "Allow HTTP access from the internal services ALB"
7373
}
7474

7575
resource "aws_security_group_rule" "CE_HttpsFromAlb" {
@@ -87,9 +87,9 @@ resource "aws_security_group_rule" "CE_ConanHttpsFromAlb" {
8787
type = "ingress"
8888
from_port = 1443
8989
to_port = 1443
90-
source_security_group_id = aws_security_group.CompilerExplorerAlb.id
90+
source_security_group_id = aws_security_group.InternalServicesAlb.id
9191
protocol = "tcp"
92-
description = "Allow HTTPS access from the ALB"
92+
description = "Allow HTTPS access from the internal services ALB"
9393
}
9494

9595
resource "aws_security_group" "CompilerExplorerAlb" {
@@ -101,6 +101,15 @@ resource "aws_security_group" "CompilerExplorerAlb" {
101101
}
102102
}
103103

104+
resource "aws_security_group" "InternalServicesAlb" {
105+
vpc_id = module.ce_network.vpc.id
106+
name = "internal-services-alb-sg"
107+
description = "Security group for internal services load balancer (conan, etc)"
108+
tags = {
109+
Name = "InternalServicesLoadBalancer"
110+
}
111+
}
112+
104113
resource "aws_security_group_rule" "ALB_HttpsFromAnywhere" {
105114
security_group_id = aws_security_group.CompilerExplorerAlb.id
106115
type = "ingress"
@@ -112,19 +121,46 @@ resource "aws_security_group_rule" "ALB_HttpsFromAnywhere" {
112121
description = "Allow HTTPS access from anywhere"
113122
}
114123

115-
resource "aws_security_group_rule" "ALB_ConanHttpsFromAnywhere" {
124+
resource "aws_security_group_rule" "ALB_EgressToAnywhere" {
116125
security_group_id = aws_security_group.CompilerExplorerAlb.id
126+
type = "egress"
127+
from_port = 0
128+
to_port = 65535
129+
cidr_blocks = ["0.0.0.0/0"]
130+
ipv6_cidr_blocks = ["::/0"]
131+
protocol = "-1"
132+
description = "Allow egress to anywhere"
133+
}
134+
135+
# TODO: Consider restricting these ports to CloudFront IP ranges only for better security.
136+
# Can use AWS managed prefix list: prefix_list_ids = ["pl-3b927c52"] instead of cidr_blocks.
137+
# Ports 1080/1443 are only used by conan via CloudFront, so there's no legitimate direct access.
138+
# Check with CE team before tightening to ensure no one is using direct ALB access for debugging.
139+
140+
resource "aws_security_group_rule" "InternalALB_ConanHttpsFromAnywhere" {
141+
security_group_id = aws_security_group.InternalServicesAlb.id
117142
type = "ingress"
118143
from_port = 1443
119144
to_port = 1443
120145
cidr_blocks = ["0.0.0.0/0"]
121146
ipv6_cidr_blocks = ["::/0"]
122147
protocol = "tcp"
123-
description = "Allow HTTPS access from anywhere"
148+
description = "Allow HTTPS access from anywhere (port 1443 for conan)"
124149
}
125150

126-
resource "aws_security_group_rule" "ALB_EgressToAnywhere" {
127-
security_group_id = aws_security_group.CompilerExplorerAlb.id
151+
resource "aws_security_group_rule" "InternalALB_ConanHttpFromAnywhere" {
152+
security_group_id = aws_security_group.InternalServicesAlb.id
153+
type = "ingress"
154+
from_port = 1080
155+
to_port = 1080
156+
cidr_blocks = ["0.0.0.0/0"]
157+
ipv6_cidr_blocks = ["::/0"]
158+
protocol = "tcp"
159+
description = "Allow HTTP access from anywhere (port 1080 for conan)"
160+
}
161+
162+
resource "aws_security_group_rule" "InternalALB_EgressToAnywhere" {
163+
security_group_id = aws_security_group.InternalServicesAlb.id
128164
type = "egress"
129165
from_port = 0
130166
to_port = 65535

0 commit comments

Comments
 (0)