Lab 10: RBAC & Security¶
| Field | Value |
|---|---|
| Tier | 2 — Kubernetes Core |
| Estimated Time | 45 minutes |
| Prerequisites | k3s cluster, kubectl |
| Auto-Grade | Yes |
Scenario¶
Your organization has three teams sharing a Kubernetes cluster: the development team, the operations team, and an external auditor. Currently everyone uses the cluster-admin credentials, which is a compliance violation. The CISO has mandated least-privilege access within two weeks or the cluster gets decommissioned.
You need to create three roles with different permissions. Developers can deploy and manage their own applications within a single namespace but cannot touch cluster-wide resources. Operations can view everything and manage deployments across all namespaces. The auditor has read-only access to everything but cannot create, modify, or delete any resource. Each role needs a ServiceAccount, a Role or ClusterRole, and a RoleBinding or ClusterRoleBinding.
Objectives¶
- Create namespace
lab-rbacfor the development team - Create ServiceAccount
dev-sawith Role allowing CRUD on pods, deployments, services inlab-rbac - Create ServiceAccount
ops-sawith ClusterRole allowing get/list/watch on all resources + CRUD on deployments - Create ServiceAccount
auditor-sawith ClusterRole allowing only get/list/watch on all resources - Verify
dev-saCAN create a deployment inlab-rbac - Verify
dev-saCANNOT list pods inkube-system - Verify
auditor-saCAN list pods but CANNOT delete them
Setup¶
Creates namespace lab-rbac with ServiceAccounts but no roles or bindings.
Hints¶
Hint 1: Creating a Role
Hint 2: RoleBinding vs ClusterRoleBinding
Use `RoleBinding` for namespace-scoped access, `ClusterRoleBinding` for cluster-wide access. The auditor needs a `ClusterRoleBinding` to see all namespaces.Hint 3: Testing with --as
Use `kubectl auth can-i` to test:Hint 4: Read-only ClusterRole
Hint 5: Binding a ServiceAccount
Grading¶
Solution¶
See the solution/ directory for RBAC manifests.