forked from hashicorp/microservices-architecture-on-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity-groups.tf
361 lines (323 loc) · 13 KB
/
security-groups.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# Security Group for Client ALB
resource "aws_security_group" "client_alb" {
name_prefix = "${local.project_tag}-ecs-client-alb"
description = "security group for client service application load balancer"
vpc_id = aws_vpc.main.id
}
resource "aws_security_group_rule" "client_alb_allow_80" {
security_group_id = aws_security_group.client_alb.id
type = "ingress"
protocol = "tcp"
from_port = 80
to_port = 80
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
description = "Allow HTTP traffic."
}
resource "aws_security_group_rule" "client_alb_allow_outbound" {
security_group_id = aws_security_group.client_alb.id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
description = "Allow any outbound traffic."
}
# Security Group for ECS Client Service.
resource "aws_security_group" "ecs_client_service" {
name_prefix = "${local.project_tag}-ecs-client-service"
description = "ECS Client service security group."
vpc_id = aws_vpc.main.id
}
resource "aws_security_group_rule" "ecs_client_service_allow_9090" {
security_group_id = aws_security_group.ecs_client_service.id
type = "ingress"
protocol = "tcp"
from_port = 9090
to_port = 9090
source_security_group_id = aws_security_group.client_alb.id
description = "Allow incoming traffic from the client ALB into the service container port."
}
resource "aws_security_group_rule" "ecs_client_service_allow_inbound_self" {
security_group_id = aws_security_group.ecs_client_service.id
type = "ingress"
protocol = -1
self = true
from_port = 0
to_port = 0
description = "Allow traffic from resources with this security group."
}
resource "aws_security_group_rule" "ecs_client_service_allow_outbound" {
security_group_id = aws_security_group.ecs_client_service.id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
description = "Allow any outbound traffic."
}
resource "aws_security_group" "ecs_fruits_service" {
name_prefix = "${local.project_tag}-ecs-fruits-service"
description = "ECS Fruits service security group."
vpc_id = aws_vpc.main.id
}
resource "aws_security_group_rule" "ecs_fruits_service_allow_inbound_self" {
security_group_id = aws_security_group.ecs_fruits_service.id
type = "ingress"
protocol = -1
self = true
from_port = 0
to_port = 0
description = "Allow traffic from resources with this security group."
}
resource "aws_security_group_rule" "ecs_fruits_service_allow_outbound" {
security_group_id = aws_security_group.ecs_fruits_service.id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
description = "Allow any outbound traffic."
}
resource "aws_security_group" "ecs_vegetables_service" {
name_prefix = "${local.project_tag}-ecs-vegetables-service"
description = "ECS Vegetables service security group."
vpc_id = aws_vpc.main.id
}
resource "aws_security_group_rule" "ecs_vegetables_service_allow_inbound_self" {
security_group_id = aws_security_group.ecs_vegetables_service.id
type = "ingress"
protocol = -1
self = true
from_port = 0
to_port = 0
description = "Allow traffic from resources with this security group."
}
resource "aws_security_group_rule" "ecs_vegetables_service_allow_outbound" {
security_group_id = aws_security_group.ecs_vegetables_service.id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
description = "Allow any outbound traffic."
}
# Security Group for Database Server
resource "aws_security_group" "database" {
name_prefix = "${local.project_tag}-database"
description = "Database security group."
vpc_id = aws_vpc.main.id
}
resource "aws_security_group_rule" "database_allow_fruits_27017" {
security_group_id = aws_security_group.database.id
type = "ingress"
protocol = "tcp"
from_port = 27017
to_port = 27017
source_security_group_id = aws_security_group.ecs_fruits_service.id
description = "Allow incoming traffic from the Fruits service onto the database port."
}
resource "aws_security_group_rule" "database_allow_vegetables_27017" {
security_group_id = aws_security_group.database.id
type = "ingress"
protocol = "tcp"
from_port = 27017
to_port = 27017
source_security_group_id = aws_security_group.ecs_vegetables_service.id
description = "Allow incoming traffic from the Vegetables service onto the database port."
}
resource "aws_security_group_rule" "database_allow_outbound" {
security_group_id = aws_security_group.database.id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
description = "Allow any outbound traffic."
}
resource "aws_security_group" "consul_server" {
name_prefix = "${local.project_tag}-consul-server"
description = "Security Group for the Consul servers"
vpc_id = aws_vpc.main.id
}
resource "aws_security_group_rule" "consul_server_allow_server_8300" {
security_group_id = aws_security_group.consul_server.id
type = "ingress"
protocol = "tcp"
from_port = 8300
to_port = 8300
self = true
description = "Allow RPC traffic from ConsulServer to Server. For data replication between servers."
}
resource "aws_security_group_rule" "consul_server_allow_server_8301" {
security_group_id = aws_security_group.consul_server.id
type = "ingress"
protocol = "tcp"
from_port = 8301
to_port = 8301
self = true
description = "Allow LAN gossip traffic from ConsulServer to Server. For managing cluster membership, distributed health checks of agents and event broadcasts"
}
resource "aws_security_group_rule" "consul_server_allow_server_8302" {
security_group_id = aws_security_group.consul_server.id
type = "ingress"
protocol = "tcp"
from_port = 8302
to_port = 8302
self = true
description = "Allow WAN gossip traffic from ConsulServer to Server. For cross-datacenter communication"
}
resource "aws_security_group_rule" "consul_server_allow_alb_8500" {
security_group_id = aws_security_group.consul_server.id
type = "ingress"
protocol = "tcp"
from_port = 8500
to_port = 8500
source_security_group_id = aws_security_group.consul_server_alb.id
description = "Allow HTTP traffic from Load Balancer onto the Consul Server API."
}
resource "aws_security_group_rule" "consul_server_allow_outbound" {
security_group_id = aws_security_group.consul_server.id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
description = "Allow outbound traffic"
}
resource "aws_security_group_rule" "consul_server_allow_server_8501" {
security_group_id = aws_security_group.consul_server.id
type = "ingress"
protocol = "tcp"
from_port = 8501
to_port = 8501
self = true
description = "Allow HTTPS API traffic from Consul Server to Server."
}
# Access From the Consul Client to Consul Servers
resource "aws_security_group_rule" "consul_server_allow_client_8300" {
security_group_id = aws_security_group.consul_server.id
type = "ingress"
protocol = "tcp"
from_port = 8300
to_port = 8300
source_security_group_id = aws_security_group.consul_client.id
description = "Allow RPC traffic from Consul Client to Server. For data replication between servers."
}
resource "aws_security_group_rule" "consul_server_allow_client_8301" {
security_group_id = aws_security_group.consul_server.id
type = "ingress"
protocol = "tcp"
from_port = 8301
to_port = 8301
source_security_group_id = aws_security_group.consul_client.id
description = "Allow LAN gossip traffic from Consul Client to Server. For data replication between servers."
}
resource "aws_security_group_rule" "consul_server_allow_client_8500" {
security_group_id = aws_security_group.consul_server.id
type = "ingress"
protocol = "tcp"
from_port = 8500
to_port = 8500
source_security_group_id = aws_security_group.consul_client.id
description = "Allow HTTP API traffic from Consul Client to Server."
}
resource "aws_security_group_rule" "consul_server_allow_client_8501" {
security_group_id = aws_security_group.consul_server.id
type = "ingress"
protocol = "tcp"
from_port = 8501
to_port = 8501
source_security_group_id = aws_security_group.consul_client.id
description = "Allow HTTPS API traffic from Consul Client to Server."
}
# Consul Server ALB Security Group
resource "aws_security_group" "consul_server_alb" {
name_prefix = "${local.project_tag}-consul-server-alb"
description = "Security Group for the ALB fronting the consul server"
vpc_id = aws_vpc.main.id
}
resource "aws_security_group_rule" "consul_server_alb_allow_80" {
security_group_id = aws_security_group.consul_server_alb.id
type = "ingress"
protocol = "tcp"
from_port = 80
to_port = 80
cidr_blocks = flatten([var.consul_server_allowed_cidr_blocks, [var.vpc_cidr]])
description = "Allow HTTP traffic."
}
resource "aws_security_group_rule" "consul_server_alb_allow_outbound" {
security_group_id = aws_security_group.consul_server_alb.id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
description = "Allow any outbound traffic."
}
resource "aws_security_group" "acl_controller" {
name_prefix = "${local.project_tag}-acl-controller-"
description = "Consul ACL Controller service security group."
vpc_id = aws_vpc.main.id
}
resource "aws_security_group_rule" "acl_controller_allow_inbound_self" {
security_group_id = aws_security_group.acl_controller.id
type = "ingress"
protocol = -1
self = true
from_port = 0
to_port = 0
description = "Allow traffic from resources with this security group."
}
resource "aws_security_group_rule" "acl_controller_allow_outbound" {
security_group_id = aws_security_group.acl_controller.id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
description = "Allow any outbound traffic."
}
# A Generalized group for all consul clients
resource "aws_security_group" "consul_client" {
name_prefix = "${local.project_tag}-consul-client-"
description = "General security group for consul clients."
vpc_id = aws_vpc.main.id
}
# Required for gossip traffic between each client
resource "aws_security_group_rule" "consul_client_allow_inbound_self_8301" {
security_group_id = aws_security_group.consul_client.id
type = "ingress"
protocol = "tcp"
self = true
from_port = 8301
to_port = 8301
description = "Allow LAN Serf traffic from resources with this security group."
}
# Required to allow the proxies to contact each other
resource "aws_security_group_rule" "consul_client_allow_inbound_self_20000" {
security_group_id = aws_security_group.consul_client.id
type = "ingress"
protocol = "tcp"
self = true
from_port = 20000
to_port = 20000
description = "Allow Proxy traffic from resources with this security group."
}
resource "aws_security_group_rule" "consul_client_allow_outbound" {
security_group_id = aws_security_group.consul_client.id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
description = "Allow any outbound traffic."
}