Security
Security in Kubernetes is about protecting your cluster, workloads, and data from threats. Kubernetes provides many security features, but security requires a defense-in-depth approach—multiple layers of protection working together. Think of it like a castle: you need strong walls (network policies), guards at the gates (authentication), careful access control (authorization), and monitoring for threats (audit logs).
The Security Model
Kubernetes security follows a defense-in-depth strategy with multiple layers:
Each layer provides protection, and together they create a comprehensive security posture.
Security Layers
Authentication (Who Are You?)
Authentication verifies the identity of users and applications:
- Certificates - X.509 certificates for user authentication
- Service Accounts - Identities for applications running in pods
- OIDC - OpenID Connect for integration with identity providers
- Tokens - Bearer tokens for API access
Authorization (What Can You Do?)
Authorization determines what authenticated entities can do:
- RBAC - Role-Based Access Control defines permissions
- Roles - Namespace-scoped permissions
- ClusterRoles - Cluster-wide permissions
- RoleBindings - Grant roles to users or groups
Network Security (Who Can Talk to Whom?)
Network security controls pod-to-pod communication:
- Network Policies - Firewall rules for pods
- TLS - Encrypt traffic between services
- Service Mesh - Advanced network security with mTLS
Pod Security (What Can Pods Do?)
Pod security restricts what containers can do:
- Security Context - Container-level security settings
- Pod Security Standards - Baseline, restricted, and privileged policies
- Capabilities - Linux capabilities that containers can use
- Seccomp/AppArmor - System call and access restrictions
Secrets Management (Protect Sensitive Data)
Secrets store sensitive information securely:
- Kubernetes Secrets - Built-in secret storage
- Encryption at Rest - Encrypt secrets in etcd
- External Secrets - Integrate with external secret managers
Policy Enforcement (Enforce Policies)
Policy enforcement ensures compliance with security policies:
- Admission Webhooks - Validate and mutate resources before creation
- OPA Gatekeeper - Policy engine for Kubernetes
- Kyverno - Kubernetes-native policy engine
Runtime Security (Detect Threats)
Runtime security monitors for threats and anomalies:
- Falco - Runtime threat detection
- KubeArmor - System call enforcement
- eBPF - Kernel-level monitoring
Supply Chain Security (Secure Images)
Supply chain security ensures container images are safe:
- Image Scanning - Detect vulnerabilities in images
- Image Signing - Verify image authenticity
- SBOM - Track software components
Audit & Compliance (Track Everything)
Audit logging tracks all API access for compliance:
- Audit Logs - Record all API access
- CIS Benchmarks - Security configuration standards
- Policy Logs - Track policy enforcement
Security Lifecycle
Security is an ongoing process:
Plan - Define security requirements and policies
Implement - Deploy security controls (RBAC, Network Policies, Pod Security)
Monitor - Continuously monitor for threats and anomalies
Detect - Identify security incidents
Respond - Take action to contain threats
Remediate - Fix vulnerabilities and improve security
Review - Learn from incidents and improve
Security Best Practices
Principle of Least Privilege - Grant only the minimum permissions needed
Enable RBAC - Use Role-Based Access Control for all access
Use Network Policies - Implement network segmentation with Network Policies
Secure Pods - Run containers as non-root, drop capabilities, use read-only filesystems
Encrypt Secrets - Enable encryption at rest for etcd
Scan Images - Scan container images for vulnerabilities before deployment
Sign Images - Use image signing to verify authenticity
Enable Audit Logging - Track all API access for compliance
Use Admission Controllers - Validate and enforce policies at admission time
Monitor Runtime - Use runtime security tools to detect threats
Keep Updated - Regularly update Kubernetes and components
Harden Nodes - Secure the underlying nodes and operating systems
Common Security Patterns
Multi-Tenant Isolation
Isolate different teams or applications:
- Namespaces for logical separation
- Network Policies for network isolation
- RBAC for access control
Zero-Trust Networking
Default deny, explicit allow:
- Network Policies deny all by default
- Explicit allow rules for needed communication
- Service mesh mTLS for encrypted communication
Least Privilege Service Accounts
Applications run with minimal permissions:
- Dedicated ServiceAccount per application
- Minimal RBAC permissions
- No cluster-admin access
Defense in Depth
Multiple security layers:
- Authentication + Authorization
- Network Policies + Pod Security
- Policy Enforcement + Runtime Security
Topics
Authentication & Authorization
- Authentication & Authorization - How users and applications authenticate
- Service Accounts - Identities for applications
- OIDC - OpenID Connect integration
- RBAC - Role-Based Access Control
- Roles & Bindings - Defining and granting permissions
- Least Privilege - Implementing least privilege
Secrets Management
- Secrets - Managing sensitive data
- Encryption at Rest - Encrypting secrets in etcd
- External Secrets - Integrating with external secret managers
Network Security
- Network Security - Securing network communication
- Network Policies - Pod-level firewalls
- TLS - Transport Layer Security
Pod Security
- Hardening - Securing pods and containers
- Security Context - Container security settings
- Capabilities - Linux capabilities
- Seccomp & AppArmor - System call restrictions
Policy Enforcement
- Admission Controllers - Validating and mutating resources
- Pod Security Standards - Built-in pod security policies
- Webhooks - Custom admission logic
- Policy Enforcement - Enforcing security policies
- OPA Gatekeeper - Open Policy Agent
- Kyverno - Kubernetes-native policies
- Patterns - Common policy patterns
Runtime Security
- Runtime Security - Detecting threats at runtime
Supply Chain Security
- Supply Chain Security - Securing the software supply chain
- Image Scanning - Vulnerability detection
- Sigstore - Image signing and verification
- Cosign - Container signing
- Fulcio & Rekor - Certificate and transparency
Scanning & Assessment
- Scanning - Security assessment tools
Audit & Compliance
- Audit - Tracking and compliance
- Audit Logging - API access logging
- CIS Benchmarks - Security configuration standards
- Policy Logs - Policy enforcement tracking
See Also
- Network Policies - Network-level security controls
- Service Meshes - Advanced network security with mTLS
- Observability - Security monitoring and audit logs
- Cluster Operations - Cluster hardening and security configuration