Configure GKE node service accounts

Your Google Kubernetes Engine (GKE) nodes use Identity and Access Management (IAM) serviceaccounts for tasks like logging and pulling container images for workloads. Thisdocument shows platform administrators and security engineers how to grant rolesto service accounts for specific use cases and how to create custom serviceaccounts instead of using a default service account. For more information, seeNode service accounts.

Before you begin

Before you start, make sure that you have performed the following tasks:

  • Enable the Google Kubernetes Engine API.
  • Enable Google Kubernetes Engine API
  • If you want to use the Google Cloud CLI for this task,install and theninitialize the gcloud CLI. If you previously installed the gcloud CLI, get the latest version by running thegcloud components update command. Earlier gcloud CLI versions might not support running the commands in this document.Note: For existing gcloud CLI installations, make sure to set thecompute/regionproperty. If you use primarily zonal clusters, set thecompute/zone instead. By setting a default location, you can avoid errors in the gcloud CLI like the following:One of [--zone, --region] must be supplied: Please specify location. You might need to specify the location in certain commands if the location of your cluster differs from the default that you set.

Required roles

To get the permissions that you need to manage IAM service accounts and roles, ask your administrator to grant you the following IAM roles:

  • Security Admin (roles/iam.securityAdmin) on the cluster project
  • Configure service accounts in a separate project:Security Admin (roles/iam.securityAdmin) on the service account project

For more information about granting roles, seeManage access to projects, folders, and organizations.

You might also be able to get the required permissions throughcustom roles or otherpredefined roles.

Grant the minimum required role for GKE

GKE uses IAM service accounts that are attached to your nodes to run system tasks like logging and monitoring. At a minimum, thesenode service accounts must have theKubernetes Engine Default Node Service Account (roles/container.defaultNodeServiceAccount) role on your project. By default, GKE uses theCompute Engine default service account, which is automatically created in your project, as the node service account.

If your organization enforces theiam.automaticIamGrantsForDefaultServiceAccounts organization policy constraint, the default Compute Engine service account in your project might not automatically get the required permissions for GKE.

Note: If your organization was created on or after May 3, 2024, this constraint is enforced by default.

The following sections show you how to grant theroles/container.defaultNodeServiceAccount role to the defaultCompute Engine service account or to a new custom service account thatyou create.

Best practice:

Create a custom service account for your nodes instead of using the defaultCompute Engine service account.

Configure the default Compute Engine service account

To grant theroles/container.defaultNodeServiceAccount role to the Compute Engine default service account, complete the following steps:

Console

  1. Go to theWelcome page:

    Go to Welcome

  2. In theProject number field, clickCopy to clipboard.
  3. Go to theIAM page:

    Go to IAM

  4. ClickGrant access.
  5. In theNew principals field, specify the following value:
    PROJECT_NUMBER-compute@developer.gserviceaccount.com
    ReplacePROJECT_NUMBER with the project number that you copied.
  6. In theSelect a role menu, select theKubernetes Engine Default Node Service Account role.
  7. ClickSave.

gcloud

  1. Find your Google Cloud project number:
    gcloudprojectsdescribePROJECT_ID\--format="value(projectNumber)"

    ReplacePROJECT_ID with your project ID.

    The output is similar to the following:

    12345678901
  2. Grant theroles/container.defaultNodeServiceAccount role to the Compute Engine default service account:
    gcloudprojectsadd-iam-policy-bindingPROJECT_ID\--member="serviceAccount:PROJECT_NUMBER-compute@developer.gserviceaccount.com"\--role="roles/container.defaultNodeServiceAccount"

    ReplacePROJECT_NUMBER with the project number from the previous step.

Configure a custom node service account

To create a custom service account and grant it the required role for GKE, complete the following steps:

Console

  1. Go to theService accounts page:

    Go to Service accounts

  2. ClickCreate service account.
  3. Enter a name for the service account. TheService account ID field automatically generates a unique ID for the service account based on the name.
  4. ClickCreate and continue.
  5. In theSelect a role menu, select theKubernetes Engine Default Node Service Account role.
  6. ClickDone.

