6.01 Kubernetes Security Primitives
Kubernetes security is layered.
To secure a production cluster, you must protect:
- The Hosts
- The API Server
- Authentication (Who?)
- Authorization (What?)
- Component Communication (TLS)
- Pod-to-Pod Communication (Network Policies)
1οΈβ£ Secure the Hosts (Foundation Layer)
If the host is compromised, the entire cluster is compromised.
Production Host Hardening
- Disable root login
- Disable password-based SSH
- Enable SSH key-based authentication only
- Restrict sudo access
- Apply OS security patches regularly
- Enable firewall rules
- Restrict control plane node access
Danger
Never expose control plane nodes directly to the public internet.
Success
Use private networking and a bastion host for production clusters.
2οΈβ£ Secure the Kubernetes API Server
The kube-apiserver is the control center of Kubernetes.
All operations go through it:
- kubectl
- Controllers
- kubelets
- Direct API access
If the API server is compromised, the cluster is compromised.
Security decisions are based on two questions:
- Who can access? β Authentication
- What can they do? β Authorization
3οΈβ£ Authentication (Who Can Access?)
Authentication verifies identity.
Supported Authentication Methods
- X.509 Client Certificates (Recommended)
- Service Accounts
- OIDC / LDAP (External Identity Providers)
- Static Token File (Not recommended for production)
Abstract
Authentication answers: "Who are you?"
Production Best Practices
Success
- Use certificates or OIDC for users
- Disable anonymous access
- Avoid static tokens
- Rotate credentials regularly
- Use short-lived service account tokens
Warning
Never share kubeconfig files insecurely.
4οΈβ£ Authorization (What Can They Do?)
Authorization defines permissions after authentication.
Authorization Modes
- RBAC (Recommended)
- ABAC (Legacy)
- Node Authorizer
- Webhook Authorizer
Abstract
Authorization answers: "What are you allowed to do?"
RBAC (Production Standard)
RBAC uses:
- Roles
- ClusterRoles
- RoleBindings
- ClusterRoleBindings
Apply Least Privilege Principle.
Success
Grant only the minimum permissions required.
Production Best Practices
Tip
- Avoid using cluster-admin role
- Create separate service accounts per application
- Regularly audit RBAC permissions
- Restrict namespace access
Danger
Assigning cluster-admin to applications is a major security risk.
5οΈβ£ TLS Encryption (Component-to-Component Security)
All internal communication in Kubernetes is secured using TLS:
- kube-apiserver β etcd
- kube-apiserver β kubelet
- kube-controller-manager β API server
- kube-scheduler β API server
- kube-proxy β API server
Note
TLS ensures encryption and identity verification between components.
Production Best Practices
Success
- Protect CA private keys
- Rotate certificates periodically
- Secure etcd with TLS
- Never expose etcd without encryption
6οΈβ£ Network Policies (Pod-to-Pod Security)
By default:
All pods can communicate with all other pods.
This is unsafe in production.
Network Policies allow:
- Ingress control (who can reach a pod)
- Egress control (where a pod can send traffic)
- Namespace isolation
- Zero-trust networking
Production Best Practices
Success
- Start with default deny policy
- Explicitly allow required traffic
- Separate workloads by namespace
- Use a CNI that supports Network Policies
Danger
Without network policies, lateral movement inside the cluster is easy.
7οΈβ£ Service Account Security
Service accounts allow pods to talk to the API server.
Secure Usage
- Disable automountServiceAccountToken when not required
- Use dedicated service accounts per workload
- Apply minimal RBAC permissions
- Use bound service account tokens
Warning
Default service account tokens should not be used blindly.
8οΈβ£ Kubernetes Security Layers Overview
| Layer | Purpose |
|---|---|
| Host OS | Node protection |
| API Server | Cluster control protection |
| Authentication | Identity verification |
| Authorization | Permission control |
| TLS | Encrypted communication |
| Network Policies | Pod isolation |
| Service Accounts | Workload identity |
9οΈβ£ Production DO & DON'T
β DO
Tip
- Harden nodes
- Enable RBAC
- Enforce TLS everywhere
- Use network policies
- Rotate credentials
- Enable audit logging
- Encrypt secrets at rest
β DON'T
Danger
- Donβt use cluster-admin unnecessarily
- Donβt allow password-based SSH
- Donβt expose API server publicly without protection
- Donβt skip certificate management
- Donβt run containers as root when avoidable
π Production Security Checklist
Abstract
- Harden hosts
- Secure API server
- Enable RBAC
- Enforce TLS
- Configure Network Policies
- Secure Service Accounts
- Enable audit logging
- Encrypt secrets at rest
π― Interview Memory
Question
- Authentication = Who?
- Authorization = What?
- RBAC is recommended
- TLS secures components
- Network Policies isolate pods
- Host security is foundational
Quote
Kubernetes security is layered. Secure every layer β host, API, identity, network, and data.