Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beta-autopilot-private-cluster uses default service account #1488

Closed
TrieBr opened this issue Dec 5, 2022 · 5 comments · Fixed by #1495
Closed

beta-autopilot-private-cluster uses default service account #1488

TrieBr opened this issue Dec 5, 2022 · 5 comments · Fixed by #1495
Labels
bug Something isn't working

Comments

@TrieBr
Copy link

TrieBr commented Dec 5, 2022

TL;DR

Using the beta-autopilot-private-cluster uses a the default service account for the cluster created in GCP.

gcloud container clusters describe --region northamerica-northeast2 cluster-main-test-29420926 | grep serviceAccount
    serviceAccount: default
  serviceAccount: default
    serviceAccount: default

Looking in cluster.tf I don't even see any reference to the service_account variable.

Expected behavior

The cluster should use the service account created by the module.

Observed behavior

Cluster uses default service account which is against GKE hardening guidelines.

Terraform Configuration

resource "random_id" "cluster" {
  byte_length = 4
}

// Subnet for Cluster.
resource "google_compute_subnetwork" "cluster-subnet" {
  project       = var.project_id
  name          = "cluster-${var.name}-subnet-${var.environment_realm}-${random_id.cluster.hex}"
  ip_cidr_range = "10.3.0.0/16"
  region        = var.region
  network       = var.network
  private_ip_google_access = true
  secondary_ip_range {
    range_name    = "cluster-${var.name}-subnet-${var.environment_realm}-range-pods"
    ip_cidr_range = "192.168.10.0/24"
  }
  secondary_ip_range {
    range_name    = "cluster-${var.name}-subnet-${var.environment_realm}-range-services"
    ip_cidr_range = "192.168.11.0/24"
  }
  depends_on = [
    var.network
  ]
}

module "main-cluster" {
  source                     = "terraform-google-modules/kubernetes-engine/google//modules/beta-autopilot-private-cluster"
  project_id                 = var.project_id
  name                       = "cluster-${var.name}-${var.environment_realm}-${random_id.cluster.hex}"
  region                     = var.region
  zones                      = ["${var.region}-a", "${var.region}-b"]
  network                    = var.network
  subnetwork                 = google_compute_subnetwork.cluster-subnet.name
  ip_range_pods              = "cluster-${var.name}-subnet-${var.environment_realm}-range-pods"
  ip_range_services          = "cluster-${var.name}-subnet-${var.environment_realm}-range-services"
  horizontal_pod_autoscaling = true
  enable_private_endpoint    = false
  enable_private_nodes       = true
  enable_vertical_pod_autoscaling = true
  release_channel = "RAPID"
  
  master_ipv4_cidr_block     = "10.0.0.0/28"
  depends_on = [
    google_compute_subnetwork.cluster-subnet
  ]
}

Terraform Version

+ provider registry.terraform.io/hashicorp/google v4.36.0
+ provider registry.terraform.io/hashicorp/google-beta v4.44.1
+ provider registry.terraform.io/hashicorp/kubernetes v2.16.0
+ provider registry.terraform.io/hashicorp/null v3.2.1
+ provider registry.terraform.io/hashicorp/random v3.4.3
+ provider registry.terraform.io/hashicorp/time v0.9.1

Additional information

No response

@bharathkkb
Copy link
Member

@TrieBr Thanks for the report! I believe we initially did not add this due to the conflictsWith on the provider. Happy to review a PR fixing this if the provider bug is resolved.

https://github.com/hashicorp/terraform-provider-google/blob/d2ea6580ef848edd94862d13ab7cddcb162df904/google/resource_container_cluster.go#L386

@ferrarimarco
Copy link
Contributor

Hi @bharathkkb ! I tried fixing this in #1495 :)

@rojomisin
Copy link

So does changing an Autopilot cluster's service account work for anyone yet? I've read a lot of threads now and I've put in a support ticket, but I keep seeing resolved and merged PRs, but with the latest 4.54 provider using google_container_cluster and adding

  cluster_autoscaling {
    auto_provisioning_defaults {
      ### https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster#service_account
      service_account = var.service_account
    }
  }

I get a successful plan, but the apply gives:

│ Error: googleapi: Error 400: Overriding Autopilot autoscaling settings is not allowed., badRequest

@rojomisin
Copy link

per google support :

We would like to inform you that in the Autopilot GKE cluster the default SA can be changed only at the time of an Autopilot cluster creation and the SA for an existing Autopilot cluster cannot be changed.

I'm going to ask about why they have an update command which wouldn't support this, and if this is specified in their documentation, however just wanted to relay the information. Was this already known and assumed by the terraform gke module authors?

1 similar comment
@rojomisin
Copy link

per google support :

We would like to inform you that in the Autopilot GKE cluster the default SA can be changed only at the time of an Autopilot cluster creation and the SA for an existing Autopilot cluster cannot be changed.

I'm going to ask about why they have an update command which wouldn't support this, and if this is specified in their documentation, however just wanted to relay the information. Was this already known and assumed by the terraform gke module authors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants