|
| 1 | ++++ |
| 2 | +title = "GCP Workload Identity" |
| 3 | ++++ |
| 4 | + |
| 5 | +[**GCP Workload Identity**](https://cloud.google.com/kubernetes-engine/docs/concepts/workload-identity) allows workloads in your GKE clusters to impersonate Identity and Access Management (IAM) service accounts to access Google Cloud services. |
| 6 | + |
| 7 | +You can tell KEDA to use GCP Workload Identity via `podIdentity.provider`. |
| 8 | + |
| 9 | +```yaml |
| 10 | +podIdentity: |
| 11 | + provider: gcp # Optional. Default: none |
| 12 | +``` |
| 13 | +### Steps to set up Workload Identity |
| 14 | +If you are using podIdentity provider as `gcp`, you need to set up workload identity as below and your GKE cluster must have Workload Identity enabled. |
| 15 | + |
| 16 | +* You need to create a GCP IAM service account with proper permissions to retrive metrics for particular scalers. |
| 17 | + |
| 18 | + ```shell |
| 19 | + gcloud iam service-accounts create GSA_NAME \ |
| 20 | + --project=GSA_PROJECT |
| 21 | + ``` |
| 22 | + |
| 23 | + Replace the following: \ |
| 24 | + GSA_NAME: the name of the new IAM service account.\ |
| 25 | + GSA_PROJECT: the project ID of the Google Cloud project for your IAM service account. |
| 26 | + |
| 27 | + |
| 28 | +* Ensure that your IAM service account has the [roles](https://cloud.google.com/iam/docs/understanding-roles) you need. You can grant additional roles using the following command: |
| 29 | + |
| 30 | + ```shell |
| 31 | + gcloud projects add-iam-policy-binding PROJECT_ID \ |
| 32 | + --member "serviceAccount:GSA_NAME@GSA_PROJECT.iam.gserviceaccount.com" \ |
| 33 | + --role "ROLE_NAME" |
| 34 | + ``` |
| 35 | + |
| 36 | + Replace the following: |
| 37 | + |
| 38 | + PROJECT_ID: your Google Cloud project ID. \ |
| 39 | + GSA_NAME: the name of your IAM service account. \ |
| 40 | + GSA_PROJECT: the project ID of the Google Cloud project of your IAM service account. \ |
| 41 | + ROLE_NAME: the IAM role to assign to your service account, like roles/monitoring.viewer. |
| 42 | + |
| 43 | +* Allow the Kubernetes service account to impersonate the IAM service account by adding an IAM policy binding between the two service accounts. This binding allows the Kubernetes service account to act as the IAM service account. |
| 44 | + ```shell |
| 45 | + gcloud iam service-accounts add-iam-policy-binding GSA_NAME@GSA_PROJECT.iam.gserviceaccount.com \ |
| 46 | + --role roles/iam.workloadIdentityUser \ |
| 47 | + --member "serviceAccount:PROJECT_ID.svc.id.goog[NAMESPACE/KSA_NAME]" |
| 48 | + ``` |
| 49 | + Replace the following: |
| 50 | + |
| 51 | + PROJECT_ID: your Google Cloud project ID. \ |
| 52 | + GSA_NAME: the name of your IAM service account. \ |
| 53 | + GSA_PROJECT: the project ID of the Google Cloud project of your IAM service account. \ |
| 54 | + NAMESPACE: Namespace where keda operator is installed; defaults to `keda` . \ |
| 55 | + KSA_NAME: Kubernetes service account name of the keda; defaults to `keda-operator` . |
| 56 | +* Then you need to annotate the Kubernetes service account with the email address of the IAM service account. |
| 57 | + |
| 58 | + ```shell |
| 59 | + kubectl annotate serviceaccount keda-operator \ |
| 60 | + --namespace keda \ |
| 61 | + iam.gke.io/gcp-service-account=GSA_NAME@GSA_PROJECT.iam.gserviceaccount.com |
| 62 | + ``` |
| 63 | + Replace the following: \ |
| 64 | + |
| 65 | + GSA_NAME: the name of your IAM service account. \ |
| 66 | + GSA_PROJECT: the project ID of the Google Cloud project of your IAM service account. |
| 67 | + |
| 68 | + |
| 69 | + Refer to GCP official [documentation](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity#authenticating_to) for more. |
0 commit comments