Skip to content

Commit 27583a1

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

File tree

4 files changed

+66
-54
lines changed

4 files changed

+66
-54
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

+27-24
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"
@@ -193,34 +194,27 @@ resource "aws_security_group" "traefik" {
193194
vpc_id = aws_vpc.default.id
194195

195196
ingress {
196-
from_port = 80
197-
to_port = 80
198-
protocol = "tcp"
199-
security_groups = []
200-
cidr_blocks = ["0.0.0.0/0"]
197+
from_port = 80
198+
to_port = 80
199+
protocol = "tcp"
200+
cidr_blocks = ["0.0.0.0/0"]
201+
ipv6_cidr_blocks = ["::/0"]
201202
}
202203

203204
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"]
205+
from_port = 443
206+
to_port = 443
207+
protocol = "tcp"
208+
cidr_blocks = ["0.0.0.0/0"]
209+
ipv6_cidr_blocks = ["::/0"]
217210
}
218211

219212
egress {
220-
from_port = 0
221-
to_port = 0
222-
protocol = "-1"
223-
cidr_blocks = ["0.0.0.0/0"]
213+
from_port = 0
214+
to_port = 0
215+
protocol = "-1"
216+
cidr_blocks = ["0.0.0.0/0"]
217+
ipv6_cidr_blocks = ["::/0"]
224218
}
225219
}
226220

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

0 commit comments

Comments
 (0)