Skip to content

Commit 3ebf04a

Browse files
authored
feat: enable binauthz for autopilot (#2030)
1 parent 3fc4db4 commit 3ebf04a

File tree

9 files changed

+35
-2
lines changed

9 files changed

+35
-2
lines changed

autogen/main/cluster.tf.tmpl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,15 @@ resource "google_container_cluster" "primary" {
208208
{% if autopilot_cluster != true %}
209209
default_max_pods_per_node = var.default_max_pods_per_node
210210
enable_shielded_nodes = var.enable_shielded_nodes
211+
{% endif %}
211212

212213
dynamic "binary_authorization" {
213214
for_each = var.enable_binary_authorization ? [var.enable_binary_authorization] : []
214215
content {
215216
evaluation_mode = "PROJECT_SINGLETON_POLICY_ENFORCE"
216217
}
217218
}
219+
{% if autopilot_cluster != true %}
218220

219221
dynamic "identity_service_config" {
220222
for_each = var.enable_identity_service ? [var.enable_identity_service] : []
@@ -248,7 +250,7 @@ resource "google_container_cluster" "primary" {
248250
enabled = secret_manager_config.value
249251
}
250252
}
251-
253+
252254
enable_fqdn_network_policy = var.enable_fqdn_network_policy
253255
{% endif %}
254256
{% if autopilot_cluster %}
@@ -1039,7 +1041,7 @@ resource "google_container_node_pool" "windows_pools" {
10391041
for_each = length(merge(
10401042
local.node_pools_linux_node_configs_sysctls["all"],
10411043
local.node_pools_linux_node_configs_sysctls[each.value["name"]],
1042-
local.node_pools_cgroup_mode[each.value["name"]] == "" ? {} : {cgroup = local.node_pools_cgroup_mode[each.value["name"]]}
1044+
local.node_pools_cgroup_mode[each.value["name"]] == "" ? {} : {cgroup = local.node_pools_cgroup_mode[each.value["name"]]}
10431045
)) != 0 ? [1] : []
10441046

10451047
content {

autogen/main/variables.tf.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,12 +743,14 @@ variable "enable_shielded_nodes" {
743743
default = true
744744
}
745745

746+
{% endif %}
746747
variable "enable_binary_authorization" {
747748
type = bool
748749
description = "Enable BinAuthZ Admission controller"
749750
default = false
750751
}
751752

753+
{% if autopilot_cluster != true %}
752754
variable "node_metadata" {
753755
description = "Specifies how node metadata is exposed to the workload running on the node"
754756
default = "GKE_METADATA"

examples/autopilot_private_firewalls/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module "gke" {
5252
add_shadow_firewall_rules = true
5353
network_tags = ["allow-google-apis"]
5454
deletion_protection = false
55+
enable_binary_authorization = true
5556

5657
master_authorized_networks = [
5758
{

modules/beta-autopilot-private-cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Then perform the following commands on the root folder:
8888
| description | The description of the cluster | `string` | `""` | no |
8989
| disable\_default\_snat | Whether to disable the default SNAT to support the private use of public IP addresses | `bool` | `false` | no |
9090
| dns\_cache | The status of the NodeLocal DNSCache addon. | `bool` | `true` | no |
91+
| enable\_binary\_authorization | Enable BinAuthZ Admission controller | `bool` | `false` | no |
9192
| enable\_cilium\_clusterwide\_network\_policy | Enable Cilium Cluster Wide Network Policies on the cluster | `bool` | `false` | no |
9293
| enable\_confidential\_nodes | An optional flag to enable confidential node config. | `bool` | `false` | no |
9394
| enable\_cost\_allocation | Enables Cost Allocation Feature and the cluster name and namespace of your GKE workloads appear in the labels field of the billing export to BigQuery | `bool` | `false` | no |

modules/beta-autopilot-private-cluster/cluster.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ resource "google_container_cluster" "primary" {
8585
enabled = var.enable_vertical_pod_autoscaling
8686
}
8787

88+
dynamic "binary_authorization" {
89+
for_each = var.enable_binary_authorization ? [var.enable_binary_authorization] : []
90+
content {
91+
evaluation_mode = "PROJECT_SINGLETON_POLICY_ENFORCE"
92+
}
93+
}
94+
8895
enable_l4_ilb_subsetting = var.enable_l4_ilb_subsetting
8996

9097
enable_cilium_clusterwide_network_policy = var.enable_cilium_clusterwide_network_policy

modules/beta-autopilot-private-cluster/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,12 @@ variable "database_encryption" {
469469
}]
470470
}
471471

472+
variable "enable_binary_authorization" {
473+
type = bool
474+
description = "Enable BinAuthZ Admission controller"
475+
default = false
476+
}
477+
472478

473479
variable "gke_backup_agent_config" {
474480
type = bool

modules/beta-autopilot-public-cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Then perform the following commands on the root folder:
8181
| description | The description of the cluster | `string` | `""` | no |
8282
| disable\_default\_snat | Whether to disable the default SNAT to support the private use of public IP addresses | `bool` | `false` | no |
8383
| dns\_cache | The status of the NodeLocal DNSCache addon. | `bool` | `true` | no |
84+
| enable\_binary\_authorization | Enable BinAuthZ Admission controller | `bool` | `false` | no |
8485
| enable\_cilium\_clusterwide\_network\_policy | Enable Cilium Cluster Wide Network Policies on the cluster | `bool` | `false` | no |
8586
| enable\_confidential\_nodes | An optional flag to enable confidential node config. | `bool` | `false` | no |
8687
| enable\_cost\_allocation | Enables Cost Allocation Feature and the cluster name and namespace of your GKE workloads appear in the labels field of the billing export to BigQuery | `bool` | `false` | no |

modules/beta-autopilot-public-cluster/cluster.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ resource "google_container_cluster" "primary" {
8585
enabled = var.enable_vertical_pod_autoscaling
8686
}
8787

88+
dynamic "binary_authorization" {
89+
for_each = var.enable_binary_authorization ? [var.enable_binary_authorization] : []
90+
content {
91+
evaluation_mode = "PROJECT_SINGLETON_POLICY_ENFORCE"
92+
}
93+
}
94+
8895
enable_l4_ilb_subsetting = var.enable_l4_ilb_subsetting
8996

9097
enable_cilium_clusterwide_network_policy = var.enable_cilium_clusterwide_network_policy

modules/beta-autopilot-public-cluster/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,12 @@ variable "database_encryption" {
433433
}]
434434
}
435435

436+
variable "enable_binary_authorization" {
437+
type = bool
438+
description = "Enable BinAuthZ Admission controller"
439+
default = false
440+
}
441+
436442

437443
variable "gke_backup_agent_config" {
438444
type = bool

0 commit comments

Comments
 (0)