DevSecOps & secrets management · Lesson 4 of 7 · 3 min read
Kubernetes workload and cluster security
Pod security
apiVersion: apps/v1
kind: Deployment
metadata: { name: orders, namespace: orders }
spec:
template:
spec:
serviceAccountName: orders
automountServiceAccountToken: false # unless the app calls the K8s API
securityContext:
runAsNonRoot: true
runAsUser: 10001
fsGroup: 10001
seccompProfile: { type: RuntimeDefault }
containers:
- name: app
image: 123456789012.dkr.ecr.ap-south-1.amazonaws.com/orders@sha256:abc...
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: { drop: ["ALL"] }
resources:
requests: { cpu: 200m, memory: 512Mi }
limits: { memory: 512Mi }
volumeMounts: [{ name: tmp, mountPath: /tmp }]
volumes: [{ name: tmp, emptyDir: {} }]
Pod Security Admission (built in, replaced PodSecurityPolicy, removed in 1.25) enforces the Pod Security Standards per namespace via labels:
metadata:
labels:
pod-security.kubernetes.io/enforce: restricted
pod-security.kubernetes.io/warn: restricted
pod-security.kubernetes.io/audit: restricted
Levels: privileged (unrestricted), baseline (blocks known privilege escalations: hostNetwork, privileged, hostPath...), restricted (hardened: non-root, drop ALL capabilities, seccomp, no privilege escalation). Use Kyverno/Gatekeeper for anything more specific (allowed registries, required labels, signature verification, no latest tag).
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
Cluster-level controls
- RBAC least privilege: namespaced Roles for teams; avoid
cluster-adminbindings; no wildcard verbs/resources; restrictsecretsread,pods/exec,create pods(which implies the power of any SA in that namespace),escalate/bind/impersonateverbs. Audit withkubectl auth can-i --list --as=..., rbac-tool, Kubescape. - EKS access: access entries/IAM Identity Center mappings for humans, private API endpoint or restricted public CIDRs, envelope encryption of Secrets with KMS, control plane audit logs to CloudWatch.
- Network policies: default-deny ingress (and egress where practical) per namespace, then allow specific flows; on EKS enable network policy in the VPC CNI or use Calico/Cilium. Block pod access to the instance metadata endpoint.
- Node security: EKS-optimised or Bottlerocket AMIs (minimal, immutable, SELinux), patched regularly via managed node group updates or Karpenter drift; IMDSv2 with hop limit 1; no SSH, SSM if needed.
- Admission policies: allowed registries (only your ECR), signed images, no privileged, required resources, no hostPath.
- Runtime detection: Falco rules (shell spawned in container, writes to /etc, unexpected outbound connections) or GuardDuty Runtime Monitoring; feed alerts to the SOC.
- Benchmarks: CIS Kubernetes/EKS benchmark with kube-bench; Kubescape against NSA/CISA hardening guidance.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.