-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsecurity_group.tf
155 lines (137 loc) · 6.04 KB
/
security_group.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
resource "aws_security_group" "eks_master" {
name = "${var.cluster_name}-master"
description = "Cluster communication with worker nodes"
vpc_id = var.vpc_id
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = merge({Name="${var.cluster_name}-master"}, var.eks_tags)
}
resource "aws_security_group_rule" "eks_master_api" {
cidr_blocks = ["0.0.0.0/0"]
description = "Allow workstation to communicate with the cluster API Server"
from_port = 443
protocol = "tcp"
security_group_id = aws_security_group.eks_master.id
to_port = 443
type = "ingress"
}
resource "aws_security_group" "eks_worker" {
name = "${var.cluster_name}-worker"
description = "Security group for all worker nodes in the cluster"
vpc_id = var.vpc_id
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = merge({Name="${var.cluster_name}-worker"}, var.eks_tags)
}
resource "aws_security_group_rule" "eks_worker_ingress_ssh" {
count = length(var.eks_worker_ssh_cidrs) > 0 ? 1 : 0
description = "Allow ssh connections"
from_port = 22
protocol = "tcp"
security_group_id = aws_security_group.eks_worker.id
cidr_blocks = var.eks_worker_ssh_cidrs
to_port = 22
type = "ingress"
}
resource "aws_security_group_rule" "eks_worker_ingress_self" {
description = "Allow node to communicate with each other"
from_port = 0
protocol = "-1"
security_group_id = aws_security_group.eks_worker.id
source_security_group_id = aws_security_group.eks_worker.id
to_port = 65535
type = "ingress"
}
resource "aws_security_group_rule" "eks_worker_ingress_managed_nodes" {
description = "Allow EC2 nodes to communicate with AWS managed nodes"
from_port = 0
protocol = "-1"
security_group_id = aws_security_group.eks_worker.id
source_security_group_id = aws_eks_cluster.main.vpc_config[0].cluster_security_group_id
to_port = 65535
type = "ingress"
}
resource "aws_security_group_rule" "managed_nodes_ingress_eks_worker" {
description = "Allow AWS managed nodes to communicate with EC2 nodes"
from_port = 0
protocol = "-1"
security_group_id = aws_eks_cluster.main.vpc_config[0].cluster_security_group_id
source_security_group_id = aws_security_group.eks_worker.id
to_port = 65535
type = "ingress"
}
resource "aws_security_group_rule" "eks_worker_ingress_cluster" {
description = "Allow worker Kubelets and pods to receive communication from the cluster control plane"
from_port = 1025
protocol = "tcp"
security_group_id = aws_security_group.eks_worker.id
source_security_group_id = aws_security_group.eks_master.id
to_port = 65535
type = "ingress"
}
resource "aws_security_group_rule" "eks_worker_ingress_https_from_master" {
description = "Allow pods to communicate with the cluster API Server"
from_port = 443
protocol = "tcp"
security_group_id = aws_security_group.eks_worker.id
source_security_group_id = aws_security_group.eks_master.id
to_port = 443
type = "ingress"
}
resource "aws_security_group_rule" "eks_master_ingress_https_from_workers" {
description = "Allow cluster control to receive communication from the worker Kubelets"
from_port = 443
protocol = "tcp"
security_group_id = aws_security_group.eks_master.id
source_security_group_id = aws_security_group.eks_worker.id
to_port = 443
type = "ingress"
}
resource "aws_security_group_rule" "eks_worker_ingress_nginx_from_vpc" {
count = var.helm_ingress_nginx_enabled ? 1 : 0
description = "Allow VPC CIDR to access ingress port"
from_port = 32080
protocol = "tcp"
security_group_id = aws_security_group.eks_worker.id
cidr_blocks = [data.aws_vpc.main.cidr_block]
to_port = 32080
type = "ingress"
}
resource "aws_security_group_rule" "eks_worker_ingress_nginx_https_from_vpc" {
count = var.ingress_https_traffic_enabled ? 1 : 0
description = "Allow VPC CIDR to access ingress https port"
from_port = 32443
protocol = "tcp"
security_group_id = aws_security_group.eks_worker.id
cidr_blocks = [data.aws_vpc.main.cidr_block]
to_port = 32443
type = "ingress"
}
resource "aws_security_group_rule" "eks_worker_ingress_nginx_additional_from_vpc" {
count = var.helm_ingress_nginx_additional_enabled ? 1 : 0
description = "Allow VPC CIDR to access additional ingress port"
from_port = 31080
protocol = "tcp"
security_group_id = aws_security_group.eks_worker.id
cidr_blocks = [data.aws_vpc.main.cidr_block]
to_port = 31080
type = "ingress"
}
resource "aws_security_group_rule" "eks_worker_ingress_nginx_additional_https_from_vpc" {
count = var.ingress_additional_https_traffic_enabled ? 1 : 0
description = "Allow VPC CIDR to access additional ingress https port"
from_port = 31443
protocol = "tcp"
security_group_id = aws_security_group.eks_worker.id
cidr_blocks = [data.aws_vpc.main.cidr_block]
to_port = 31443
type = "ingress"
}