Defining Permissions with Rules
You'll learn: How to precisely define what actions RBAC subjects can perform using Rules with apiGroups, resources, and verbs.
What Are Rules?
In Kubernetes RBAC, Rules are the building blocks that define permissions. Think of a Rule like a permission slip that says "You may perform these specific actions on these specific things." Every Role and ClusterRole contains one or more Rules that grant access to Kubernetes API resources.
The Three Components of a Rule
Each Rule consists of three key elements:
1. apiGroups
Specifies which API group the resources belong to. The core API group is represented by an empty string "". Other examples include apps, batch, or rbac.authorization.k8s.io.
2. resources
Lists the Kubernetes resource types the rule applies to, like pods, services, deployments, or configmaps.
3. verbs
Defines the allowed actions. Common verbs include:
get- read individual resourceslist- read collectionswatch- monitor for changescreate- make new resourcesupdate- modify existing resourcespatch- partial updatesdelete- remove resources
How Rules Work Together
You can specify multiple values in each field using arrays. For example, allowing someone to view and list pods would use verbs ["get", "list"]. Using wildcards (*) grants all permissions in that category—use cautiously!
Think of it like a library card system: The apiGroup is which section of the library, resources are which types of books, and verbs are what you can do with them (read, borrow, return).
Key Takeaway: Rules in RBAC combine apiGroups, resources, and verbs to create granular permissions that precisely control what actions subjects can perform on specific Kubernetes resources.