Skip to content

Commit a404d99

Browse files
committed
add all pod_ranges to cluster firewall rules and add missing shadow rules
1 parent 43bbd3c commit a404d99

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

autogen/main/firewall.tf.tmpl

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ resource "google_compute_firewall" "intra_egress" {
3434
direction = "EGRESS"
3535

3636
target_tags = [local.cluster_network_tag]
37-
destination_ranges = [
37+
destination_ranges = concat([
3838
local.cluster_endpoint_for_nodes,
3939
local.cluster_subnet_cidr,
40-
local.cluster_alias_ranges_cidr[var.ip_range_pods],
41-
]
40+
],
41+
local.pod_all_ip_ranges
42+
)
4243

4344
# Allow all possible protocols
4445
allow { protocol = "tcp" }
@@ -143,7 +144,7 @@ resource "google_compute_firewall" "shadow_allow_pods" {
143144
priority = var.shadow_firewall_rules_priority
144145
direction = "INGRESS"
145146

146-
source_ranges = [local.cluster_alias_ranges_cidr[var.ip_range_pods]]
147+
source_ranges = local.pod_all_ip_ranges
147148
target_tags = [local.cluster_network_tag]
148149

149150
# Allow all possible protocols
@@ -213,3 +214,50 @@ resource "google_compute_firewall" "shadow_allow_nodes" {
213214
metadata = "INCLUDE_ALL_METADATA"
214215
}
215216
}
217+
218+
resource "google_compute_firewall" "shadow_allow_inkubelet" {
219+
count = var.add_shadow_firewall_rules ? 1 : 0
220+
221+
name = "gke-shadow-${substr(var.name, 0, min(25, length(var.name)))}-inkubelet"
222+
description = "Managed by terraform GKE module: A shadow firewall rule to match the default rule allowing worker nodes & pods communication to kubelet."
223+
project = local.network_project_id
224+
network = var.network
225+
priority = min(998, var.shadow_firewall_rules_priority) # rule created by GKE robot have prio 999
226+
direction = "INGRESS"
227+
228+
source_ranges = local.pod_all_ip_ranges
229+
source_tags = [local.cluster_network_tag]
230+
target_tags = [local.cluster_network_tag]
231+
232+
allow {
233+
protocol = "tcp"
234+
ports = ["10255"]
235+
}
236+
237+
log_config {
238+
metadata = "INCLUDE_ALL_METADATA"
239+
}
240+
}
241+
242+
resource "google_compute_firewall" "shadow_deny_exkubelet" {
243+
count = var.add_shadow_firewall_rules ? 1 : 0
244+
245+
name = "gke-shadow-${substr(var.name, 0, min(25, length(var.name)))}-exkubelet"
246+
description = "Managed by terraform GKE module: A shadow firewall rule to match the default deny rule to kubelet."
247+
project = local.network_project_id
248+
network = var.network
249+
priority = min(999, var.shadow_firewall_rules_priority) # rule created by GKE robot have prio 1000
250+
direction = "INGRESS"
251+
252+
source_ranges = ["0.0.0.0/0"]
253+
target_tags = [local.cluster_network_tag]
254+
255+
deny {
256+
protocol = "tcp"
257+
ports = ["10255"]
258+
}
259+
260+
log_config {
261+
metadata = "INCLUDE_ALL_METADATA"
262+
}
263+
}

autogen/main/main.tf.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ locals {
8686

8787
cluster_subnet_cidr = var.add_cluster_firewall_rules ? data.google_compute_subnetwork.gke_subnetwork[0].ip_cidr_range : null
8888
cluster_alias_ranges_cidr = var.add_cluster_firewall_rules ? { for range in toset(data.google_compute_subnetwork.gke_subnetwork[0].secondary_ip_range) : range.range_name => range.ip_cidr_range } : {}
89+
pod_all_ip_ranges = var.add_cluster_firewall_rules ? compact(concat([local.cluster_alias_ranges_cidr[var.ip_range_pods]], [for k, v in merge(local.node_pools, local.windows_node_pools): local.cluster_alias_ranges_cidr[v.pod_range] if length(lookup(v, "pod_range", "")) > 0] )) : []
8990

9091
{% if autopilot_cluster != true %}
9192
cluster_network_policy = var.network_policy ? [{

0 commit comments

Comments
 (0)