-
Notifications
You must be signed in to change notification settings - Fork 22
/
template_main_security_groups.go
288 lines (275 loc) · 8.27 KB
/
template_main_security_groups.go
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
package template
const TemplateMainSecurityGroups = `
{{- define "security_groups" -}}
{{- $v := .SecurityGroups -}}
MasterSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: {{ $v.ClusterID }}-master
VpcId: !Ref VPC
SecurityGroupIngress:
{{- if $v.APIWhitelist.Public.Enabled }}
#
# Public API Whitelist Enabled Rules
#
-
Description: "Allow traffic from Control Plane CIDR."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: {{ $v.ControlPlaneVPCCIDR }}
-
Description: "Allow traffic from Tenant Cluster CIDR."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: {{ $v.TenantClusterVPCCIDR }}
{{- range $subnet := $v.APIWhitelist.Public.SubnetList }}
-
Description: "Custom Public API Whitelist CIDR."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: {{ $subnet }}
{{- end }}
{{- range $v.ControlPlaneNATGatewayAddresses }}
-
Description: "Allow traffic from NAT Gateways."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: {{ .PublicIp }}/32
{{- end }}
{{- range .NATGateway.Gateways }}
-
Description: "Allow NAT gateway IP."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: !Join [ "/", [ !Ref {{ .NATEIPName }}, "32" ] ]
{{- end }}
{{- else }}
#
# Public API Whitelist Disabled Rules
#
-
Description: "Allow all traffic to the master instance."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
{{- end }}
-
Description: "Allow traffic from Control Plane CIDR to 4194 for cadvisor scraping."
IpProtocol: tcp
FromPort: 4194
ToPort: 4194
CidrIp: {{ $v.ControlPlaneVPCCIDR }}
-
Description: "Allow traffic from Control Plane CIDR to 2379 for etcd backup."
IpProtocol: tcp
FromPort: 2379
ToPort: 2379
CidrIp: {{ $v.ControlPlaneVPCCIDR }}
-
Description: "Allow traffic from Control Plane CIDR to 10250 for kubelet scraping."
IpProtocol: tcp
FromPort: 10250
ToPort: 10250
CidrIp: {{ $v.ControlPlaneVPCCIDR }}
-
Description: "Allow traffic from Control Plane CIDR to 10300 for node-exporter scraping."
IpProtocol: tcp
FromPort: 10300
ToPort: 10300
CidrIp: {{ $v.ControlPlaneVPCCIDR }}
-
Description: "Allow traffic from Control Plane CIDR to 10301 for kube-state-metrics scraping."
IpProtocol: tcp
FromPort: 10301
ToPort: 10301
CidrIp: {{ $v.ControlPlaneVPCCIDR }}
-
Description: "Only allow SSH traffic from the Control Plane."
IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: {{ $v.ControlPlaneVPCCIDR }}
Tags:
- Key: Name
Value: {{ $v.ClusterID }}-master
EtcdELBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: {{ $v.ClusterID }}-etcd-elb
VpcId: !Ref VPC
SecurityGroupIngress:
-
Description: "Allow all Etcd traffic from the VPC to the Etcd load balancer."
IpProtocol: tcp
FromPort: 2379
ToPort: 2379
CidrIp: 0.0.0.0/0
-
Description: "Allow traffic from Control Plane to Etcd port for backup and metrics."
IpProtocol: tcp
FromPort: 2379
ToPort: 2379
CidrIp: {{ $v.ControlPlaneVPCCIDR }}
Tags:
- Key: Name
Value: {{ $v.ClusterID }}-etcd-elb
APIInternalELBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: {{ $v.ClusterID }}-internal-api
VpcId: !Ref VPC
SecurityGroupIngress:
{{- if $v.APIWhitelist.Private.Enabled }}
#
# Private API Whitelist Enabled Rules
#
-
Description: "Allow traffic from Control Plane CIDR."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: {{ $v.ControlPlaneVPCCIDR }}
-
Description: "Allow traffic from Tenant Cluster CIDR."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: {{ $v.TenantClusterVPCCIDR }}
-
Description: "Allow traffic from Tenant Cluster CNI CIDR."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: {{ $v.TenantClusterCNICIDR }}
{{- range $subnet := $v.APIWhitelist.Private.SubnetList }}
-
Description: "Custom Private API Whitelist CIDR."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: {{ $subnet }}
{{- end }}
{{- else }}
#
# Private API Whitelist Disabled Rules
#
-
Description: "Allow all traffic to the master instance from A class network."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: "10.0.0.0/8"
-
Description: "Allow all traffic to the master instance from B class network."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: "172.16.0.0/12"
-
Description: "Allow all traffic to the master instance from C class network."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: "192.168.0.0/16"
-
Description: "Allow all traffic to the master instance from CNI (non RFC-1918)."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: "100.64.0.0/10"
-
Description: "Allow all traffic to the master instance from CNI (non RFC-1918)."
IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: "198.19.0.0/16"
{{- end }}
Tags:
- Key: Name
Value: {{ $v.ClusterID }}-internal-api
AWSCNISecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "AWS CNI Security Group configured to the ENIConfig CRD."
VpcId: !Ref VPC
Tags:
- Key: Name
Value: {{ $v.ClusterID }}-aws-cni
{{- if .EnableAWSCNI }}
PodsIngressRuleFromMAsters:
Type: AWS::EC2::SecurityGroupIngress
DependsOn: AWSCNISecurityGroup
Properties:
Description: Allow traffic from masters to pods.
GroupId: !Ref AWSCNISecurityGroup
IpProtocol: -1
FromPort: -1
ToPort: -1
SourceSecurityGroupId: !Ref MasterSecurityGroup
PodsAllowPodsCNIIngressRule:
Type: AWS::EC2::SecurityGroupIngress
DependsOn: AWSCNISecurityGroup
Properties:
Description: Allow traffic from pod to pod.
GroupId: !Ref AWSCNISecurityGroup
IpProtocol: -1
FromPort: -1
ToPort: -1
SourceSecurityGroupId: !Ref AWSCNISecurityGroup
{{- end }}
MasterAllowCalicoIngressRule:
Type: AWS::EC2::SecurityGroupIngress
DependsOn: MasterSecurityGroup
Properties:
GroupId: !Ref MasterSecurityGroup
IpProtocol: -1
FromPort: -1
ToPort: -1
SourceSecurityGroupId: !Ref MasterSecurityGroup
MasterAllowAPIInternalELBHealthCheck:
Type: AWS::EC2::SecurityGroupIngress
DependsOn:
- MasterSecurityGroup
- APIInternalELBSecurityGroup
Properties:
GroupId: !Ref MasterSecurityGroup
IpProtocol: "tcp"
FromPort: 8089
ToPort: 8089
SourceSecurityGroupId: !Ref APIInternalELBSecurityGroup
{{- if .EnableAWSCNI }}
MasterAllowPodsCNIIngressRule:
Type: AWS::EC2::SecurityGroupIngress
DependsOn: MasterSecurityGroup
Properties:
Description: Allow traffic from pod to master.
GroupId: !Ref MasterSecurityGroup
IpProtocol: -1
FromPort: -1
ToPort: -1
SourceSecurityGroupId: !Ref AWSCNISecurityGroup
{{- end }}
MasterAllowEtcdIngressRule:
Type: AWS::EC2::SecurityGroupIngress
DependsOn: MasterSecurityGroup
Properties:
GroupId: !Ref MasterSecurityGroup
IpProtocol: "tcp"
FromPort: 2379
ToPort: 2379
SourceSecurityGroupId: !Ref EtcdELBSecurityGroup
VPCDefaultSecurityGroupEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
Description: Allow outbound traffic from loopback address.
GroupId: !GetAtt VPC.DefaultSecurityGroup
IpProtocol: -1
CidrIp: 127.0.0.1/32
{{- end -}}
`