Scenario
A company’s Kubernetes cluster was compromised due to overly permissive RBAC and missing Pod Security Policies. Attackers used a high-privileged ServiceAccount to deploy a malicious pod that gained node-level root access.
Symptoms
- Unknown pods appearing in the cluster with no clear origin.
kubectl get podsshows unusual containers (e.g., crypto-miners).- Audit logs show excessive
create podevents from an unexpected user. - Node CPU/memory usage spikes unexpectedly.
Diagnosis
- List all RBAC bindings:
bash kubectl get rolebindings,clusterrolebindings -A -o wideIdentify bindings grantingcluster-adminto suspicious subjects. - Inspect audit logs (if enabled):
bash kubectl logs -n kube-system apiserver | grep -i “user=<suspicious>” - Check existing Pod Security Policies (or Pod Security Admission):
bash kubectl get psp # if using deprecated PSP - Review NetworkPolicies:
bash kubectl get networkpolicies -ATypically none are defined, allowing unrestricted traffic.
Commands & Remediation
Step 1: Least Privilege RBAC
- Remove dangerous bindings:
bash kubectl delete clusterrolebinding <binding-name> - Create fine-grained roles:
bash kubectl create role pod-reader --verb=get,list,watch --resource=pods kubectl create rolebinding dev-pod-reader --role=pod-reader --user=dev-user
Step 2: Enforce Pod Security Standards
- Label namespaces to enforce
restrictedprofile (K8s v1.23+):bash kubectl label --overwrite ns <namespace> pod-security.kubernetes.io/enforce=restricted
Step 3: Network Policies
- Create a default deny ingress policy:
```yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-ingress
spec:
podSelector: {}
policyTypes:
- Ingress ```
Step 4: Secrets Management
- Stop storing secrets in ConfigMaps. Use external secret stores (e.g., HashiCorp Vault) or Sealed Secrets.
Risk Controls
- Test all changes on a non-production cluster first or use a clone.
- Use
--dry-run=clientwhen applying RBAC changes. - Keep backup YAML files for every modified resource.
Rollback
- If new policies break applications:
bash kubectl apply -f backup-rbac.yaml kubectl label ns <namespace> pod-security.kubernetes.io/enforce- # remove label
Verification
- Test user permissions:
bash kubectl auth can-i create pods --as=dev-user # Should return 'no' - Attempt to run a privileged pod (should be rejected):
bash kubectl run test-pod --image=nginx --privileged - Review audit logs to confirm no unauthorized activity.
When to Submit an OpsGlobal Ticket
- The cluster is actively compromised and needs immediate forensics and recovery.
- Your team lacks expertise in security hardening and requires expert guidance.
- Advanced security controls (e.g., runtime security, CIS benchmarks) are needed.
- You suspect insider threats or long-term malicious persistence.
OpsGlobal’s SRE experts can help restore quickly, deploy security tooling, and provide ongoing monitoring.
Use cases
Useful for teams handling Security issues and needing a clear troubleshooting and delivery workflow.
Problem background
A real-world scenario-driven guide to securing Kubernetes clusters, including RBAC auditing, Pod Security admission, and rollback procedures.
Troubleshooting steps
Confirm impact and recent changes, collect logs, configuration and metrics, then apply fixes from low to high risk.
Command examples
Replace sample resource names with real values and store passwords, tokens and keys in environment variables.
Risks
Before production changes, confirm backups, access boundaries, change windows and rollback paths.
Rollback plan
Keep original configuration and release versions; roll back config, images or database changes if metrics degrade.
Deliverables
Root-cause notes, key commands, remediation steps, verification results and follow-up recommendations.
Need help with a similar technical issue?
If your servers, Kubernetes, Docker, CI/CD, databases or monitoring systems have similar issues, submit logs and config files for remote diagnosis.