-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsecurity_groups.tf
More file actions
294 lines (268 loc) · 9.08 KB
/
security_groups.tf
File metadata and controls
294 lines (268 loc) · 9.08 KB
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
// -----------------------------
// Redpanda Agent security group
// -----------------------------
resource "aws_security_group" "redpanda_agent" {
name_prefix = "${var.common_prefix}-agent-"
description = "Redpanda agent VM"
vpc_id = data.aws_vpc.redpanda.id
ingress = []
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
lifecycle {
create_before_destroy = true
}
tags = var.default_tags
}
// -----------------------------
// Connectors security group
// -----------------------------
resource "aws_security_group" "connectors" {
name_prefix = "${var.common_prefix}-connect-"
description = "Redpanda connectors nodes"
vpc_id = data.aws_vpc.redpanda.id
lifecycle {
create_before_destroy = true
}
tags = var.default_tags
}
resource "aws_security_group_rule" "connectors" {
security_group_id = aws_security_group.connectors.id
protocol = "-1"
from_port = 0
to_port = 0
type = "egress"
description = "Allow all egress traffic"
cidr_blocks = ["0.0.0.0/0"]
}
// -----------------------------
// Redpanda Connect security group
// -----------------------------
resource "aws_security_group" "redpanda_connect" {
count = var.enable_redpanda_connect ? 1 : 0
name_prefix = "${var.common_prefix}-rpcn-"
description = "Redpanda Connect nodes"
vpc_id = data.aws_vpc.redpanda.id
lifecycle {
create_before_destroy = true
}
}
resource "aws_security_group_rule" "redpanda_connect" {
count = var.enable_redpanda_connect ? 1 : 0
security_group_id = aws_security_group.redpanda_connect[0].id
protocol = "-1"
from_port = 0
to_port = 0
type = "egress"
description = "Allow all egress traffic"
cidr_blocks = ["0.0.0.0/0"]
}
// -----------------------------
// Utility security group
// -----------------------------
resource "aws_security_group" "utility" {
name_prefix = "${var.common_prefix}-util-"
description = "Redpanda utility nodes"
vpc_id = data.aws_vpc.redpanda.id
lifecycle {
create_before_destroy = true
}
tags = var.default_tags
}
resource "aws_security_group_rule" "utility" {
security_group_id = aws_security_group.utility.id
protocol = "-1"
from_port = 0
to_port = 0
type = "egress"
description = "Allow all egress traffic"
cidr_blocks = ["0.0.0.0/0"]
}
// ----------------------------------
// Redpanda Node Group security group
// ----------------------------------
resource "aws_security_group" "redpanda_node_group" {
name_prefix = "${var.common_prefix}-rp-"
description = "Redpanda cluster nodes"
vpc_id = data.aws_vpc.redpanda.id
lifecycle {
create_before_destroy = true
}
tags = var.default_tags
}
locals {
rp_node_group_cidr_blocks = [
// RFC 6598 reserved prefix for shared address space
// https://datatracker.ietf.org/doc/html/rfc6598
"100.64.0.0/10",
// RFC 1918 reserved IP address space for private internets
// https://datatracker.ietf.org/doc/html/rfc1918
"172.16.0.0/12",
"192.168.0.0/16",
"10.0.0.0/8",
]
}
resource "aws_security_group_rule" "redpanda_node_group" {
security_group_id = aws_security_group.redpanda_node_group.id
protocol = "tcp"
from_port = 30092
to_port = 30094
type = "ingress"
description = "Allow access to Kafka API in the ports advertised by Redpanda brokers"
cidr_blocks = local.rp_node_group_cidr_blocks
}
// -----------------------------
// Cluster security group
// -----------------------------
resource "aws_security_group" "cluster" {
name_prefix = "${var.common_prefix}-cluster-"
description = "EKS cluster security group"
vpc_id = data.aws_vpc.redpanda.id
lifecycle {
create_before_destroy = true
}
tags = var.default_tags
}
resource "aws_security_group_rule" "cluster_node_groups_to_cluster_api" {
description = "Node groups to cluster API"
security_group_id = aws_security_group.cluster.id
protocol = "tcp"
from_port = 443
to_port = 443
type = "ingress"
source_security_group_id = aws_security_group.node.id
}
resource "aws_security_group_rule" "cluster_agent_to_cluster_api" {
description = "Redpanda Agent to K8s Cluster"
security_group_id = aws_security_group.cluster.id
protocol = "tcp"
from_port = 443
to_port = 443
type = "ingress"
# cidr blocks must include the IP address of the Redpanda Agent VM
cidr_blocks = data.aws_subnet.private[*].cidr_block
}
resource "aws_security_group_rule" "cluster_api_to_node_group" {
description = "Cluster API to node groups"
security_group_id = aws_security_group.cluster.id
protocol = "tcp"
from_port = 443
to_port = 443
type = "egress"
source_security_group_id = aws_security_group.node.id
}
resource "aws_security_group_rule" "cluster_egress_nodes_kubelet" {
description = "Cluster API to node kubelets"
security_group_id = aws_security_group.cluster.id
protocol = "tcp"
from_port = 10250
to_port = 10250
type = "egress"
source_security_group_id = aws_security_group.node.id
}
// -----------------------------
// Node security group
// -----------------------------
resource "aws_security_group" "node" {
name_prefix = "${var.common_prefix}-node-"
description = "EKS node shared security group"
vpc_id = data.aws_vpc.redpanda.id
lifecycle {
create_before_destroy = true
}
tags = var.default_tags
}
resource "aws_security_group_rule" "node_groups_to_cluster_api" {
description = "Node groups to cluster API"
security_group_id = aws_security_group.node.id
protocol = "tcp"
from_port = "443"
to_port = "443"
type = "egress"
source_security_group_id = aws_security_group.cluster.id
}
resource "aws_security_group_rule" "cluster_api_to_node_groups" {
description = "Cluster API to node groups"
security_group_id = aws_security_group.node.id
protocol = "tcp"
from_port = "443"
to_port = "443"
type = "ingress"
source_security_group_id = aws_security_group.cluster.id
}
resource "aws_security_group_rule" "cluster_api_to_node_kubelets" {
description = "Cluster API to node kubelets"
security_group_id = aws_security_group.node.id
protocol = "tcp"
from_port = "10250"
to_port = "10250"
type = "ingress"
source_security_group_id = aws_security_group.cluster.id
}
resource "aws_security_group_rule" "node_to_node_coredns" {
description = "Node to node CoreDNS"
security_group_id = aws_security_group.node.id
protocol = "tcp"
from_port = "53"
to_port = "53"
type = "ingress"
self = true
}
resource "aws_security_group_rule" "node_to_node_coredns_egress" {
description = "Node to node CoreDNS"
security_group_id = aws_security_group.node.id
protocol = "tcp"
from_port = "53"
to_port = "53"
type = "egress"
self = true
}
resource "aws_security_group_rule" "node_to_node_coredns_udp" {
description = "Node to node CoreDNS"
security_group_id = aws_security_group.node.id
protocol = "udp"
from_port = "53"
to_port = "53"
type = "ingress"
self = true
}
resource "aws_security_group_rule" "node_to_node_coredns_udp_egress" {
description = "Node to node CoreDNS"
security_group_id = aws_security_group.node.id
protocol = "udp"
from_port = "53"
to_port = "53"
type = "egress"
self = true
}
resource "aws_security_group_rule" "egress_all_https_to_internet" {
description = "Egress all HTTPS to internet"
security_group_id = aws_security_group.node.id
protocol = "tcp"
from_port = "443"
to_port = "443"
type = "egress"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "egress_ntp_tcp_to_internet" {
description = "Egress NTP/TCP to internet"
security_group_id = aws_security_group.node.id
protocol = "tcp"
from_port = "123"
to_port = "123"
type = "egress"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "egress_ntp_udp_to_internet" {
description = "Egress NTP/UDP to internet"
security_group_id = aws_security_group.node.id
protocol = "udp"
from_port = "123"
to_port = "123"
type = "egress"
cidr_blocks = ["0.0.0.0/0"]
}