Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 37 ยท Security and Operators

RBAC in OpenShift: Roles, Bindings and Groups

Control who can do what in OpenShift: roles, cluster roles, role bindings, default roles such as admin, edit and view, groups, oc auth can-i and least privilege.

Role-based access control (RBAC) answers one question: may this subject perform this verb on this resource? OpenShift uses the Kubernetes RBAC API and adds a few ready-made roles and helper commands. Getting RBAC right means teams can deploy to their own projects without being able to touch anyone else's, and nobody holds more power than their job needs.

All commands here are read-only examples. The Python stand-ins model the permission check.

The four objects

Object Scope Purpose
Role One project A list of allowed verbs on resources
ClusterRole Whole cluster Same, but for any project or cluster-level resources
RoleBinding One project Grants a role (or cluster role) to subjects in that project
ClusterRoleBinding Whole cluster Grants a cluster role everywhere

Subjects are users, groups or service accounts. A role holds rules:

YAML
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: pod-reader
  namespace: shop
rules:
  - apiGroups: [""]
    resources: ["pods", "pods/log"]
    verbs: ["get", "list", "watch"]
YAML
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-pods
  namespace: shop
subjects:
  - kind: User
    name: alice
    apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

RBAC is additive: there are no deny rules. A subject's rights are the union of all bindings that apply.

Default cluster roles

You usually bind built-in roles in a project with oc adm policy:

Role What it allows
view Read most objects in the project, but not secrets
edit Create and change most objects, including secrets, but not roles or bindings
admin Everything in the project, including managing access
basic-user Read basic info about projects and the user's own details
self-provisioner Create new projects
cluster-admin Everything, everywhere
Terminal
oc adm policy add-role-to-user edit alice -n shop
oc adm policy add-role-to-group view qa-team -n shop
oc adm policy remove-role-from-user edit alice -n shop
oc get rolebindings -n shop
oc describe rolebinding admin -n shop

Whoever creates a project becomes its admin. Granting cluster-admin is a decision to treat with caution:

Terminal
oc adm policy add-cluster-role-to-user cluster-admin carol

Do not hand cluster-admin to people who only need access to their own project. Give them admin or edit in that project instead.

Checking permissions

oc auth can-i tests a verb, and the --as flag impersonates another subject (you need permission to do that):

Terminal
oc auth can-i create deployments -n shop
oc auth can-i delete pods -n shop --as=alice
oc auth can-i --list -n shop
oc adm policy who-can delete pods -n shop

who-can is invaluable in audits: it lists the users and groups allowed to perform a verb.

Groups

Bind roles to groups instead of individual users. Groups come from your identity provider (LDAP, OIDC) or you can create local ones:

Terminal
oc adm groups new qa-team alice bob
oc adm groups add-users qa-team dave
oc adm policy add-role-to-group view qa-team -n shop

When people join or leave, you change the group, not dozens of bindings.

A permission evaluator

RBAC evaluation is simple enough to model in a few lines: gather every role bound to the subject (directly or through groups), then see whether any rule matches the verb and resource.

Python Stand-in: RBAC check

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice the absence of any deny: bob has no right on secrets simply because no binding grants it, and alice is powerful in shop but nearly powerless in billing.

Least privilege in practice

  1. Start with view, raise to edit only for people who deploy.
  2. Give CI/CD pipelines their own service account with edit in one project (see service accounts), not a person's token.
  3. Create custom roles for narrow jobs, such as "restart deployments only".
  4. Review bindings periodically: oc get rolebindings,clusterrolebindings -A.
  5. Remove the self-provisioner right from system:authenticated:oauth if users must not create projects themselves.
Python Stand-in: find over-privileged subjects

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which built-in role can read most objects in a project but not secrets?

    view is read-only and excludes secrets; edit can change objects, admin can also manage access.
  2. 2. RBAC in Kubernetes and OpenShift works how?

    Rights are the union of all bound roles; anything not granted is denied.
  3. 3. Which command lists who may delete pods in a project?

    oc adm policy who-can VERB RESOURCE answers audit questions.
  4. 4. Why bind roles to groups?

    Group membership is managed centrally, so joiners and leavers need no binding edits.

Summary

  • Roles hold rules; bindings attach roles to users, groups or service accounts.
  • Use view, edit and admin per project; reserve cluster-admin.
  • Test with oc auth can-i; audit with oc adm policy who-can.
  • Prefer groups and service accounts; keep permissions minimal.

Next: Service accounts and secrets