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

feat: WorkloadIdenity allow to use k8s sa from the different project #1275

Conversation

ykyr
Copy link
Contributor

@ykyr ykyr commented May 31, 2022

WorkloadIdenity can be used for cross-project linking.
It is useful in some use-cases:

  • when you have deployed workload with pre-created k8s SA in the GKE cluster that lives in the proj B. But we want to use Google SA from proj A.

PR adds the possibility to specify a different k8s_sa_project_id.

Example of usage:

module "my_app_workload_identity" {
  source              = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity"
  use_existing_k8s_sa = true
  annotate_k8s_sa     = false
  k8s_sa_name         = "my-k8s-sa"
  namespace           = "prod"
  k8s_sa_project_id   = "proj-B"
  name                = "my-gcp-sa"
  project_id          = "proj-A"
}

Terraform plan:

Terraform will perform the following actions:

  # module.my_app_workload_identity.google_service_account.cluster_service_account[0] will be created
  + resource "google_service_account" "cluster_service_account" {
      + account_id   = "my-gcp-sa"
      + disabled     = false
      + display_name = "GCP SA bound to K8S SA proj-B[my-k8s-sa]"
      + email        = (known after apply)
      + id           = (known after apply)
      + name         = (known after apply)
      + project      = "proj-A"
      + unique_id    = (known after apply)
    }

  # module.my_app_workload_identity.google_service_account_iam_member.main will be created
  + resource "google_service_account_iam_member" "main" {
      + etag               = (known after apply)
      + id                 = (known after apply)
      + member             = "serviceAccount:proj-B.svc.id.goog[prod/my-k8s-sa]"
      + role               = "roles/iam.workloadIdentityUser"
      + service_account_id = (known after apply)
    }

Plan: 2 to add, 0 to change, 0 to destroy.

@ykyr ykyr requested review from a team, Jberlinsky and bharathkkb as code owners May 31, 2022 15:12
@google-cla
Copy link

google-cla bot commented May 31, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ykyr ykyr changed the title feat: allow to use k8s sa from the different project feat: WorkloadIdenity allow to use k8s sa from the different project May 31, 2022
@ykyr ykyr force-pushed the feat/allow_ksa_from_the_different_project branch from 4a69d25 to a01b041 Compare June 2, 2022 08:37
Copy link
Member

@bharathkkb bharathkkb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @ykyr

@comment-bot-dev
Copy link

@ykyr
Thanks for the PR! 🚀
✅ Lint checks have passed.

@bharathkkb bharathkkb merged commit 4f5dded into terraform-google-modules:master Jun 29, 2022
CPL-markus pushed a commit to WALTER-GROUP/terraform-google-kubernetes-engine that referenced this pull request Jul 15, 2024
…erraform-google-modules#1275)

* feat: allow to use k8s sa from the different project

* chore: generate docs

Co-authored-by: Bharath KKB <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants