This page provides an overview for role-based access control in Kubernetes Engine.
Kubernetes Engine's role-based access control (RBAC) lets you exercise fine-grained control over how users access the Kubernetes API resources running on your container cluster. You can use RBAC to dynamically configure permissions for your cluster's users and define the kinds of resources with which they can interact.
You can create RBAC permissions that apply to your entire cluster, or to specific namespaces within your cluster. Cluster-wide permissions are useful for limiting certain users' access to specific API resources (such as security policies or Secrets). Namespace-specific permissions are useful if, for example, you have multiple groups of users operating within their own respective namespaces. RBAC can help you ensure that users only have access to cluster resources within their own namespace.
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]
Interaction with Identity and Access Management
Kubernetes Engine also uses Identity and Access Management (IAM) to control access to your container cluster. However, IAM works on a per-project basis—that is, users require IAM-level permissions to access any cluster in a given Cloud Platform project.
RBAC permissions provide finer-grained control over access to resources within each cluster. As such, IAM and RBAC can work in concert, and a user must have sufficient permissions at either level to work with resources in your cluster.
Prerequisites for using Role-Based Access Control
For Kubernetes Engine clusters running Kubernetes versions 1.6 or 1.7,
you must create or update with the option
to ensure that your role-based access control permissions take effect.
Once the cluster has the legacy authorizer disabled, you must grant your user the ability to create authorization roles by running the following Kubernetes command:
kubectl create clusterrolebinding cluster-admin-binding \ --clusterrole cluster-admin --user $(gcloud config get-value account)
Kubernetes Engine clusters running Kubernetes version 1.8 and later disable the legacy authorization system by default, and thus role-based access control permissions take effect with no special action required.
Setting up Role-Based Access Control
You define your RBAC permissions by creating objects
rbac.authorization.k8s.io API group in your cluster. You can create
the objects using the
kubectl command-line interface, or programmatically.
You'll need to create two kinds of objects:
ClusterRoleobject that defines what resource types and operations are allowed for a set of users.
ClusterRoleBindingthat associates the
ClusterRole) with one or more specific users.
RBAC permissions are purely additive--there are no "deny" rules. When structuring your RBAC permissions, you should think in terms of "granting" users access to cluster resources.
Defining Permissions in a
You define permissions within a Kubernetes
ClusterRole API object. A
Role grants access to resources within a single namespace, while a
ClusterRole grants access to resources in the entire cluster.
ClusterRole) object, you define the permissions as a
rules determine the namespace, resource type, and
allowable operations for that role. For example, you can create a
grants read access (operations such as
list) for all Pod
resources in a given namespace.
ClusterRole permissions apply across the entire cluster, you can use
them to control access to different kinds of resources than you can with a
Role. These include:
- Cluster-scoped resources such as Nodes
- Non-resource Endpoints such as
- Namespaced resources across all namespaces (for example, all Pods across the entire cluster, regardless of namespace)
Assigning Permissions to Users with
Once you've created the
ClusterRole), you must create a
ClusterRoleBinding) object to grant the permissions in the
ClusterRole) to a set of users. The users can be individual users,
or Kubernetes service accounts.
ClusterRoleBinding) contains a list of the users, and a
reference to the
ClusterRole) being granted to those users.
API Usage and Examples
For complete information on using the Kubernetes API to create the necessary
ClusterRoleBinding objects for
RBAC, see Using Role-Based Access Control Authorization in
the Kubernetes documentation.