gcloud

  1. Create the service account:
    gcloudiamservice-accountscreateSA_NAME

    ReplaceSA_NAME with a unique name that identifies the service account.

  2. Grant theKubernetes Engine Default Node Service Account (roles/container.defaultNodeServiceAccount) role to the service account:
    gcloudprojectsadd-iam-policy-bindingPROJECT_ID\--member="serviceAccount:SA_NAME@PROJECT_ID.iam.gserviceaccount.com"\--role=roles/container.defaultNodeServiceAccount

    Replace the following:

    • PROJECT_ID: your Google Cloud project ID.
    • SA_NAME: the name of the service account that you created.

Terraform

Create an IAM service account and grant it theroles/container.defaultNodeServiceAccount role on the project:

resource"google_service_account""default"{account_id="gke-node-service-account"display_name="GKE node service account"}data"google_project""project"{}resource"google_project_iam_member""default"{project=data.google_project.project.project_idrole="roles/container.defaultNodeServiceAccount"member="serviceAccount:${google_service_account.default.email}"}

Config Connector

Note: This step requiresConfig Connector. Follow theinstallation instructions to install Config Connector on your cluster.

  1. To create the service account, download the following resource asservice-account.yaml:
    apiVersion:iam.cnrm.cloud.google.com/v1beta1kind:IAMServiceAccountmetadata:name:[SA_NAME]spec:displayName:[DISPLAY_NAME]

    Replace the following:

    • [SA_NAME]: the name of the new service account.
    • [DISPLAY_NAME]: a display name for the service account.
  2. Create the service account:
    kubectlapply-fservice-account.yaml
  3. Apply theroles/logging.logWriter role to the service account:
    1. Download the following resource aspolicy-logging.yaml.
      apiVersion:iam.cnrm.cloud.google.com/v1beta1kind:IAMPolicyMembermetadata:name:policy-loggingspec:member:serviceAccount:[SA_NAME]@[PROJECT_ID].iam.gserviceaccount.comrole:roles/logging.logWriterresourceRef:kind:Projectname:[PROJECT_ID]

      Replace the following:

      • [SA_NAME]: the name of the service account.
      • [PROJECT_ID]: your Google Cloud project ID.
    2. Apply the role to the service account:
      kubectlapply-fpolicy-logging.yaml
  4. Apply theroles/monitoring.metricWriter role to the service account:
    1. Download the following resource aspolicy-metrics-writer.yaml. Replace[SA_NAME] and[PROJECT_ID] with your own information.
      apiVersion:iam.cnrm.cloud.google.com/v1beta1kind:IAMPolicyMembermetadata:name:policy-metrics-writerspec:member:serviceAccount:[SA_NAME]@[PROJECT_ID].iam.gserviceaccount.comrole:roles/monitoring.metricWriterresourceRef:kind:Projectname:[PROJECT_ID]

      Replace the following:

      • [SA_NAME]: the name of the service account.
      • [PROJECT_ID]: your Google Cloud project ID.
    2. Apply the role to the service account:
      kubectlapply-fpolicy-metrics-writer.yaml
  5. Apply theroles/monitoring.viewer role to the service account:
    1. Download the following resource aspolicy-monitoring.yaml.
      apiVersion:iam.cnrm.cloud.google.com/v1beta1kind:IAMPolicyMembermetadata:name:policy-monitoringspec:member:serviceAccount:[SA_NAME]@[PROJECT_ID].iam.gserviceaccount.comrole:roles/monitoring.viewerresourceRef:kind:Projectname:[PROJECT_ID]

      Replace the following:

      • [SA_NAME]: the name of the service account.
      • [PROJECT_ID]: your Google Cloud project ID.
    2. Apply the role to the service account:
      kubectlapply-fpolicy-monitoring.yaml
  6. Apply theroles/autoscaling.metricsWriter role to the service account:
    1. Download the following resource aspolicy-autoscaling-metrics-writer.yaml.
      apiVersion:iam.cnrm.cloud.google.com/v1beta1kind:IAMPolicyMembermetadata:name:policy-autoscaling-metrics-writerspec:member:serviceAccount:[SA_NAME]@[PROJECT_ID].iam.gserviceaccount.comrole:roles/autoscaling.metricsWriterresourceRef:kind:Projectname:[PROJECT_ID]

      Replace the following:

      • [SA_NAME]: the name of the service account.
      • [PROJECT_ID]: your Google Cloud project ID.
    2. Apply the role to the service account:
      kubectlapply-fpolicy-autoscaling-metrics-writer.yaml

