Phase 5: Platform Engineering

RBAC, pod security standards & image scanning

Advanced ~2 min read
Think of it this way A friendly analogy. Read this if the technical version feels dense. Show Hide

Imagine our computer systems are like a super busy, super important kitchen where lots of amazing digital dishes (those are like apps or programs) are being cooked up all the time. Just like in a real kitchen, we need rules to keep things safe and working well.

First, we need to decide who can do what. This is like giving out special "kitchen passes." Some passes might only let you get ingredients out of the fridge, like a "Snack Preparer" pass. Others might let you use the blender or even the hot oven, like a "Master Chef" pass. We call this "Role-Based Access Control" (RBAC). It means we give different roles (like "Master Chef" or "Snack Preparer") certain permissions (like "use oven" or "get milk"), and then we give those roles to specific people or even to robot chefs. The goal is simple: only let someone do exactly what they need to, so nobody accidentally breaks something or makes a huge mess. It’s like saying, "You can mix the batter, but only an adult can put it in the oven."

Next, think about the recipes themselves. Every dish needs to follow some safety guidelines. This is like "Pod Security Standards." It’s a checklist for all our digital recipes to make sure they're not trying to do anything risky. For example, a simple recipe (like making a sandwich) might have basic safety rules: "don't leave food out too long." But a complicated recipe (like baking a big cake for a party) might have super strict rules: "always wash hands, measure precisely, don't use raw ingredients near cooked ones." We set these standards so that even if a "Snack Preparer" is following a recipe, the recipe itself isn't asking them to do something dangerous. We make sure all our digital dishes follow the right level of safety rules to prevent problems.

And before anyone even starts cooking, we need to check all the ingredients! This is "image scanning." Imagine every digital ingredient (which is like a building block for our apps) comes in a package. We carefully scan each package to make sure there are no hidden bad surprises inside, like moldy flour or expired milk. We want to know that everything is fresh, safe, and exactly what it claims to be. A special ingredient-checker system automatically looks for anything suspicious that could make our digital food (our apps) sick or cause problems later.

So, when you're helping to build these big digital kitchens, understanding these ideas helps you make sure everyone knows their job, all the recipes are safe, and every ingredient is perfect. This means the digital dishes you create will be delicious, safe, and work reliably for everyone!

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

bash
kubectl label namespace my-secure-app pod-security.kubernetes.io/enforce=restricted \
  pod-security.kubernetes.io/warn=restricted \
  pod-security.kubernetes.io/audit=restricted --overwrite

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