Home/Refreshers/Kubernetes for defenders: refresher
Kubernetes for defenders
The common paths through a cluster, where each one leaves traces, and what stops it.
| Attack path | Look in | Stop it with |
|---|---|---|
| Privileged pod or host mount | Audit log: a pod with privileged, hostPath, or hostPID | An admission policy |
| Stolen service account token | Runtime: the token read by a shell or curl | No token where none is needed |
| Exec into a pod | Audit log: pods/exec, get or create | Few people allowed pods/exec |
| The node's cloud credentials | Cloud audit log: the node's role used elsewhere | On EKS, IMDSv2 with a hop limit of 1 |
| A borrowed workload identity | Audit log, and the cloud audit log | Few people allowed to create pods in that namespace |
| A new role binding | Audit log: bindings to cluster-admin | Few people with bind and escalate |
Commands
| Who may exec | kubectl auth can-i create pods/exec --as <user> -n <namespace> |
| Find cluster-admin bindings | kubectl get clusterrolebindings -o wide | grep cluster-admin |
| Save a pod's definition | kubectl get pod <pod> -o yaml > pod.yaml |
| Logs from before a restart | kubectl logs <pod> --previous |
Watch out
- EKS keeps its audit log off until you switch it on.
- GKE records admin actions by default. Reads of secrets are Data Access logs, off by default.
- Whoever can create a pod with a service account bound to a cloud role has that role.
Check it worked
A test kubectl exec appears in the audit log, with the user, within minutes.