Security Resources

⌘K
  1. Home
  2. Security Resources
  3. Cloud & Container Securit...
  4. Kubernetes RBAC and Cluster Security Hardening

Kubernetes RBAC and Cluster Security Hardening

Kubernetes Cluster Defense & RBAC Hardening Playbook
Production hardening for Kubernetes: Role-Based Access Control (RBAC) audit, service account token projection, admission controllers, and network policies.

1. The Danger of Over-Permissive ClusterRoles


Binding pods or service accounts to cluster-admin or broad resources: ["*"], verbs: ["*"] allows an attacker who achieves remote code execution in any pod to compromise the entire Kubernetes control plane.

# Vulnerable: Insecure ClusterRole granting wildcard privileges
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: app-operator
rules:
- apiGroups: ["*"]
  resources: ["*"]
  verbs: ["*"]

2. Hardened Least-Privilege Role & RoleBinding


Restrict permissions strictly to the target namespace, specify exact resources, and limit verbs to read-only where possible:

# Secure: Scoped Role restricted to read ConfigMaps in the 'backend' namespace
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: backend
  name: configmap-reader
rules:
- apiGroups: [""]
  resources: ["configmaps"]
  verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: bind-configmap-reader
  namespace: backend
subjects:
- kind: ServiceAccount
  name: backend-api-sa
  namespace: backend
roleRef:
  kind: Role
  name: configmap-reader
  apiGroup: rbac.authorization.k8s.io

3. Disabling Default Service Account Token Auto-Mounting


By default, Kubernetes mounts an API token into every pod at /var/run/secrets/kubernetes.io/serviceaccount/. If your application does not query the Kubernetes API, disable auto-mounting:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: backend-api-sa
  namespace: backend
automountServiceAccountToken: false

4. Zero-Trust NetworkPolicy (Default Deny Ingress/Egress)

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
  namespace: backend
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  - Egress