LAB05: Authorization in Kubernetes

Create a user: ram

Create a group: DevOps

Assign ram → group DevOps

Give ram full access to vpsxyz namespace

Create a StorageAdmin role so ram can manage Storage resources

(PVC, PV, StorageClass)

This lab uses client certificates (recommended for kubeadm labs).

LAB OUTLINE

  1. Create user certificate → ram

  2. Add ram to DevOps group

  3. Add ram to kubeconfig

  4. Create namespace vpsxyz

  5. Create Role + RoleBinding for namespace ownership

  6. Create StorageAdmin ClusterRole

  7. Bind StorageAdmin to ram

  8. Test access as ram

1. Create Private Key for User ram

On control-plane:

2. Create CSR (with group DevOps)

The group is defined in the CSR using O=DevOps.

  • CN = username

  • O = group

Kubernetes will treat:

  • username → ram

  • group → DevOps


3. Sign the CSR with the Kubernetes Cluster CA

You now have:

  • ram.key

  • ram.crt

4. Add ram user to kubeconfig

5. Create a context for ram

Switch to ram (later during testing):

6. Create namespace vpsxyz

7. Create Role: Namespace Owner (read/write all inside vpsxyz)

vpsxyz-owner.yaml:

Apply:

8. Bind ram (or DevOps group) to namespace owner

Option A: Bind the group DevOps (recommended)

Apply:

➡ Any user in group DevOps (like ram) can now fully control vpsxyz namespace.

9. Create StorageAdmin ClusterRole

This role gives the user the ability to manage:

  • StorageClasses

  • PersistentVolumes

  • PersistentVolumeClaims

storage-admin.yaml:

Apply:


10. Bind ram (or DevOps group) to StorageAdmin

Recommended: Bind the group:

storage-binding.yaml:

Apply:

11. Test as ram

Switch to ram:

Test namespace access:

Should work.

Test StorageAdmin:

Try creating a PVC:

Apply:

Should work.

Last updated