Scenario
A fast-growing startup runs its production workloads on a Kubernetes cluster with default RBAC and permissive network policies. The security team detects unusual API calls from an external IP in audit logs, suggesting unauthorized access.
Symptoms
- Audit logs show
kubectl get secretsfrom unexpected users. - Pods can reach resources in other namespaces.
- Service accounts have excessive privileges, e.g., default
defaultservice account bound tocluster-admin.
Diagnosis
- Review RBAC bindings:
kubectl get clusterrolebindings -o wideandkubectl get rolebindings --all-namespaces -o wide. - Test permissions:
kubectl auth can-i --list --as=system:serviceaccount:default:default. - Check network policies:
kubectl get networkpolicies --all-namespaces. - Examine Pod Security Policies:
kubectl get psp.
Hardening Commands
# Remove dangerous cluster-admin binding
kubectl delete clusterrolebinding default-admin
# Create minimal service account
kubectl create serviceaccount my-app -n production
kubectl create role my-app-role --verb=get,list,watch --resource=pods,services -n production
kubectl create rolebinding my-app-binding --role=my-app-role --serviceaccount=production:my-app -n production
# Apply default deny network policy
kubectl apply -f - <<EOF
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
EOF
# Enable audit logging (if not already)
audit-policy.yaml:
apiVersion: audit.k8s.io/v1
kind: Policy
rules:
- level: RequestResponse
Risk Controls
- Backup existing RBAC before changes:
kubectl get clusterrolebindings -o yaml > clusterrolebindings-backup.yaml - Test network policies in non-production clusters first.
- Tighten permissions incrementally to avoid breaking services.
Rollback Plan
If hardening causes legitimate requests to fail:
kubectl apply -f clusterrolebindings-backup.yaml
kubectl delete networkpolicy default-deny
Re-apply permissive policies and note affected services.
Verification
- Re-run diagnosis commands; sensitive actions should be denied.
kubectl auth can-i list secrets --as=system:serviceaccount:default:defaultshould returnno.- Check audit logs for denied unauthorized calls.
When to Submit a Ticket
- Internal team lacks RBAC best practices expertise for designing a least-privilege model.
- Cluster has been compromised, requiring forensic analysis and incident response.
- Need advanced security controls (e.g., OPA/Gatekeeper, kube-bench scanning) but lack experience.
- Contact OpsGlobal at support@opsglobal.com for 24/7 remote SRE assistance.
Use cases
Useful for teams handling Security issues and needing a clear troubleshooting and delivery workflow.
Problem background
This post walks through a real-world scenario of securing a Kubernetes cluster, including diagnosis, commands, risk controls, rollback, verification, and when to escalate to OpsGlobal professional support.
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.