Skip to main content


How to Secure Kubernetes with RBAC and Avoid Risks with kubectl

Beyond RBAC: Additional Security Measures

kubectl is a powerful command-line tool used to manage Kubernetes clusters. However, certain commands can expose sensitive information or disrupt cluster operations if misused. Ensuring proper configuration and rigorous oversight is crucial to maintaining the security and integrity of the cluster.


High-Risk kubectl Commands

kubectl get cm -n kube-system

This command retrieves all ConfigMaps in the kube-system namespace, including critical configuration files like the kubelet or kubeadm configurations, potentially exposing sensitive information.


kubectl cluster-info

Provides detailed information about the cluster, which can be exploited if accessed by unauthorized users.


kubectl config <verb>

Commands like kubectl config view give insight into cluster configurations, while kubectl config set-context or kubectl config use-context allow modifications, which can lead to unauthorized changes.


kubectl delete <resource>

This command deletes Kubernetes objects, which can disrupt services and applications if used improperly.


Mitigation Measures

Since not all commands can be restricted via RBAC, it is essential to implement additional security measures:


Define Clear Permissions with RBAC:

Use Role-Based Access Control (RBAC) to define clear permissions for users, specifying who can perform which actions. Ensure roles are assigned based on the principle of least privilege.



kind: Role


  namespace: default

  name: pod-reader


- apiGroups: [""]

  resources: ["pods"]

  verbs: ["get", "watch", "list"]


kind: RoleBinding


  name: read-pods

  namespace: default


- kind: User

  name: jane



  kind: Role

  name: pod-reader




Monitor Command Usage:

Implement monitoring and logging for kubectl command usage. Track who is running which commands and alert administrators of any suspicious activity.


kind: Policy


  - level: Metadata

    users: ["system:serviceaccount:kube-system:default"]

    verbs: ["create", "update", "patch", "delete"]

    resources: ["secrets", "configmaps"]


Restrict Access to Sensitive Commands:

Use tools like admission controllers to enforce policies that restrict access to high-risk commands and sensitive resources.


Regular Security Audits:

Conduct regular security audits to review RBAC configurations and ensure compliance with best practices. Identify and mitigate potential vulnerabilities.


Use Multi-Factor Authentication (MFA):

Require MFA for accessing Kubernetes clusters to add an additional layer of security.


Educate and Train Administrators:

Ensure that administrators and users are aware of the potential risks associated with kubectl commands and the importance of following security best practices.

follow these measures