In Kubernetes, a ClusterRole and a Role define authorisation rules to access Kubernetes resources either on a cluster level (ClusterRole) or on a particular namespace (Role).
A ClusterRole is a non-namespaced resource that allows you to define permissions across the entire cluster. It can grant access to resources like nodes, namespaces, or persistent volumes that exist at the cluster level, independent of any particular namespace. On the other hand, a Role operates within the boundary of a particular namespace and is used to grant permissions on resources such as Pods, Services, or ConfigMaps that exist within that namespace.
This ClusterRole for example allows read access to all pods in the cluster:
And this Role allows writing (creating, updating, deleting) to pods in a particular namespace (my-namespace for this instance):
In order for a workload (Pod) to be able to use these permissions:
- That pod must have a ServiceAccount
- The ServiceAccount must have a RoleBinding/ClusterRoleBinding that reference the Role/ClusterRole
However Pods aren’t used directly in Kubernetes (usually), they are instead controlled by Deployments, ReplicaSets, DaemonSets, Jobs or CronJobs and therefore in order to truly understand the impact of changing a Role/ClusterRole, we need to link all the way back to these controlling resources. This means that the whole relationship looks like this:
This means that in order to work out the true potential impact of changing a Role/ClusterRole, we must follow all of the relationships in this diagram. Here are the commands you need:
Get the details of a role:
Get the bindings that refer to that role
Get the ServiceAccounts that use a given ClusterRoleBinding bindings
Get the Pods that use that ServiceAccount
Note that in the above command we produce the ownerKind and ownerName columns. These show what type of resource owns this pod, e.g. a ReplicaSet, DaemonSet, Job or CronJob
Get the CronJob that controls a given Job:
Get the CronJob that controls a given Job:
Get the Deployment that controls a ReplicaSet:
Get the details of a deployment:
With Overmind
Overmind allows you to determine the potential blast radius of changes to ClusterRoles, Deployments and any other Kubernetes or AWS resources before you make them. Using current application config it acts as a second pair of eyes, analysing your config changes to calculate any dependencies. From the blast radius it can provide a list of human readable risks that can be reviewed prior to deploying the changes.These risks can either be commented back as part of your CI / CD pipeline or viewed in the app.
To get started calculating the impact of a change to a ClusterRole, firstly create a free Overmind account.
Next you will need to create a change. This can be done by:
- Get started quickly using the Overmind Github action. The action will automatically create a new change with the resources and items parsed from your Terraform plan output.
- Integrate Overmind into any CI /CD tool using the CLI.
- Coming soon or by using the Overmind CLI to run a plan and apply locally.
Select the relevant ClusterRole as the expected change. From there Overmind automatically determines the potential impact in real time:
Interested in learning more, join our Discord or check out our Terraform example repository.