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:

graph TB A[Defense in Depth] --> B[Authentication] A --> C[Authorization] A --> D[Network Security] A --> E[Pod Security] A --> F[Secrets Management] A --> G[Policy Enforcement] A --> H[Runtime Security] A --> I[Supply Chain Security] A --> J[Audit & Compliance] B --> B1[Who Are You?] C --> C2[What Can You Do?] D --> D1[Who Can Talk to Whom?] E --> E1[What Can Pods Do?] F --> F1[Protect Sensitive Data] G --> G2[Enforce Policies] H --> H1[Detect Threats] I --> I2[Secure Images] J --> J1[Track Everything] style A fill:#e1f5ff style B fill:#fff4e1 style C fill:#e8f5e9 style D fill:#f3e5f5 style E fill:#ffe1e1

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:

graph LR A[User/Application] --> B{Authentication Method} B --> C[Certificates] B --> D[Service Accounts] B --> E[OIDC] B --> F[Tokens] C --> G[Authenticated Identity] D --> G E --> G F --> G style A fill:#e1f5ff style G fill:#e8f5e9
  • 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:

graph TB A[Authenticated Request] --> B[RBAC Evaluates] B --> C{Has Permission?} C -->|Yes| D[Request Allowed] C -->|No| E[Request Denied] B --> F[Check Roles] B --> G[Check RoleBindings] B --> H[Check Resource] B --> I[Check Action] style A fill:#e1f5ff style D fill:#e8f5e9 style E fill:#ffe1e1
  • 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:

graph TB A[Pod A] --> B{Network Policy} B -->|Allowed| C[Pod B] B -->|Denied| D[Traffic Blocked] E[Default Deny] --> F[Explicit Allow Rules] F --> G[Ingress Rules] F --> H[Egress Rules] style A fill:#e1f5ff style C fill:#e8f5e9 style D fill:#ffe1e1 style E fill:#fff4e1
  • 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:

graph TB A[Pod Security] --> B[Security Context] A --> C[Pod Security Standards] A --> D[Capabilities] A --> E[Seccomp/AppArmor] B --> F[Run as Non-Root] B --> G[Read-Only Root FS] B --> H[Drop Capabilities] style A fill:#e1f5ff style B fill:#e8f5e9 style C fill:#fff4e1
  • 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:

graph TB A[Secrets] --> B[Encryption at Rest] A --> C[Encryption in Transit] A --> D[External Secrets] B --> E[etcd Encryption] C --> F[TLS] D --> G[Vault/AWS Secrets Manager] style A fill:#e1f5ff style B fill:#e8f5e9 style C fill:#e8f5e9 style D fill:#fff4e1
  • 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:

graph TB A[Policy Enforcement] --> B[Admission Webhooks] A --> C[OPA Gatekeeper] A --> D[Kyverno] B --> E[Validate Resources] C --> F[Open Policy Agent] D --> G[Kubernetes Native Policies] style A fill:#e1f5ff style B fill:#e8f5e9 style C fill:#fff4e1 style D fill:#f3e5f5
  • 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:

graph TB A[Runtime Security] --> B[Falco] A --> C[KubeArmor] A --> D[eBPF Monitoring] B --> E[Threat Detection] C --> F[System Call Monitoring] D --> G[Kernel-Level Visibility] style A fill:#e1f5ff style B fill:#e8f5e9 style C fill:#fff4e1 style D fill:#f3e5f5
  • 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:

graph TB A[Supply Chain Security] --> B[Image Scanning] A --> C[Image Signing] A --> D[SBOM] B --> E[Vulnerability Detection] C --> F[Sigstore/Cosign] D --> G[Software Bill of Materials] style A fill:#e1f5ff style B fill:#e8f5e9 style C fill:#fff4e1 style D fill:#f3e5f5
  • 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:

graph TB A[API Request] --> B[Audit Log] B --> C[Who] B --> D[What] B --> E[When] B --> F[Result] C --> G[User/Service Account] D --> H[Resource & Action] E --> I[Timestamp] F --> J[Allowed/Denied] style A fill:#e1f5ff style B fill:#e8f5e9
  • Audit Logs - Record all API access
  • CIS Benchmarks - Security configuration standards
  • Policy Logs - Track policy enforcement

Security Lifecycle

Security is an ongoing process:

graph TD A[Plan Security] --> B[Implement Controls] B --> C[Monitor & Detect] C --> D{Threat Detected?} D -->|No| C D -->|Yes| E[Respond] E --> F[Remediate] F --> G[Review & Improve] G --> B style A fill:#e1f5ff style B fill:#e8f5e9 style C fill:#fff4e1 style E fill:#ffe1e1 style F fill:#e8f5e9

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

  1. Principle of Least Privilege - Grant only the minimum permissions needed

  2. Enable RBAC - Use Role-Based Access Control for all access

  3. Use Network Policies - Implement network segmentation with Network Policies

  4. Secure Pods - Run containers as non-root, drop capabilities, use read-only filesystems

  5. Encrypt Secrets - Enable encryption at rest for etcd

  6. Scan Images - Scan container images for vulnerabilities before deployment

  7. Sign Images - Use image signing to verify authenticity

  8. Enable Audit Logging - Track all API access for compliance

  9. Use Admission Controllers - Validate and enforce policies at admission time

  10. Monitor Runtime - Use runtime security tools to detect threats

  11. Keep Updated - Regularly update Kubernetes and components

  12. 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

Secrets Management

Network Security

Pod Security

Policy Enforcement

Runtime Security

Supply Chain Security

Scanning & Assessment

Audit & Compliance

See Also