-
Notifications
You must be signed in to change notification settings - Fork 0
/
access.tf
274 lines (231 loc) · 5 KB
/
access.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
## get total subnets for standard nacl
## see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/guides/version-4-upgrade#data-source-aws_subnet_ids for new >4.0 changes
data "aws_subnets" "total" {
filter {
name = "vpc-id"
values = [aws_vpc.main.id]
}
depends_on = [aws_vpc.main]
}
data "aws_subnet" "total" {
for_each = toset(data.aws_subnets.total.ids)
id = each.value
depends_on = [aws_vpc.main]
}
resource "aws_network_acl" "main-default" {
vpc_id = aws_vpc.main.id
## standard nacl handles all subnets, ext & int
subnet_ids = [for s in data.aws_subnet.total : s.id]
## all outbound allowed
egress {
protocol = -1
rule_no = 100
action = "allow"
cidr_block = "0.0.0.0/0"
from_port = 0
to_port = 0
}
egress {
protocol = -1
rule_no = 101
action = "allow"
ipv6_cidr_block = "::/0"
from_port = 0
to_port = 0
}
## all dns return traffic
ingress {
protocol = "udp"
rule_no = 200
action = "allow"
cidr_block = "9.9.9.9/32"
from_port = 0
to_port = 65535
}
ingress {
protocol = "udp"
rule_no = 205
action = "allow"
cidr_block = "1.1.1.1/32"
from_port = 0
to_port = 65535
}
## icmp for v4/v6
ingress {
protocol = "icmp"
rule_no = 900
action = "allow"
cidr_block = "0.0.0.0/0"
icmp_code = -1
icmp_type = -1
from_port = 0
to_port = 0
}
ingress {
protocol = "58"
rule_no = 910
action = "allow"
ipv6_cidr_block = "::/0"
icmp_code = -1
icmp_type = -1
from_port = 0
to_port = 0
}
## v4/v6 ephemeral ports
ingress {
protocol = "udp"
rule_no = 996
action = "allow"
ipv6_cidr_block = "::/0"
from_port = 1024
to_port = 65535
}
ingress {
protocol = "tcp"
rule_no = 997
action = "allow"
ipv6_cidr_block = "::/0"
from_port = 1024
to_port = 65535
}
ingress {
protocol = "udp"
rule_no = 998
action = "allow"
cidr_block = "0.0.0.0/0"
from_port = 1024
to_port = 65535
}
ingress {
protocol = "tcp"
rule_no = 999
action = "allow"
cidr_block = "0.0.0.0/0"
from_port = 1024
to_port = 65535
}
## external trust-nets
ingress {
rule_no = 300
action = "allow"
protocol = -1
cidr_block = "PUB-IP-A/32"
from_port = 0
to_port = 0
}
ingress {
rule_no = 310
action = "allow"
protocol = -1
cidr_block = "PUB-IP-B/32"
from_port = 0
to_port = 0
}
ingress {
rule_no = 320
action = "allow"
protocol = -1
ipv6_cidr_block = "fc00:0000:0000:0000::/64"
from_port = 0
to_port = 0
}
## internal trust-nets
ingress {
rule_no = 400
action = "allow"
protocol = -1
cidr_block = "10.32.32.0/24"
from_port = 0
to_port = 0
}
ingress {
rule_no = 410
action = "allow"
protocol = -1
cidr_block = "10.66.96.0/24"
from_port = 0
to_port = 0
}
ingress {
rule_no = 420
action = "allow"
protocol = -1
cidr_block = "10.66.87.0/24"
from_port = 0
to_port = 0
}
ingress {
rule_no = 430
action = "allow"
protocol = -1
cidr_block = "172.30.160.0/21"
from_port = 0
to_port = 0
}
tags = merge(local.default_tags,
{
Name = "main-default-${local.prefix}"
}
)
}
resource "aws_security_group" "trust-services" {
name = "trust-services"
description = "trusted nets/services, secure protocols"
vpc_id = aws_vpc.main.id
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
ipv6_cidr_blocks = ["::/0"]
}
## trust internal nets
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["10.66.96.0/24", "10.66.87.0/24", "10.32.32.0/24"]
}
## ssh v4/v6, icmpv6
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
ipv6_cidr_blocks = ["::/0"]
}
ingress {
from_port = "-1"
to_port = "-1"
protocol = "icmpv6"
ipv6_cidr_blocks = ["::/0"]
}
## wireguard vpn
ingress {
from_port = 7500
to_port = 7500
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 7500
to_port = 7500
protocol = "udp"
ipv6_cidr_blocks = ["::/0"]
}
tags = merge(local.default_tags,
{
Name = "trust-services-${local.prefix}"
}
)
}