You can also use this service account for resources in other projects. For instructions, seeEnabling service account impersonation across projects.

Allow principals to attach custom service accounts

You can attach a custom service account when you create a cluster or a nodepool. To let a principal (such as a platform administrator) use a custom serviceaccount to create GKE resources, grant theService Account User(roles/iam.serviceAccountUser) role on the custom service account to thatprincipal. To grant this role, select one of the following options:

Console

  1. In the Google Cloud console, go to theService accounts page:

    Go to Service accounts

    In the resource selector, choose the project that contains your customservice account.

  2. Select the checkbox for the custom service account that you created to usewith GKE nodes.

  3. ClickManage access.TheManage Access pane opens.

  4. ClickAdd principal.TheGrant access pane opens.

  5. In theNew principals field, specify the principal, such as anadministrator group.

  6. In theSelect a role drop-down menu, select theService AccountUser role.

  7. ClickSave. TheGrant access pane closes.

  8. Close theManage Access pane.

gcloud

Grant theroles/iam.serviceAccountUser role:

gcloudiamservice-accountsadd-iam-policy-binding\SA_NAME@SERVICE_ACCOUNT_PROJECT_ID.iam.gserviceaccount.com\--member=PRINCIPAL\--role=roles/iam.serviceAccountUser

Replace the following:

  • SA_NAME: the name of the custom service account.
  • SERVICE_ACCOUNT_PROJECT_ID: the project ID that contains thecustom service account.
  • PRINCIPAL: theprincipal identifier, such asuser:baklavainthebalkans@example.com.

Config Connector

Note: This step requiresConfig Connector. Follow theinstallation instructions to install Config Connector on your cluster.

Apply theiam.serviceAccountUser role to your service account. Download thefollowing resource aspolicy-service-account-user.yaml. Replace[SA_NAME]and[PROJECT_ID] with your own information.

apiVersion:iam.cnrm.cloud.google.com/v1beta1kind:IAMPolicyMembermetadata:name:policy-service-account-userspec:member:serviceAccount:[SA_NAME]@[PROJECT_ID].iam.gserviceaccount.comrole:roles/iam.serviceAccountUserresourceRef:kind:Projectname:[PROJECT_ID]
kubectl apply -f policy-service-account-user.yaml

After you grant the role on the service account, those principals can use thatservice account to create clusters and node pools. For more information, seethe following documents:

Configure service account usage across projects

If your node service account isn't in the same project as your cluster, serviceagents in the cluster project need additional permissions on the serviceaccount. For more information, seeNode service accounts and project service agents.

To grant the required roles on node service accounts that aren't in your clusterproject, follow these steps:

  1. To enable cross-project service account attachment,update your organization policies.
  2. To grant the required roles on the custom service account to the serviceagents in your cluster project, select one of the following options:

    Console

    1. In the Google Cloud console, go to theService accounts page.

      Go to Service accounts

    2. Select the checkbox for the custom service account that you created touse with GKE nodes.

    3. ClickManage access.TheManage Access pane opens.

    4. Grant the Service Account Token Creator role to theCompute Engine service agent in your cluster project:

      1. In theManage Access pane, clickAdd principal.TheGrant access pane opens.
      2. In theNew principals field, specify the email address of theCompute Engine service agent in your cluster project:

        service-CLUSTER_PROJECT_NUMBER@compute-system.iam.gserviceaccount.com

        ReplaceCLUSTER_PROJECT_NUMBER with theproject number of your cluster project.

      3. In theSelect a role menu, select theService Account TokenCreator role.

      4. ClickSave. TheGrant access pane closes.

    5. Grant the Service Account User role to the GKE serviceagent in your cluster project:

      1. In theManage Access pane, clickAdd principal.TheGrant access pane opens.
      2. In theNew principals field, specify the email address of theGKE service agent in your cluster project:

        service-CLUSTER_PROJECT_NUMBER@container-engine-robot.iam.gserviceaccount.com
      3. In theSelect a role menu, select theService Account Userrole.

      4. ClickSave. TheGrant access pane closes.

    6. Close theManage Access pane.

    gcloud

    1. Get the project number of your cluster project:

      gcloudprojectsdescribeCLUSTER_PROJECT_ID\--format='value(projectNumber)'

      ReplaceCLUSTER_PROJECT_ID with the projectID of your cluster project.

      The output is similar to123456789.

    2. Grant theroles/iam.serviceAccountTokenCreator role on the customservice account to the Compute Engine service agent in yourcluster project:

      gcloudiamservice-accountsadd-iam-policy-binding\SA_NAME@SERVICE_ACCOUNT_PROJECT_ID.iam.gserviceaccount.com\--member=service-CLUSTER_PROJECT_NUMBER@compute-system.iam.gserviceaccount.com\--role=roles/iam.serviceAccountTokenCreator

      Replace the following:

      • SA_NAME: the name of the custom serviceaccount.
      • SERVICE_ACCOUNT_PROJECT_ID: the projectID of the project that contains your custom service account.
      • CLUSTER_PROJECT_NUMBER: the projectnumber of your cluster project.
    3. Grant theroles/iam.serviceAccountUser role on the customservice account to the GKE service agent in yourcluster project:

      gcloudiamservice-accountsadd-iam-policy-binding\SA_NAME@SERVICE_ACCOUNT_PROJECT_ID.iam.gserviceaccount.com\--member=service-CLUSTER_PROJECT_NUMBER@container-engine-robot.iam.gserviceaccount.com\--role=roles/iam.serviceAccountUser

