Skip to content

Commit 8a5dcb8

Browse files
authored
feat: Introduce add_master_webhook_firewall_rules flag to add webhooks (#882)
- Flag controls exclusive creation of a firewall rule for ports defined in firewall_inbound_ports - The existing flag add_cluster_firewall_rules is kept on the firewall rule resource for backwards compatibility
1 parent 110adb6 commit 8a5dcb8

File tree

23 files changed

+78
-23
lines changed

23 files changed

+78
-23
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ Then perform the following commands on the root folder:
124124
| Name | Description | Type | Default | Required |
125125
|------|-------------|------|---------|:--------:|
126126
| add\_cluster\_firewall\_rules | Create additional firewall rules | `bool` | `false` | no |
127+
| add\_master\_webhook\_firewall\_rules | Create master\_webhook firewall rules for ports defined in `firewall_inbound_ports` | `bool` | `false` | no |
127128
| add\_shadow\_firewall\_rules | Create GKE shadow firewall (the same as default firewall rules with firewall logs enabled). | `bool` | `false` | no |
128129
| basic\_auth\_password | The password to be used with Basic Authentication. | `string` | `""` | no |
129130
| basic\_auth\_username | The username to be used with Basic Authentication. An empty value will disable Basic Authentication, which is the recommended configuration. | `string` | `""` | no |
@@ -141,7 +142,7 @@ Then perform the following commands on the root folder:
141142
| enable\_resource\_consumption\_export | Whether to enable resource consumption metering on this cluster. When enabled, a table will be created in the resource export BigQuery dataset to store resource consumption data. The resulting table can be joined with the resource usage table or with BigQuery billing export. | `bool` | `true` | no |
142143
| enable\_shielded\_nodes | Enable Shielded Nodes features on all nodes in this cluster | `bool` | `true` | no |
143144
| enable\_vertical\_pod\_autoscaling | Vertical Pod Autoscaling automatically adjusts the resources of pods controlled by it | `bool` | `false` | no |
144-
| firewall\_inbound\_ports | List of TCP ports for admission/webhook controllers | `list(string)` | <pre>[<br> "8443",<br> "9443",<br> "15017"<br>]</pre> | no |
145+
| firewall\_inbound\_ports | List of TCP ports for admission/webhook controllers. Either flag `add_master_webhook_firewall_rules` or `add_cluster_firewall_rules` (also adds egress rules) must be set to `true` for inbound-ports firewall rules to be applied. | `list(string)` | <pre>[<br> "8443",<br> "9443",<br> "15017"<br>]</pre> | no |
145146
| firewall\_priority | Priority rule for firewall rules | `number` | `1000` | no |
146147
| gcloud\_upgrade | Whether to upgrade gcloud at runtime | `bool` | `false` | no |
147148
| grant\_registry\_access | Grants created cluster-specific service account storage.objectViewer role. | `bool` | `false` | no |

autogen/main/firewall.tf.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ resource "google_compute_firewall" "intra_egress" {
7272
https://github.com/kubernetes/kubernetes/issues/79739
7373
*****************************************/
7474
resource "google_compute_firewall" "master_webhooks" {
75-
count = var.add_cluster_firewall_rules ? 1 : 0
75+
count = var.add_cluster_firewall_rules || var.add_master_webhook_firewall_rules ? 1 : 0
7676
name = "gke-${substr(var.name, 0, min(25, length(var.name)))}-webhooks"
7777
description = "Managed by terraform gke module: Allow master to hit pods for admission controllers/webhooks"
7878
project = local.network_project_id

autogen/main/variables.tf.tmpl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,12 @@ variable "add_cluster_firewall_rules" {
569569
default = false
570570
}
571571

572+
variable "add_master_webhook_firewall_rules" {
573+
type = bool
574+
description = "Create master_webhook firewall rules for ports defined in `firewall_inbound_ports`"
575+
default = false
576+
}
577+
572578
variable "firewall_priority" {
573579
type = number
574580
description = "Priority rule for firewall rules"
@@ -577,7 +583,7 @@ variable "firewall_priority" {
577583

578584
variable "firewall_inbound_ports" {
579585
type = list(string)
580-
description = "List of TCP ports for admission/webhook controllers"
586+
description = "List of TCP ports for admission/webhook controllers. Either flag `add_master_webhook_firewall_rules` or `add_cluster_firewall_rules` (also adds egress rules) must be set to `true` for inbound-ports firewall rules to be applied."
581587
default = ["8443", "9443", "15017"]
582588
}
583589

firewall.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ resource "google_compute_firewall" "intra_egress" {
6161
https://github.com/kubernetes/kubernetes/issues/79739
6262
*****************************************/
6363
resource "google_compute_firewall" "master_webhooks" {
64-
count = var.add_cluster_firewall_rules ? 1 : 0
64+
count = var.add_cluster_firewall_rules || var.add_master_webhook_firewall_rules ? 1 : 0
6565
name = "gke-${substr(var.name, 0, min(25, length(var.name)))}-webhooks"
6666
description = "Managed by terraform gke module: Allow master to hit pods for admission controllers/webhooks"
6767
project = local.network_project_id

modules/beta-private-cluster-update-variant/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Then perform the following commands on the root folder:
155155
| Name | Description | Type | Default | Required |
156156
|------|-------------|------|---------|:--------:|
157157
| add\_cluster\_firewall\_rules | Create additional firewall rules | `bool` | `false` | no |
158+
| add\_master\_webhook\_firewall\_rules | Create master\_webhook firewall rules for ports defined in `firewall_inbound_ports` | `bool` | `false` | no |
158159
| add\_shadow\_firewall\_rules | Create GKE shadow firewall (the same as default firewall rules with firewall logs enabled). | `bool` | `false` | no |
159160
| authenticator\_security\_group | The name of the RBAC security group for use with Google security groups in Kubernetes RBAC. Group name must be in format [email protected] | `string` | `null` | no |
160161
| basic\_auth\_password | The password to be used with Basic Authentication. | `string` | `""` | no |
@@ -187,7 +188,7 @@ Then perform the following commands on the root folder:
187188
| enable\_shielded\_nodes | Enable Shielded Nodes features on all nodes in this cluster | `bool` | `true` | no |
188189
| enable\_tpu | Enable Cloud TPU resources in the cluster. WARNING: changing this after cluster creation is destructive! | `bool` | `false` | no |
189190
| enable\_vertical\_pod\_autoscaling | Vertical Pod Autoscaling automatically adjusts the resources of pods controlled by it | `bool` | `false` | no |
190-
| firewall\_inbound\_ports | List of TCP ports for admission/webhook controllers | `list(string)` | <pre>[<br> "8443",<br> "9443",<br> "15017"<br>]</pre> | no |
191+
| firewall\_inbound\_ports | List of TCP ports for admission/webhook controllers. Either flag `add_master_webhook_firewall_rules` or `add_cluster_firewall_rules` (also adds egress rules) must be set to `true` for inbound-ports firewall rules to be applied. | `list(string)` | <pre>[<br> "8443",<br> "9443",<br> "15017"<br>]</pre> | no |
191192
| firewall\_priority | Priority rule for firewall rules | `number` | `1000` | no |
192193
| gce\_pd\_csi\_driver | (Beta) Whether this cluster should enable the Google Compute Engine Persistent Disk Container Storage Interface (CSI) Driver. | `bool` | `false` | no |
193194
| gcloud\_upgrade | Whether to upgrade gcloud at runtime | `bool` | `false` | no |

modules/beta-private-cluster-update-variant/firewall.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ resource "google_compute_firewall" "intra_egress" {
5959
https://github.com/kubernetes/kubernetes/issues/79739
6060
*****************************************/
6161
resource "google_compute_firewall" "master_webhooks" {
62-
count = var.add_cluster_firewall_rules ? 1 : 0
62+
count = var.add_cluster_firewall_rules || var.add_master_webhook_firewall_rules ? 1 : 0
6363
name = "gke-${substr(var.name, 0, min(25, length(var.name)))}-webhooks"
6464
description = "Managed by terraform gke module: Allow master to hit pods for admission controllers/webhooks"
6565
project = local.network_project_id

modules/beta-private-cluster-update-variant/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,12 @@ variable "add_cluster_firewall_rules" {
549549
default = false
550550
}
551551

552+
variable "add_master_webhook_firewall_rules" {
553+
type = bool
554+
description = "Create master_webhook firewall rules for ports defined in `firewall_inbound_ports`"
555+
default = false
556+
}
557+
552558
variable "firewall_priority" {
553559
type = number
554560
description = "Priority rule for firewall rules"
@@ -557,7 +563,7 @@ variable "firewall_priority" {
557563

558564
variable "firewall_inbound_ports" {
559565
type = list(string)
560-
description = "List of TCP ports for admission/webhook controllers"
566+
description = "List of TCP ports for admission/webhook controllers. Either flag `add_master_webhook_firewall_rules` or `add_cluster_firewall_rules` (also adds egress rules) must be set to `true` for inbound-ports firewall rules to be applied."
561567
default = ["8443", "9443", "15017"]
562568
}
563569

modules/beta-private-cluster/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ Then perform the following commands on the root folder:
133133
| Name | Description | Type | Default | Required |
134134
|------|-------------|------|---------|:--------:|
135135
| add\_cluster\_firewall\_rules | Create additional firewall rules | `bool` | `false` | no |
136+
| add\_master\_webhook\_firewall\_rules | Create master\_webhook firewall rules for ports defined in `firewall_inbound_ports` | `bool` | `false` | no |
136137
| add\_shadow\_firewall\_rules | Create GKE shadow firewall (the same as default firewall rules with firewall logs enabled). | `bool` | `false` | no |
137138
| authenticator\_security\_group | The name of the RBAC security group for use with Google security groups in Kubernetes RBAC. Group name must be in format [email protected] | `string` | `null` | no |
138139
| basic\_auth\_password | The password to be used with Basic Authentication. | `string` | `""` | no |
@@ -165,7 +166,7 @@ Then perform the following commands on the root folder:
165166
| enable\_shielded\_nodes | Enable Shielded Nodes features on all nodes in this cluster | `bool` | `true` | no |
166167
| enable\_tpu | Enable Cloud TPU resources in the cluster. WARNING: changing this after cluster creation is destructive! | `bool` | `false` | no |
167168
| enable\_vertical\_pod\_autoscaling | Vertical Pod Autoscaling automatically adjusts the resources of pods controlled by it | `bool` | `false` | no |
168-
| firewall\_inbound\_ports | List of TCP ports for admission/webhook controllers | `list(string)` | <pre>[<br> "8443",<br> "9443",<br> "15017"<br>]</pre> | no |
169+
| firewall\_inbound\_ports | List of TCP ports for admission/webhook controllers. Either flag `add_master_webhook_firewall_rules` or `add_cluster_firewall_rules` (also adds egress rules) must be set to `true` for inbound-ports firewall rules to be applied. | `list(string)` | <pre>[<br> "8443",<br> "9443",<br> "15017"<br>]</pre> | no |
169170
| firewall\_priority | Priority rule for firewall rules | `number` | `1000` | no |
170171
| gce\_pd\_csi\_driver | (Beta) Whether this cluster should enable the Google Compute Engine Persistent Disk Container Storage Interface (CSI) Driver. | `bool` | `false` | no |
171172
| gcloud\_upgrade | Whether to upgrade gcloud at runtime | `bool` | `false` | no |

modules/beta-private-cluster/firewall.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ resource "google_compute_firewall" "intra_egress" {
5959
https://github.com/kubernetes/kubernetes/issues/79739
6060
*****************************************/
6161
resource "google_compute_firewall" "master_webhooks" {
62-
count = var.add_cluster_firewall_rules ? 1 : 0
62+
count = var.add_cluster_firewall_rules || var.add_master_webhook_firewall_rules ? 1 : 0
6363
name = "gke-${substr(var.name, 0, min(25, length(var.name)))}-webhooks"
6464
description = "Managed by terraform gke module: Allow master to hit pods for admission controllers/webhooks"
6565
project = local.network_project_id

modules/beta-private-cluster/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,12 @@ variable "add_cluster_firewall_rules" {
549549
default = false
550550
}
551551

552+
variable "add_master_webhook_firewall_rules" {
553+
type = bool
554+
description = "Create master_webhook firewall rules for ports defined in `firewall_inbound_ports`"
555+
default = false
556+
}
557+
552558
variable "firewall_priority" {
553559
type = number
554560
description = "Priority rule for firewall rules"
@@ -557,7 +563,7 @@ variable "firewall_priority" {
557563

558564
variable "firewall_inbound_ports" {
559565
type = list(string)
560-
description = "List of TCP ports for admission/webhook controllers"
566+
description = "List of TCP ports for admission/webhook controllers. Either flag `add_master_webhook_firewall_rules` or `add_cluster_firewall_rules` (also adds egress rules) must be set to `true` for inbound-ports firewall rules to be applied."
561567
default = ["8443", "9443", "15017"]
562568
}
563569

0 commit comments

Comments
 (0)