Skip to content

Commit bec2827

Browse files
committed
tighten security groups and add ipv6
1 parent d1a82bc commit bec2827

File tree

4 files changed

+69
-56
lines changed

4 files changed

+69
-56
lines changed

terraform/auth.tf

+9-8
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,17 @@ resource "aws_security_group" "auth" {
163163
vpc_id = aws_vpc.default.id
164164

165165
ingress {
166-
from_port = 0
167-
to_port = 0
168-
protocol = "-1"
169-
cidr_blocks = ["0.0.0.0/0"]
166+
from_port = 0
167+
to_port = 0
168+
protocol = "-1"
169+
security_groups = [aws_security_group.traefik.id]
170170
}
171171

172172
egress {
173-
from_port = 0
174-
to_port = 0
175-
protocol = "-1"
176-
cidr_blocks = ["0.0.0.0/0"]
173+
from_port = 0
174+
to_port = 0
175+
protocol = "-1"
176+
cidr_blocks = ["0.0.0.0/0"]
177+
ipv6_cidr_blocks = ["::/0"]
177178
}
178179
}

terraform/ctfd.tf

+9-9
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,17 @@ resource "aws_security_group" "ctfd" {
281281
vpc_id = aws_vpc.default.id
282282

283283
ingress {
284-
from_port = 0
285-
to_port = 0
286-
protocol = "-1"
287-
# security_groups = [aws_security_group.traefik.id]
288-
cidr_blocks = ["0.0.0.0/0"]
284+
from_port = 0
285+
to_port = 0
286+
protocol = "-1"
287+
security_groups = [aws_security_group.traefik.id]
289288
}
290289

291290
egress {
292-
from_port = 0
293-
to_port = 0
294-
protocol = "-1"
295-
cidr_blocks = ["0.0.0.0/0"]
291+
from_port = 0
292+
to_port = 0
293+
protocol = "-1"
294+
cidr_blocks = ["0.0.0.0/0"]
295+
ipv6_cidr_blocks = ["::/0"]
296296
}
297297
}

terraform/networking.tf

