For Site Reliability Engineers, securing Kubernetes clusters is paramount to maintaining reliability and integrity. RBAC (Role-Based Access Control) is your primary mechanism for managing who can do what within the cluster. This applies equally to human users interacting via kubectl and, critically, to service accounts used by applications, CI/CD pipelines, and Kubernetes operators. As SREs, you'll define Roles (namespace-scoped) or ClusterRoles (cluster-scoped) specifying permissible actions (e.g., get, list, create deployments, read secrets) and then bind these via RoleBindings or ClusterRoleBindings to specific users, groups, or service accounts. The principle of least privilege is non-negotiable here; granting only the permissions necessary for a given entity prevents unauthorized access and limits the blast radius of compromised credentials.
Building upon access control, Pod Security Standards (PSS) define predefined security profiles that pods must adhere to. Replacing the more complex Pod Security Policies (PSPs), PSS provides three levels: Privileged (unrestricted), Baseline (minimally restrictive), and Restricted (highly restrictive). SREs enforce these standards using the PodSecurity admission controller, typically by applying specific labels to namespaces (e.g., pod-security.kubernetes.io/enforce: restricted). This ensures that even if an authorized user attempts to deploy an insecure pod (e.g., one requesting hostPath volumes, running as root, or with privileged escalation), the admission controller will block it, thus maintaining a baseline security posture across your fleet and significantly reducing the cluster's attack surface.
Finally, image scanning addresses vulnerabilities at the source: your container images. While RBAC governs cluster interactions and PSS dictates pod runtime security, image scanning is crucial for detecting known CVEs, misconfigurations, and sensitive data within the image layers themselves. SREs integrate tools like Trivy, Clair, or commercial solutions into CI/CD pipelines to scan images before they're pushed to registries or, ideally, before deployment to production. Establishing a clear policy—e.g., blocking deployments with critical vulnerabilities or failing builds if images don't meet an acceptable security threshold—is vital. Together, RBAC, PSS, and image scanning form a robust, multi-layered defense strategy, ensuring that only trusted entities can deploy secure code in a controlled manner, which is fundamental to SRE principles of system health and resilience.
Key Takeaways
- RBAC enforces granular 'who can do what' for both human users and critical service accounts, central to the principle of least privilege.
- Pod Security Standards (PSS) define and enforce security profiles for pods via admission controllers, reducing attack surface at runtime.
- Integrate image scanning into CI/CD pipelines to prevent known vulnerabilities from reaching production environments.
- These three elements combine to form a critical, multi-layered security defense, essential for SREs to maintain cluster reliability and integrity.
Code Example
kubectl label namespace my-secure-app pod-security.kubernetes.io/enforce=restricted \
pod-security.kubernetes.io/warn=restricted \
pod-security.kubernetes.io/audit=restricted --overwriteHow this code works
This code configures Pod Security Standards (PSS) for the my-secure-app namespace, enforcing a specific security profile for all pods running within it. Its main job is to apply labels that instruct Kubernetes to restrict pods to the restricted PSS profile, which significantly limits a pod's capabilities and access to host resources. This is a fundamental step in securing an application by preventing common security vulnerabilities at the pod level within that namespace.
The command uses kubectl label namespace my-secure-app to target the specified namespace for label modification. It then applies three labels: pod-security.kubernetes.io/enforce=restricted, pod-security.kubernetes.io/warn=restricted, and pod-security.kubernetes.io/audit=restricted. These labels work together to define how Kubernetes handles violations of the restricted profile: enforce actively blocks non-compliant pods, warn issues a warning but allows the pod, and audit logs violations. The --overwrite flag is crucial here; without it, if any of these specific pod-security.kubernetes.io labels already exist on the namespace, the command would fail, preventing the update. overwrite ensures the labels are always successfully applied or updated to the desired restricted policy.