RBAC monitoring
Author: Fabrice JAMMES (LinkedIn).
Objective
Somewhere in the cluster, a ServiceAccount has been granted far more power than it needs. Find it, explain the risk, and propose a least-privilege fix.
The CKS curriculum lists “Use Role Based Access Controls to minimize exposure” and “Exercise caution in using service accounts” in the Cluster hardening domain.
Setup
The lab works on the shared cluster: the trainer injects the security issue once, for all the trainees.
Info
Trainer only, once per cluster, before the lab (sec-issue.sh does the same):
Exercise 1: find the over-privileged service account
Find the bindings which grant the ClusterRole cluster-admin. Which one does not belong to the cluster administrators or to the system components?
Tip
In the exam, only kubectl is available: kubectl get clusterrolebindings -o wide shows the role and the subjects of each binding. On the training server, these tools help too: rbac-tool who-can create pods, kubectl access-matrix (rakkess), kubescape scan control C-0035 -v.
Exercise 2: the risk
What can an attacker do with a pod running in the namespace monitor?
Exercise 3: propose a fix
The monitoring application only needs to read the pods and the nodes of the cluster. Write the least-privilege fix:
- a dedicated service account
monitoringinmonitor - a
ClusterRolemonitoring-reader, withget,listandwatchonpodsandnodes - a
ClusterRoleBindingwhich grants it tomonitor:monitoring - the deletion of
cluster-monitoring
The cluster is shared: test the fix with --dry-run=server, the trainer applies it at the end of the lab.
Questions
- How do you find this kind of issue regularly, without searching by hand?
- Which other RBAC rights are as dangerous as
cluster-admin?
Info
Trainer only, at the end of the lab: