In this lesson, you will learn how to use Kubernetes Admission Controllers to automatically block the deployment of insecure or untrusted container images.
Up until now, we have focused on scanning images for vulnerabilities and signing them to prove their origin. However, even with these safeguards in place, a developer could still accidentally deploy an unverified or high-risk image to your cluster. An Admission Controller acts as the final "gatekeeper" that intercepts requests to the Kubernetes API server before an object is persisted. By using a Validating Admission Controller, you can enforce a policy that inspects every Pod creation request to ensure the image meets your security criteria.
How It Works
When you submit a kubectl apply command, the request passes through the admission chain. A security-focused controller checks the image against your requirements:
- Signature Verification: Does the image have a valid cryptographic signature (e.g., from your internal build pipeline)?
- Scan Status: Has the image been cleared by your vulnerability scanner?
If an image fails these checks—for example, if it lacks a required signature or contains "Critical" vulnerabilities—the controller rejects the deployment entirely, returning an error message to the user.
Example Policy Concept
You can define a policy that restricts image sources and requires signatures. In a cluster using a tool like OPA Gatekeeper, your rule might look conceptually like this:
# A conceptual gatekeeper policy
rules:
- apiGroups: [""]
apiVersions: ["v1"]
operations: ["CREATE"]
resources: ["pods"]
verifyImageSignature:
required: true
trustedAuthorities: ["my-company-signing-key"]
By enforcing this at the cluster level, you remove the reliance on human diligence. Even if a user has administrative access to the cluster, they cannot bypass the security requirements you have codified. This creates a "secure-by-default" environment where only images that have passed through your automated CI/CD pipeline—and verified their integrity—are allowed to run.
Key Takeaway: Admission Controllers act as automated security gatekeepers that reject any image deployment failing to meet your pre-defined cryptographic signature or vulnerability scan standards.