Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes: Role vs ClusterRole

Tags:

kubernetes

Which is the difference between a Role or a ClusterRole?

When should I create one or the other one?

I don't quite figure out which is the difference between them.

like image 535
Jordi Avatar asked Aug 02 '18 07:08

Jordi


People also ask

What is the difference between role and ClusterRole in Kubernetes?

A Role always sets permissions within a particular namespace; when you create a Role, you have to specify the namespace it belongs in. ClusterRole, by contrast, is a non-namespaced resource.

Why is RBAC needed in Kubernetes?

Kubernetes RBAC is a key security control to ensure that cluster users and workloads have only the access to resources required to execute their roles.

Which Kubernetes resource is used in Role based access control?

Role-based access control (RBAC) is a way of granting users granular access to Kubernetes API resources. RBAC is a security design that restricts access to Kubernetes resources based on the role the user holds. API Objects for configuring RBAC: Role , ClusterRole , RoleBinding and ClusterRoleBinding .


2 Answers

From the documentation:

A Role can only be used to grant access to resources within a single namespace.

Example: List all pods in a namespace

A ClusterRole can be used to grant the same permissions as a Role, but because they are cluster-scoped, they can also be used to grant access to:

cluster-scoped resources (like nodes)
non-resource endpoints (like “/healthz”)
namespaced resources (like pods) across all namespaces (needed to run kubectl get pods --all-namespaces, for example)

Examples: List all pods in all namespaces. Get a list of all nodes and theis public IP.

like image 110
herm Avatar answered Oct 12 '22 23:10

herm


Cluster roles also allow for the reuse of common permission sets across namespaces (via role bindings). The bootstrap admin, edit and view cluster roles are the canonical examples.

like image 24
monis Avatar answered Oct 12 '22 22:10

monis