Scenario
A company runs a multi-tenant Kubernetes cluster where multiple teams deploy workloads. A security audit reveals that some pods can access the host node's filesystem due to privileged containers or hostPath volumes.
Symptoms
- Pods can read sensitive host files like /etc/shadow.
- Security scanners report violations of Pod Security Standards.
- Unexpected network connections or resource access.
Diagnosis
- Check for privileged containers:
bash kubectl get pods --all-namespaces -o jsonpath='{range .items[*]}{.metadata.namespace} {.metadata.name} {.spec.containers[*].securityContext.privileged}{"\n"}{end}'An output containingtrueindicates privileged containers. - Check for hostPath volumes:
bash kubectl get pods --all-namespaces -o jsonpath='{range .items[*]}{.metadata.namespace} {.metadata.name} {.spec.volumes[*].hostPath}{"\n"}{end}' - Review RBAC permissions:
bash kubectl get rolebindings,clusterrolebindings --all-namespaces -o wideLook for inappropriate bindings, e.g., granting cluster-admin to regular users.
Risk Controls
- Enforce Pod Security Admission with a global
restrictedpolicy. - Use OPA/Gatekeeper or Kyverno to deny privileged containers and hostPath.
- Implement NetworkPolicies to restrict inter-pod traffic.
- Apply least-privilege RBAC, avoid wildcards (
*). - Enable audit logging and review regularly.
Rollback
If policies break applications, roll back via GitOps:
git revert <commit-hash>
kubectl apply -f <previous-config>
Alternatively, temporarily delete the admission controller webhook configuration.
Verification
- Re-run diagnosis commands to confirm no privileged containers.
- Run kube-bench for security benchmarks:
bash kubectl run kube-bench --image=aquasec/kube-bench:latest --restart=Never --rm --command -- /kube-bench run --targets=master,node - Check audit logs for policy violation denials.
When to Submit an OpsGlobal Ticket
- When mass remediation of legacy workloads is needed.
- If a security breach has occurred, requiring rapid forensics and isolation.
- When cluster-wide policy enforcement is beyond the team's expertise.
Use cases
Useful for teams handling Security issues and needing a clear troubleshooting and delivery workflow.
Problem background
Learn how to identify and fix common Kubernetes security weaknesses that SRE teams face, with step-by-step commands and risk controls.
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.