+21-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
resource "aws_vpc" "default" {
2-
cidr_block = "10.0.0.0/16"
3-
enable_dns_support = true
4-
enable_dns_hostnames = true
2+
cidr_block = "10.0.0.0/16"
3+
assign_generated_ipv6_cidr_block = true
4+
enable_dns_support = true
5+
enable_dns_hostnames = true
56

67
tags = {
78
Name = local.name
@@ -17,9 +18,10 @@ resource "aws_internet_gateway" "default" {
1718
}
1819

1920
resource "aws_subnet" "public" {
20-
vpc_id = aws_vpc.default.id
21-
cidr_block = "10.0.1.0/24"
22-
availability_zone = local.availability_zone
21+
vpc_id = aws_vpc.default.id
22+
cidr_block = "10.0.1.0/24"
23+
ipv6_cidr_block = cidrsubnet(aws_vpc.default.ipv6_cidr_block, 8, 1)
24+
availability_zone = local.availability_zone
2325

2426
tags = {
2527
Name = "${local.name}-public"
@@ -30,13 +32,13 @@ resource "aws_route_table" "public" {
3032
vpc_id = aws_vpc.default.id
3133

3234
route {
33-
ipv6_cidr_block = "::/0"
34-
gateway_id = aws_internet_gateway.default.id
35+
cidr_block = "0.0.0.0/0"
36+
gateway_id = aws_internet_gateway.default.id
3537
}
3638

3739
route {
38-
cidr_block = "0.0.0.0/0"
39-
gateway_id = aws_internet_gateway.default.id
40+
ipv6_cidr_block = "::/0"
41+
gateway_id = aws_internet_gateway.default.id
4042
}
4143

4244
tags = {
@@ -50,9 +52,10 @@ resource "aws_route_table_association" "public" {
5052
}
5153

5254
resource "aws_subnet" "private" {
53-
vpc_id = aws_vpc.default.id
54-
cidr_block = "10.0.0.0/24"
55-
availability_zone = local.availability_zone
55+
vpc_id = aws_vpc.default.id
56+
cidr_block = "10.0.0.0/24"
57+
ipv6_cidr_block = cidrsubnet(aws_vpc.default.ipv6_cidr_block, 8, 0)
58+
availability_zone = local.availability_zone
5659

5760
tags = {
5861
Name = "${local.name}-private"
@@ -73,6 +76,11 @@ resource "aws_route_table" "private" {
7376
network_interface_id = aws_instance.traefik.primary_network_interface_id
7477
}
7578

79+
route {
80+
ipv6_cidr_block = "::/0"
81+
network_interface_id = aws_instance.traefik.primary_network_interface_id
82+
}
83+
7684
tags = {
7785
Name = "${local.name}-private"
7886
}

terraform/traefik.tf

+30-26
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resource "aws_eip" "traefik" {
44
tags = {
55
Name = "${local.name}-traefik"
66
}
7-
depends_on = [ aws_internet_gateway.default ]
7+
depends_on = [aws_internet_gateway.default]
88
}
99

1010
resource "aws_instance" "traefik" {
@@ -15,8 +15,9 @@ resource "aws_instance" "traefik" {
1515
iam_instance_profile = aws_iam_instance_profile.ecs_instance.name
1616
vpc_security_group_ids = [aws_security_group.traefik.id]
1717
source_dest_check = false
18-
associate_public_ip_address = false
18+
associate_public_ip_address = true
1919
user_data_replace_on_change = true
20+
ipv6_addresses = [cidrhost(aws_subnet.public.ipv6_cidr_block, 4)]
2021

2122
root_block_device {
2223
volume_type = "gp3"
@@ -35,6 +36,7 @@ resource "aws_instance" "traefik" {
3536
echo "ECS_CLUSTER=${aws_ecs_cluster.default.name}" > /etc/ecs/ecs.config
3637
3738
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
39+
echo "net.ipv6.conf.all.forwarding=1" >> /etc/sysctl.conf
3840
sysctl -p
3941
4042
cat <<EOF > /etc/systemd/system/nat-setup.service
@@ -142,8 +144,8 @@ resource "aws_ecs_task_definition" "traefik" {
142144
logDriver = "awslogs"
143145
options = {
144146
"awslogs-group" = aws_cloudwatch_log_group.default.name
145-
"awslogs-region" = local.region,
146-
"awslogs-stream-prefix" = "traefik",
147+
"awslogs-region" = local.region
148+
"awslogs-stream-prefix" = "traefik"
147149
}
148150
}
149151

@@ -193,34 +195,27 @@ resource "aws_security_group" "traefik" {
193195
vpc_id = aws_vpc.default.id
194196

195197
ingress {
196-
from_port = 80
197-
to_port = 80
198-
protocol = "tcp"
199-
security_groups = []
200-
cidr_blocks = ["0.0.0.0/0"]
198+
from_port = 80
199+
to_port = 80
200+
protocol = "tcp"
201+
cidr_blocks = ["0.0.0.0/0"]
202+
ipv6_cidr_blocks = ["::/0"]
201203
}
202204

203205
ingress {
204-
from_port = 443
205-
to_port = 443
206-
protocol = "tcp"
207-
security_groups = []
208-
cidr_blocks = ["0.0.0.0/0"]
209-
}
210-
211-
ingress {
212-
from_port = 22
213-
to_port = 22
214-
protocol = "tcp"
215-
security_groups = []
216-
cidr_blocks = ["0.0.0.0/0"]
206+
from_port = 443
207+
to_port = 443
208+
protocol = "tcp"
209+
cidr_blocks = ["0.0.0.0/0"]
210+
ipv6_cidr_blocks = ["::/0"]
217211
}
218212

219213
egress {
220-
from_port = 0
221-
to_port = 0
222-
protocol = "-1"
223-
cidr_blocks = ["0.0.0.0/0"]
214+
from_port = 0
215+
to_port = 0
216+
protocol = "-1"
217+
cidr_blocks = ["0.0.0.0/0"]
218+
ipv6_cidr_blocks = ["::/0"]
224219
}
225220
}
226221

@@ -324,3 +319,12 @@ resource "aws_route53_record" "wildcard_a" {
324319
ttl = 300
325320
records = [aws_eip.traefik.public_ip]
326321
}
322+
323+
resource "aws_route53_record" "wildcard_aaaa" {
324+
count = 1
325+
zone_id = local.domain_zone_id
326+
name = "*.testing.${local.domain}"
327+
type = "AAAA"
328+
ttl = 300
329+
records = [aws_instance.traefik.ipv6_addresses[0]]
330+
}

0 commit comments

Comments
 (0)