-
Notifications
You must be signed in to change notification settings - Fork 1
/
firewall.tf
171 lines (139 loc) · 5.2 KB
/
firewall.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
/**
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// This file was automatically generated from a template in ./autogen/main
/******************************************
Match the gke-<CLUSTER>-<ID>-all INGRESS
firewall rule created by GKE but for EGRESS
Required for clusters when VPCs enforce
a default-deny egress rule
*****************************************/
resource "google_compute_firewall" "intra_egress" {
count = var.add_cluster_firewall_rules ? 1 : 0
name = "gke-${substr(var.name, 0, min(25, length(var.name)))}-intra-cluster-egress"
description = "Managed by terraform gke module: Allow pods to communicate with each other and the master"
project = local.network_project_id
network = var.network
priority = var.firewall_priority
direction = "EGRESS"
target_tags = [local.cluster_network_tag]
destination_ranges = [
local.cluster_endpoint_for_nodes,
local.cluster_subnet_cidr,
local.cluster_alias_ranges_cidr[var.ip_range_pods],
]
# Allow all possible protocols
allow { protocol = "tcp" }
allow { protocol = "udp" }
allow { protocol = "icmp" }
allow { protocol = "sctp" }
allow { protocol = "esp" }
allow { protocol = "ah" }
depends_on = [
google_container_cluster.primary,
]
}
/******************************************
Allow GKE master to hit non 443 ports for
Webhooks/Admission Controllers
https://github.com/kubernetes/kubernetes/issues/79739
*****************************************/
resource "google_compute_firewall" "master_webhooks" {
count = var.add_cluster_firewall_rules || var.add_master_webhook_firewall_rules ? 1 : 0
name = "gke-${substr(var.name, 0, min(25, length(var.name)))}-webhooks"
description = "Managed by terraform gke module: Allow master to hit pods for admission controllers/webhooks"
project = local.network_project_id
network = var.network
priority = var.firewall_priority
direction = "INGRESS"
source_ranges = [local.cluster_endpoint_for_nodes]
source_tags = []
target_tags = [local.cluster_network_tag]
allow {
protocol = "tcp"
ports = var.firewall_inbound_ports
}
depends_on = [
google_container_cluster.primary,
]
}
/******************************************
Create shadow firewall rules to capture the
traffic flow between the managed firewall rules
*****************************************/
resource "google_compute_firewall" "shadow_allow_pods" {
count = var.add_shadow_firewall_rules ? 1 : 0
name = "gke-shadow-${substr(var.name, 0, min(25, length(var.name)))}-all"
description = "Managed by terraform gke module: A shadow firewall rule to match the default rule allowing pod communication."
project = local.network_project_id
network = var.network
priority = var.shadow_firewall_rules_priority
direction = "INGRESS"
source_ranges = [local.cluster_alias_ranges_cidr[var.ip_range_pods]]
target_tags = [local.cluster_network_tag]
# Allow all possible protocols
allow { protocol = "tcp" }
allow { protocol = "udp" }
allow { protocol = "icmp" }
allow { protocol = "sctp" }
allow { protocol = "esp" }
allow { protocol = "ah" }
log_config {
metadata = "INCLUDE_ALL_METADATA"
}
}
resource "google_compute_firewall" "shadow_allow_master" {
count = var.add_shadow_firewall_rules ? 1 : 0
name = "gke-shadow-${substr(var.name, 0, min(25, length(var.name)))}-master"
description = "Managed by terraform GKE module: A shadow firewall rule to match the default rule allowing worker nodes communication."
project = local.network_project_id
network = var.network
priority = var.shadow_firewall_rules_priority
direction = "INGRESS"
source_ranges = [local.cluster_endpoint_for_nodes]
target_tags = [local.cluster_network_tag]
allow {
protocol = "tcp"
ports = ["10250", "443"]
}
log_config {
metadata = "INCLUDE_ALL_METADATA"
}
}
resource "google_compute_firewall" "shadow_allow_nodes" {
count = var.add_shadow_firewall_rules ? 1 : 0
name = "gke-shadow-${substr(var.name, 0, min(25, length(var.name)))}-vms"
description = "Managed by Terraform GKE module: A shadow firewall rule to match the default rule allowing worker nodes communication."
project = local.network_project_id
network = var.network
priority = var.shadow_firewall_rules_priority
direction = "INGRESS"
source_ranges = [local.cluster_subnet_cidr]
target_tags = [local.cluster_network_tag]
allow {
protocol = "icmp"
}
allow {
protocol = "udp"
ports = ["1-65535"]
}
allow {
protocol = "tcp"
ports = ["1-65535"]
}
log_config {
metadata = "INCLUDE_ALL_METADATA"
}
}