Kubernetes Security Basics for Defenders
Kubernetes security basics for defenders: control who can change the cluster (RBAC), isolate workloads (namespaces and network policy), keep secrets out of images, run containers with least privilege, and watch the API audit log — so one bad pod does not become a whole-cluster incident.
Friends! kubectl power and an exposed dashboard = classic foot-gun. Today beginner K8s defence: RBAC, network policy, secrets, non-root, admission themes. No exploit recipes. Own cluster / authorised lab only — do not scan random clusters on the public internet.
मित्रांनो! kubectl power आणि exposed dashboard = classic foot-gun. आज beginner K8s defence: RBAC, network policy, secrets, non-root, admission themes. Exploit recipes नाही. Own cluster / authorised lab only — public internet वर random clusters scan नको.
मित्रों! kubectl power और exposed dashboard = classic foot-gun. आज beginner K8s defence: RBAC, network policy, secrets, non-root, admission themes. Exploit recipes नहीं. Own cluster / authorised lab only — public internet पर random clusters scan नहीं.
Quick answer
Kubernetes security — vertical starter checklist:
- Never leave the API server or dashboard reachable from the open internet without strong auth.
- Avoid standing
cluster-adminfor humans; prefer namespaced roles + MFA on the identity provider. - Separate prod / non-prod namespaces; default-deny network policy where the CNI supports it.
- Mount secrets as short-lived volumes — not baked into images or ConfigMaps with passwords.
- Run as non-root; drop risky capabilities; set resource limits.
- Scan images in CI; pin digests when you can.
- Enable and ship API server audit logs to your SIEM.
Tiny mental model:
Identity → RBAC → Admission → Runtime (pod security) → Network → Audit
Exposed dashboard = “please crypto-mine me” era lessons
kubectl = production change control, not a toy
What do I need before this guide?
- Cloud shared duty mindset: Cloud IAM least privilege.
- Optional containers context from supply chain: SBOM / dependency / secrets.
- Optional Zero Trust flavour: Zero Trust explained simply.
What are we protecting in a cluster?
Cluster defence layers: RBAC, network policy and hardened workloads with secrets kept out of images — plus audit logs.
Cluster defence layers: RBAC, network policy आणि hardened workloads with secrets images बाहेर — plus audit logs.
Cluster defence layers: RBAC, network policy और hardened workloads with secrets images के बाहर — plus audit logs.
Layers beginners should name in interviews:
- Cluster identity — who can talk to the API server.
- RBAC — which verbs on which resources.
- Admission / policy — block privileged pods before they schedule (vendor tools vary).
- Workload hardening — non-root, read-only root FS themes, seccomp where supported.
- Network — east-west limits so a web pod cannot freely hit the metadata service or payroll DB.
- Secrets & supply chain — image provenance, SCA, secret managers.
- Detection — audit logs, runtime sensors, SIEM alerts on weird
exec/ secret reads.
Educational warning: practise on minikube / kind / a cloud sandbox you own. Do not “test RBAC” on a shared company prod cluster without change tickets — you can lock teams out or expose services.
Real incident: Tesla Kubernetes cryptojacking (2018)
Public reporting on a 2018 Tesla cloud incident described an unauthenticated Kubernetes dashboard exposure that attackers used to run cryptocurrency mining workloads. The lasting lesson for every student cluster: management UIs and API endpoints are crown jewels. Convenience “open for debugging” kills.
Takeaways (vertical):
- What happened — cluster console exposure leading to abusive workloads (mining) in public analyses.
- What went wrong (theme) — internet-facing admin surface without adequate authentication.
- Care-take — private control planes; SSO + MFA; no anonymous dashboard.
- Care-take — network policies and egress controls limit miner profit even after a foothold.
- Care-take — alert on sudden CPU / new Deployments in sensitive namespaces.
- Bonus parallel — Capital One–era cloud identity lessons: metadata and over-broad roles still matter beside K8s RBAC.
Red Team vs Blue Team (awareness only)
Red Team — what attackers try
- Find open dashboards, kubelets, or mis-bound Services of type LoadBalancer.
- Steal service account tokens from mounts inside a compromised pod (high-level).
- Escape or widen access when pods run privileged (themes — not a how-to).
- Abuse CI credentials that can
kubectl applyto prod.
Blue Team — defend, detect, respond
- SSO to the API; short-lived creds; no long-lived kubeconfig on laptops without disk encryption + MFA.
- Pod security standards / policies that deny privileged by default.
- Secrets in KMS-backed stores; rotate on leak.
- Audit log → SIEM:
exec, secret get bursts, new ClusterRoleBindings. - Break-glass admin with tickets and alarms.
How do I apply basics step by step?
Step 1 — Lock the front door
- Confirm the API server endpoint is not anonymously usable from the internet.
- Remove or strongly authenticate any dashboard.
- Restrict
kubectlaccess via your identity provider groups.
Step 2 — RBAC least privilege
- Inventory ClusterRoles and RoleBindings.
- Replace standing
cluster-adminfor humans with namespace-scoped roles. - CI bots get only the verbs they need (often apply in one namespace).
Step 3 — Namespace and network boundaries
- One team / app per namespace when practical.
- Default-deny ingress/egress policies; open only documented paths.
- Keep kube-system and ingress controllers tightly watched.
Step 4 — Workload hardening
runAsNonRoot, drop capabilities, read-only root filesystem where apps allow.- CPU/memory limits — noisy neighbours and fork bombs hurt everyone.
- Prefer distroless or minimal base images from maintained sources.
Step 5 — Secrets and images
- No passwords in environment variables committed to git.
- Image scan in CI; block critical fixable CVEs on prod paths.
- Pin versions; record SBOMs for cluster images you ship.
Step 6 — Detect and practise (lab)
- On a local kind/minikube cluster you own, create a read-only role and prove AccessDenied on delete.
- Turn on audit logging (or provider equivalent) and ship a sample to your lab SIEM.
- Deploy a deliberate too-open Service only inside host-only / local networking — never on a public VPS without auth.
- Tabletop: “dashboard open for 2 hours — revoke, rotate, review Deployments”.
Starter policy themes (descriptive, not a paste-blind prod YAML)
- Deny privileged containers in app namespaces.
- Deny hostNetwork / hostPID for normal apps.
- Allow egress to approved CIDRs / FQDNs only (mesh or DNS policy depending on stack).
- Require labels: owner, app, data-class — so SOC knows who to page.
Ravindra Bagale's Tip
💡 Students install kind and expose the dashboard NodePort 0.0.0.0/0 on a public VPS. Then they say "it's a lab". Even a lab should bind localhost / VPN. Remember the Tesla-2018 lesson. In interviews say RBAC + network policy + non-root + audit. Stay alert!
Ravindra Bagale's Tip – मराठी
💡 Students kind install करून dashboard NodePort 0.0.0.0/0 public VPS वर ठेवतात. मग "lab आहे" म्हणतात. Lab असेल तरी bind localhost / VPN. Tesla-2018 lesson लक्षात ठेवा. Interview मध्ये RBAC + network policy + non-root + audit सांगा. ध्यान ठेवा!
Ravindra Bagale's Tip – हिंदी
💡 Students kind install करके dashboard NodePort 0.0.0.0/0 public VPS पर रखते हैं. फिर कहते हैं "lab है". Lab हो तब भी bind localhost / VPN. Tesla-2018 lesson याद रखो. Interview में RBAC + network policy + non-root + audit बताओ. ध्यान रखो!
Managed Kubernetes vs DIY — shared habits
- Cloud-managed control planes still need your RBAC, network policies and workload hardening.
- Node OS patching may be shared with the provider — read their shared-responsibility doc for your service.
- Store kubeconfigs in a password manager or SSO flow; never commit them to git.
- Treat every
LoadBalancer/ public Ingress as an internet service with authn/authz and rate limits. - Keep a paper (or wiki) map: namespace → owner → data class → on-call.
Care-take — cluster habits that age well
- GitOps with reviews for prod manifests — no cowboy
kubectlon Friday night without tickets. - Separate prod cluster accounts / projects from personal experiments.
- Rotate service account tokens and cloud node roles on a schedule.
- Backup etcd / control plane recovery tested like any DR plan.
- Patch nodes and middlewares; old kube versions are CVE magnets.
- When someone leaves: revoke IdP group that gates cluster access first.
How do I fix common Kubernetes security mistakes?
Ghabru naka 😅 — these are the usual ones:
| Symptom | Likely cause | Fix |
|---|---|---|
| Crypto miners in namespace | Open admin surface / weak RBAC | Private API; authn; audit Deployments |
| Secret in git history | Env baked in manifests | Rotate; use secret store; scan git |
| Pod can reach all DBs | No network policy | Default deny; allow-list flows |
| “AccessDenied” chaos | Over-tight without break-glass | Monitored emergency RoleBinding |
| Node disk full | No resource limits / log spam | Limits + retention + alerts |
| CI can destroy cluster | Bot has cluster-admin | Namespace-scoped apply only |
Try it at home
On kind or minikube on your laptop (or a cloud sandbox billed to you):
- Create a namespace
learnfast-laband a Role that can get/list pods only; prove delete fails. - List Services; ensure nothing sensitive is published on a public IP for “convenience”.
- Write three SIEM alert ideas (new ClusterRoleBinding, secret list burst, Deployment in kube-system by odd user).
- One-sentence Tesla-2018 lesson in your notes.
- Tear down the lab when done; do not leave dashboards on cheap VPS hosts.
Learn it properly
Course lessons:
- The shared responsibility model
- IAM done right
- Network security in AWS
- Protecting data — S3, encryption and secrets
- Detection — CloudTrail, GuardDuty, Config
Related guides: Cloud IAM least privilege · SBOM / supply chain · Zero Trust simply · DevSecOps pipeline · Linux harden checklist
Got it? K8s security = API locked + RBAC least privilege + network/secrets/non-root + audit. Do not forget the Tesla dashboard lesson. Practise in your own lab. Next: learn DevSecOps pipeline.
समजलं का? K8s security = API locked + RBAC least privilege + network/secrets/non-root + audit. Tesla dashboard lesson विसरू नका. Own lab मध्ये practise. आता DevSecOps pipeline शिका.
समझ में आया? K8s security = API locked + RBAC least privilege + network/secrets/non-root + audit. Tesla dashboard lesson मत भूलो. Own lab में practise. आगे DevSecOps pipeline सीखो.
Frequently asked questions
Why is an open Kubernetes dashboard dangerous?
It is an admin console — public reporting on Tesla 2018 showed cryptojacking after dashboard exposure.
What is RBAC in Kubernetes?
Role-based access control deciding which identities may run which verbs on which resources.
Should pods run as root?
Prefer non-root with dropped capabilities unless a rare exception is documented.
Where do secrets belong?
In a secret store / KMS-backed mechanism — not in git, images or casual ConfigMaps.
Is this guide for attacking clusters?
No. It is defensive hardening on clusters you own or are authorised to administer.
Where are related lessons?
Cloud IAM, network security, secrets and detection chapters on this site.