$ skip to content
devresurge

k8s-internals · chapter 16 of 22

15 — Cluster security: trust on the API and the wire

Chapters
  1. Kubernetes Internals — From Linux Up (Book Length)
  2. 01 — Linux processes: the real unit of work
  3. 02 — Namespaces: walls, not VMs
  4. 03 — cgroups: budgets, not walls
  5. 04 — Security primitives: least privilege at the kernel
  6. 05 — OCI images: suitcases of files + config
  7. 06 — containerd & CRI: who actually starts containers
  8. 07 — Pods: shared fate, shared network namespace
  9. 08 — kubelet: the node babysitter
  10. 09 — API server & etcd: the desired-state store
  11. 10 — Controllers: reconcile forever
  12. 11 — Scheduler: who goes where
  13. 12 — Networking: Pod IP → Service → world
  14. 13 — Ingress & Gateway: the L7 front door
  15. 14 — Storage: disks that outlive pods
  16. 15 — Cluster security: trust on the API and the wire
  17. 16 — Troubleshoot: debug like an owner
  18. 17 — etcd deep dive: the notebook behind the librarian
  19. 18 — Controllers deep dive: informers, workqueues, and level triggers
  20. 19 — CNI deep dive: plugging Pods into the network
  21. 20 — eBPF dataplane: services and policy in the kernel
  22. 21 — CSI deep dive: attach, mount, and the sidecar circus
15 — Cluster security: trust on the API and the wire

ELI5 hook

Chapter 04 gave processes seatbelts. Cluster security asks: who may ask the librarian for which books, and which apartments may phone each other. ServiceAccounts are name badges for Pods. RBAC is the permission matrix. Admission is the metal detector at the door. NetworkPolicy is who can dial whom.

Mental model

flowchart TB
  human[Human / CI] -->|"kubeconfig creds"| api[API server]
  pod[Pod] -->|"ServiceAccount token"| api
  api --> rbac[RBAC]
  api --> admit[Admission]
  admit --> etcd[(etcd)]
  pod --> np[NetworkPolicy / CNI]
  np --> other[Other Pods]
LayerControls
AuthnWho are you? (certs, OIDC, SA tokens, webhook)
Authz (RBAC)What verbs on what resources?
AdmissionMutate/validate before persist
Pod securityPrivileges inside the node (PSS)
NetworkPolicyPod ↔ Pod / egress allow rules
SecretsConfidential data distribution (still encrypt etcd!)

What Kubernetes does

ServiceAccounts

Every Pod gets an SA (default: default). The projected token mounts at /var/run/secrets/kubernetes.io/serviceaccount/token for in-cluster API calls. Prefer per-app SAs with minimal RBAC — never hand cluster-admin to a workload.

RBAC

Role / ClusterRole     = verbs + resources (+ optional resourceNames)
RoleBinding / ClusterRoleBinding = who gets that role (User, Group, SA)

Verbs: get, list, watch, create, update, patch, delete, …

Admission

  • Mutating — inject sidecars, defaults
  • Validating — reject dangerous specs (PSS, policy engines)

If a validating webhook is down, you can brick creates/updates — monitor webhooks.

NetworkPolicy

Default: all Pods can talk (unless your CNI defaults otherwise). Policies are additive allow lists for selected Pods — CNI enforces with iptables/eBPF.

How to think in production

GoalMove
Least privilege APIDedicated SA + Role + RoleBinding
Block privileged PodsPod Security Restricted / policy engine
Limit blast radiusNamespaces + NetworkPolicies
Secret hygieneExternal KMS / sealed secrets / CSI secret store; encrypt etcd
Supply chainAdmission image verification

Lab

# Who can I do what as default SA? (usually very little)
kubectl auth can-i list pods --as=system:serviceaccount:default:default

# Create a locked-down SA + role
kubectl create sa course-reader
kubectl create role course-reader --verb=get,list --resource=pods
kubectl create rolebinding course-reader --role=course-reader --serviceaccount=default:course-reader
kubectl auth can-i list pods --as=system:serviceaccount:default:course-reader
kubectl auth can-i delete pods --as=system:serviceaccount:default:course-reader

kubectl delete rolebinding course-reader role course-reader sa course-reader

NetworkPolicy sketch (needs a CNI that enforces policies):

kubectl explain networkpolicy.spec

Gotchas

  • default SA in every namespace — Automount tokens; disable automount when unused.
  • ClusterRoleBinding sprawl — Audit regularly; kubectl get clusterrolebinding.
  • RBAC allows get secrets — Equivalent to reading passwords for that namespace.
  • NetworkPolicy without supporting CNI — Objects apply; nothing enforces.
  • Webhook timeouts — Fail-closed vs fail-open behavior matters for availability vs safety.

Checkpoint

Secure clusters compose API identity, RBAC, admission, pod isolation, and network policy — on top of Linux primitives from chapters 01–04.

Next: 16 — Troubleshoot.


Quiz arc: after chapters 15–16 → /quizzes/k8s-security-ops/