Allow image pulls from private repositories

If you have images in private Artifact Registry repositories, you must give your nodeservice account access to those repositories. Even if you use the defaultCompute Engine service account, you might need to give the serviceaccount access to your repository if the repository is in another project.

Note: The steps in this section give access to the repository only to your nodeservice account. The workloads in your cluster don't get this access. To giveyour GKE workloads access to Google Cloud resources,useWorkload Identity Federation for GKE.

To pull private images from Artifact Registry, grant theArtifact Registry Reader role(roles/artifactregistry.reader) on the repository to your node service account.

Console

  1. In the Google Cloud console, go to theRepositories page.

    Go to Repositories

  2. Select the checkbox for your repository.

  3. ClickShow info panel. The repository information pane opens.

  4. In thePermissions tab, clickAdd principal. TheGrant access pane opens.

  5. In theNew principals field, specify theemail address of your node service account.

  6. ClickSelect a role to open the role selection dialog.

  7. Select theArtifact Registry Reader role.

  8. ClickSave.

gcloud

Grant theroles/artifactregistry.reader role on the repository:

gcloudartifactsrepositoriesadd-iam-policy-bindingREPOSITORY_NAME\--member=serviceAccount:SERVICE_ACCOUNT_EMAIL\--project=REPOSITORY_PROJECT_ID\--role=roles/artifactregistry.reader

Replace the following:

  • REPOSITORY_NAME: the name of theArtifact Registry repository.
  • SERVICE_ACCOUNT_EMAIL: theemail address of your node service account.
  • REPOSITORY_PROJECT_ID: the project ID of theproject that contains your repository.

Config Connector

Note: This step requiresConfig Connector. Follow theinstallation instructions to install Config Connector on your cluster.

Note: These steps assume that you use Config Connector to manage yourArtifact Registry repository. If your repository doesn't exist as aConfig Connector resource, these steps won't work.
  1. Save the following manifest aspolicy-artifact-registry-reader.yaml:

    apiVersion:iam.cnrm.cloud.google.com/v1beta1kind:IAMPolicyMembermetadata:name:policy-artifact-registry-readerspec:member:serviceAccount:"SA_NAME"@"PROJECT_ID".iam.gserviceaccount.comrole:roles/artifactregistry.readerresourceRef:apiVersion:artifactregistry.cnrm.cloud.google.com/v1beta1kind:ArtifactRegistryRepositoryname:"REPOSITORY_NAME"

    Replace the following:

    • SA_NAME: the name of your IAMservice account.
    • PROJECT_ID: your Google Cloud project ID.
    • REPOSITORY_NAME: the name of yourArtifact Registry repository.
  2. Grant the Artifact Registry Reader role to the service account:

    kubectlapply-fpolicy-artifact-registry-reader.yaml

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.