Thuta Learning
AdvancedDevOpsintermediate

RBAC & Security Basics

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand RBAC & Security Basics without feeling intimidated by them
  • Get comfortable running the kubectl commands/YAML yourself
  • Be able to apply this concept immediately in a real project

Let's think about it this way for a second

A cluster admin can run 'anything' with Kubernetes commands, but giving every team admin access is dangerous (like accidentally deleting a production deployment). RBAC has 4 core concepts — Role (a set of permissions within one namespace, like 'can view pods'), ClusterRole (cluster-level permissions), RoleBinding (attaching a Role to a user/group), and ClusterRoleBinding (attaching a ClusterRole). Service Accounts matter here too — when an app inside a Pod itself needs to call the Kubernetes API (like a CI/CD tool), it needs to be given scoped permissions through a Service Account.

Let's connect this to a real scenario

If you create a `pod-reader` Role (with only get, list, watch permissions) for a developer team and connect team members to it with a RoleBinding, they can view pods but can't create or delete them. A CI/CD pipeline (like GitHub Actions) should only be given deployment-update permission, not cluster-wide admin permission.

Let's look at it together

yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: staging
  name: pod-reader
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-pods
  namespace: staging
subjects:
  - kind: User
    name: dev-team
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io
You should see
$ kubectl auth can-i delete pods --as=dev-team -n staging
no

$ kubectl auth can-i get pods --as=dev-team -n staging
yes

5-Minute Try-It

Apply a `pod-reader` Role and RoleBinding, then confirm the permissions with the `kubectl auth can-i` command.

A Quick Word of Caution

Don't put off setting up RBAC on a production cluster as something for 'later' — if every developer/CI tool starts out with default admin access, tightening it later gets a lot harder.

Easy traps

  • Giving everyone the cluster-admin ClusterRole (violating the least-privilege principle) — this raises troubleshooting/incident risk
  • Running a Service Account with default permissions (the default namespace token) — if the app gets compromised, the attacker's access scope can end up much wider than it should be

Now Try It Yourself

Apply a `pod-reader` Role and RoleBinding, then confirm the permissions with the `kubectl auth can-i` command.

You'll know it worked when: $ kubectl auth can-i delete pods --as=dev-team -n staging no $ kubectl auth can-i get pods --as=dev-team -n staging yes

RBAC & Security Basics | Thuta Learning