Course contentsShow
← Cloud and Infrastructure
Lesson 1409 of 2,98928. Kubernetes SecurityFree lesson

Validating Admission Webhooks

Implementing validating webhooks to accept or reject API requests based on custom validation logic and policies.

Validating Admission Webhooks

What you'll learn: How to use validating webhooks to enforce custom validation rules on API requests before they're persisted to etcd.

What Are Validating Admission Webhooks?

After a request passes through all built-in admission controllers, Kubernetes can send it to external services (webhooks) for additional validation. Validating admission webhooks act as custom gatekeepers that examine API requests and either approve or reject them based on your organization's specific policies.

Think of it like airport security with multiple checkpoints: built-in admission controllers are the standard TSA rules everyone follows, but validating webhooks are like additional custom security protocols your organization adds for extra scrutiny.

How They Work

When you create or update a Kubernetes object (like a Pod or Deployment), the API server:

  1. Runs built-in admission controllers first
  2. Sends the request payload to your configured webhook endpoint (an HTTPS service you host)
  3. Waits for a response: allowed: true or allowed: false
  4. If rejected, returns an error to the user; if approved, continues processing

Your webhook service receives the full object specification and can validate anything: naming conventions, label requirements, image registry restrictions, resource limit policies, compliance rules—anything your logic can check.

Common Use Cases

  • Image registry validation: Reject pods using images from untrusted registries
  • Naming conventions: Enforce namespace or resource naming standards
  • Policy compliance: Ensure all deployments have specific labels or annotations
  • Security rules: Block privileged containers or host path mounts beyond what built-in controllers check
  • Custom business logic: Enforce organization-specific requirements that don't fit standard Kubernetes patterns

Unlike mutating webhooks (which can modify requests), validating webhooks can only say yes or no—they cannot change the object.

Key Takeaway: Validating admission webhooks let you enforce custom validation logic by calling external HTTPS services that approve or reject API requests before they reach etcd, extending Kubernetes security beyond built-in rules.