Creating Cloud IAM Policies

This page explains how to create Cloud Identity and Access Management (Cloud IAM) policies for authorization in Kubernetes Engine.

Overview

Every Google Cloud Platform (GCP), Kubernetes Engine, and Kubernetes API call requires that the account making the request has the necessary permissions. By default, no one except you or others granted permission by folder- and organization-level policies can access your project or its resources without being authenticated and authorized. You can use Cloud IAM to manage who can access your project and what they are allowed to do.

To grant users and service accounts access to your GCP project, you need to add them as project team members. Then, you need to assign roles. Roles define which GCP resources an account can access and which operations they can perform.

In Kubernetes Engine, you use Cloud IAM to manage which users and service accounts can access, and perform operations in, your clusters.

Before you begin

To prepare for this task, perform the following steps:

  • Ensure that you have installed the Cloud SDK.
  • Set your default project ID:
    gcloud config set project [PROJECT_ID]
  • Set your default compute zone:
    gcloud config set compute/zone [COMPUTE_ZONE]
  • Update all gcloud commands to the latest version:
    gcloud components update

Interaction with role-based access control

Kubernetes' native role-based access control system also manages access to your cluster. RBAC controls access on a cluster- and namespace-level, while Cloud IAM works on the project-level.

Cloud IAM and RBAC can work in concert, and an entity must have sufficient permissions at either level to work with resources in your cluster.

Cloud IAM Roles

The following sections describe the Cloud IAM roles available in GCP.

Predefined Kubernetes Engine roles

Cloud IAM provides predefined roles that grant access to specific GCP resources and prevent unauthorized access to other resources.

Cloud IAM offers the following predefined roles for Kubernetes Engine:

Role Title Role Name Capabilities Target Users
Kubernetes Engine Admin roles/container.admin Full access to clusters and their Kubernetes resources.
  • Project owners/administrators
  • On-call engineers
  • System administrators
Kubernetes Engine Developer roles/container.developer Full access to Kubernetes resources running in clusters.
  • Developers
  • Release engineers
Kubernetes Engine Viewer roles/container.viewer Read-only access to clusters and their Kubernetes resources.
  • Users who only need visibility into clusters and their resources
Kubernetes Engine Cluster Admin roles/container.clusterAdmin
    When paired with Service Account User, grants permission to create, delete, update, and view clusters only. No access to Kubernetes resources.
  • Users need to only manage clusters, and don't need to access cluster workloads.

To learn about permissions granted by each Kubernetes Engine role, refer to Permissions granted by Cloud IAM roles.

Primitive Cloud IAM roles

Primitive Cloud IAM roles grant users global, project-level access to all GCP resources. To keep your project and clusters secure, you should use predefined roles whenever possible.

To learn more about primitive roles, refer to Primitive Roles in the Cloud IAM documentation.

Service Account User role

Service Account User grants users permission to complete certain tasks using a GCP service account. In Kubernetes Engine, users needing to create, update, and delete clusters might require this role. You pair the Service Account User role with other roles depending on the level of access an entity requires.

For example, if a user with the Cluster Admin role needs to create a cluster, they need to access the Kubernetes Engine default service account. Adding the Service Account User role to the user's Cloud IAM policy ensures that they have permission to use the service account.

Role Title Role Name Capabilities Permissions
Service Account User roles/iam.serviceAccountUser Access to project-level or service-specific service accounts.
  • iam.serviceAccounts.actAs
  • iam.serviceAccounts.get
  • iam.serviceAccounts.list
  • resourcemanager.projects.get
  • resourcemanager.projects.list

Host Service Agent User role

The Host Service Agent User role is only used in Shared VPC clusters.

Role Title Role Name Capabilities Permissions
Host Service Agent User roles/container.hostServiceAgentUser Used with Shared VPC. Grants permission to manage network resources in the host project. This role is granted to the service account of a service project, and it is not granted to users.
  • container.hostServiceAgent.use
  • compute.firewalls.get

Custom roles

If predefined roles don't meet your needs, you can create custom roles with permissions that you define.

To learn how to create and assign custom roles, refer to Creating and Managing Custom Roles.

Permissions granted by Cloud IAM roles

You can view the permissions granted by each role using the gcloud command-line tool or GCP Console.

gcloud

To view the permissions granted by a specific role, run the following command. [ROLE] is any Cloud IAM role. Kubernetes Engine roles are prefixed with roles/container.:

gcloud iam roles describe roles/[ROLE]

For example:

gcloud iam roles describe roles/container.admin

Console

To view the permissions granted by a specific role, perform the following steps:

  1. Visit the Roles section of GCP Console's IAM menu.

    Visit the IAM menu

  2. From the Filter table field, enter "Kubernetes Engine"

  3. Select the desired role.

Managing Cloud IAM policies

To learn how to manage Cloud IAM roles and permissions for users, refer to Granting, Changing, and Revoking Access to Project Members in the Cloud IAM documentation.

For service accounts, refer to Granting Roles to Service Accounts.

Examples

Here are a few examples of how Cloud IAM works with Kubernetes Engine:

  • A new employee has joined a company. They need to be added to the GCP project, but they only need to view the project's clusters and other GCP resources. The project owner assigns them the project-level Viewer role, which contains the compute.projects.get permission required to view projects and their resources.
  • The employee is working in operations, and they need to update a cluster using gcloud or Google Cloud Platform Console. This operation requires the container.clusters.update permission, so the project owner assigns them the Cluster Admin role. The employee now has Cluster Admin and Viewer roles.
  • The employee needs to investigate why a Deployment is having issues. They need to run kubectl get pods to see Pods running in the cluster. The employee already has the Viewer role, which grants this permission.
  • The employee needs to create a new cluster. The project owner grants the employee the Service Account User role, so that the employee's account can access Kubernetes Engine's default service account.

What's next

Was this page helpful? Let us know how we did:

Send feedback about...

Kubernetes Engine