This page explains how to create Cloud Identity and Access Management (Cloud IAM) policies for authorization in Kubernetes Engine.
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
gcloudcommands 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||
||Full access to clusters and their Kubernetes resources.||
|Kubernetes Engine Developer||
||Full access to Kubernetes resources running in clusters.||
|Kubernetes Engine Viewer||
||Read-only access to clusters and their Kubernetes resources.||
|Kubernetes Engine Cluster Admin||
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||
||Access to project-level or service-specific service accounts.||
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||
||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.||
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
command-line tool or GCP Console.
To view the permissions granted by a specific role, run the following
[ROLE] is any Cloud IAM role.
Kubernetes Engine roles are prefixed with
gcloud iam roles describe roles/[ROLE]
gcloud iam roles describe roles/container.admin
To view the permissions granted by a specific role, perform the following steps:
Visit the Roles section of GCP Console's IAM menu.
From the Filter table field, enter "Kubernetes Engine"
- 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.
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.getpermission required to view projects and their resources.
- The employee is working in operations, and they need to update a cluster using
gcloudor Google Cloud Platform Console. This operation requires the
container.clusters.updatepermission, 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 podsto 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.