Cloud Security
Advanced 20 min read Cloud Security

Kubernetes Security Posture

Secure the control plane, the workload plane, and the supply of both: RBAC, admission policy, network policies, and secrets-in-etcd without a plaintext excuse.

KubernetesRBACadmission webhooknetwork policyPSP/PSAetcdsecrets
Introduction

What is this?

Kubernetes security spans the control plane (API server, etcd, RBAC), the workload plane (admission policy, network policy, pod runtime), and their supply chain.

Motivation

Why do you need it?

  • K8s is the most common runtime target today: one RBAC mistake or mislabeled namespace can grant cross-tenant admin.
  • The control plane is a super-user rich in every app's data — protecting it is protecting everything it orchestrates.
  • Admission and network policy are the 'SG + segmentation' of Kubernetes; absent them, pods are flat-trust.
Think about it

Mental model

Imagine

An airport control tower

Think of

Every gate agent having tower privileges

The tower (API/etcd) concentrates authority; granting it to every scheduling request is how runways get mixed up.

Mechanics

How it works

  • RBAC binds roles (permissions on API resources) to subjects; default is deny for unbound identities.
  • Admission controllers (PSA or webhooks) force policy at write-time: non-root, no privileged, image provenance.
  • Network policies are per-namespace default-deny: only allowed pod-to-pod flows exist.
  • Secrets are base64 in etcd until encrypted at rest — encryption-at-rest on etcd is non-negotiable at scale.

The K8s security layers

API
Admission
Scheduler
Network
etcd/Data
Real world

In production

  • A fintech enforces 'no privileged containers, no hostNet, environments pinned' via an admission webhook at the API layer.
  • A retail platform sets default-deny network policies then allows only the dashboard->api->db chain.
  • An enterprise encrypts etcd at rest and rotates service-account tokens on a rotation cycle.
Guidelines

Best practices

  • Lock down the API server: HTTPS only, strong authn, minimal anonymous access, and admit policy in the door.
  • Prefer namespace-wide default-deny network policies; review the allow-list before relaxing.
  • Never store secrets in plaintext env vars — use the Secrets API with etcd encryption and RBAC read gates.
  • Run pod security admission (or equivalent) at warn/audit first, then enforce.
Watch out

Common mistakes

  • Cluster-admin for 'convenience' on a service account a compromised pod can inherit.
  • A default 'allow all' network policy that means every pod reaches the control plane port.
  • Secrets in the image's env or in the manifest repo — base64 is not encryption.
  • Patching the app but never auditing the RBAC bindings that grant the blast radius.
When things break

Debugging tips

  • When a pod can't be scheduled, check admission policy errors in the events, not the image build.
  • Use kubectl auth can-i to test a subject's exact permission — faster than reading solitaire role YAML.
  • For network-policy silence, exec a ping/nc from one pod to another and read the CNPI logs.
Security

Security considerations

  • The cluster's audit log is evidence: enable it, ship it immutably, and alert on escalated permissions.
  • Treat service accounts like machine identities: automated rotation, lifecycle check, and least scope.
Interviews

Interview checkpoint

Practice

Hands-on lab

Model RBAC and Network Policy in a Local Cluster
55 min · advanced
In progress
Objectives
  • Create a namespace, a least-privilege service account, and RBAC that grants read-only on pods.
  • Verify the account can read but not mutate.
  • Write a NetworkPolicy pattern and predict its default-deny effect.

Model RBAC and Network Policy in a Local Cluster

55 min · advanced

0/4 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

Which layer decides 'this Deployment object is allowed to exist'?

2

K8s Secrets are base64 in etcd unless...

Go deeper

Official documentation