Kubernetes Hardening L5: Admission Control in 2026 with CEL Policies and Kyverno
DEV Community

Kubernetes Hardening L5: Admission Control in 2026 with CEL Policies and Kyverno

Kubernetes Hardening L5: Admission Control in 2026 with CEL Policies and Kyverno TL;DR: Stop writing external HTTP webhooks for basic pod validation and mutation. In 2026, Kubernetes admission control belongs inside kube-apiserver first: use Pod Security Admission (PSA) (enforce=restricted) as your zero-config floor, enforce synchronous guardrails and defaults in-process using ValidatingAdmissionPolicy (GA in 1.30) and MutatingAdmissionPolicy (GA in 1.36) written in Common Expression Language (CEL), and reserve Kyverno 1.16+ (CNCF Graduated) for capabilities that genuinely require external calls or background controllers - specifically ImageValidatingPolicy (cosign/SLSA verification) and GeneratingPolicy (stamping out default-deny NetworkPolicies per namespace). For every webhook that remains, lock its ingress port exclusively to kube-apiserver via NetworkPolicy so you never repeat the IngressNightmare (CVE-2025-1974) RCE vector.

Why External Webhooks Are No Longer the Default

Between 2019 and 2023, hardening a Kubernetes cluster meant installing two or three admission webhook controllers and routing every Pod, Deployment, Service, and Ingress creation over the cluster network as a serialized AdmissionReview JSON payload.

In production, webhook-heavy architectures failed in three predictable ways:

  • Cold-boot cluster deadlocks. If a webhook configured with failurePolicy: Fail matched kube-system pods or Node leases and the cluster lost power, kube-apiserver blocked CNI DaemonSet and CoreDNS scheduling because the webhook pods were not running yet - and the webhook pods could not start because the CNI was blocked.
  • Control-plane tail latency. Each external webhook hop adds roughly 5 to 50ms+ of network, TLS, and JSON serialization overhead to matching API requests; chaining multiple mutating and validating webhooks compounds tail latency and throttles deployment controllers during large node drains.
  • Webhooks are network attack surface. An admission webhook is an HTTPS server running inside your cluster, often holding broad RBAC permissions. In March 2025, IngressNightmare (CVE-2025-1974) demonstrated that an unauthenticated admission webhook endpoint exposed on the pod network (ingress-nginx) allowed any compromised container in the cluster to send a crafted AdmissionReview request, achieve remote code execution inside the controller pod, and dump cluster-wide Secrets.

The 2026 Layered Admission Architecture

Modern Kubernetes moves the majority of synchronous admission logic directly into the kube-apiserver binary using compiled Common Expression Language (CEL) abstract syntax trees (ASTs). External webhooks are now used surgically for supply-chain cryptography and cross-resource automation.

  • Layer 1: Pod Security Floor - Pod Security Admission (PSA) (Built-in) - In-process (kube-apiserver) - Enforces the upstream baseline and restricted Pod Security Standards (blocks privileged containers, root UIDs, host namespaces, and unsafe capabilities).
  • Layer 2: Synchronous Guardrails & Defaults - MutatingAdmissionPolicy (GA 1.36) & ValidatingAdmissionPolicy (GA 1.30) - In-process CEL (kube-apiserver) - Sub-millisecond mutation (defaulting automountServiceAccountToken: false on ServiceAccount creation, and seccompProfile: RuntimeDefault / hostUsers: false on non-host-namespace Pods) and validation (blocking :latest, unapproved registries, hostPath, auto-mounted kube-api-access-* tokens, or reserved label spoofing).
  • Layer 3: Supply Chain & Lifecycle Automation - Kyverno 1.16+ or OPA Gatekeeper (CNCF Graduated under OPA) - Hardened Webhook + Background Controller - Verifying Sigstore / cosign signatures and in-toto (CNCF Graduated) SLSA provenance (ImageValidatingPolicy), generating per-namespace default-deny NetworkPolicies (GeneratingPolicy), and producing PolicyReport CRDs.

Layer 1: Pod Security Admission (PSA)

Pod Security Admission is compiled directly into kube-apiserver and evaluates pods against the three upstream Pod Security Standards (privileged, baseline, restricted) across three modes (enforce, audit, warn).

Every application namespace should enforce the restricted profile, which requires runAsNonRoot: true, allowPrivilegeEscalation: false, dropping ALL Linux capabilities (allowing only NET_BIND_SERVICE if explicitly needed), a RuntimeDefault or Localhost seccomp profile, and safe volume types:

apiVersion: v1
kind: Namespace
metadata:
  name: payments
  labels:
    pod-security.kubernetes.io/enforce: restricted
    pod-security.kubernetes.io/enforce-version: v1.36
    pod-security.kubernetes.io/audit: restricted
    pod-security.kubernetes.io/audit-version: v1.36
    pod-security.kubernetes.io/warn: restricted
    pod-security.kubernetes.io/warn-version: v1.36

Cluster-Wide PSA Defaults on Bare Metal

Relying solely on namespace labels has a gap: if an engineer or Helm chart creates a new namespace and forgets the pod-security.kubernetes.io/enforce label, PSA defaults to privileged (unrestricted).

On self-hosted bare metal, close this gap at the API server level by passing --admission-control-config-file=/etc/kubernetes/admission-config.yaml to kube-apiserver. This sets restricted as the cluster-wide floor for every namespace except explicitly exempted system namespaces:

# /etc/kubernetes/admission-config.yaml
apiVersion: apiserver.config.k8s.io/v1
kind: AdmissionConfiguration
plugins:
- name: PodSecurity
  configuration:
    apiVersion: pod-security.admission.config.k8s.io/v1
    kind: PodSecurityConfiguration
    # Pin PSA version to the target cluster minor release (v1.36) in production
    # so control-plane upgrades never introduce surprise admission rejections unannounced
    defaults:
      enforce: "restricted"
      enforce-version: "v1.36"
      audit: "restricted"
      audit-version: "v1.36"
      warn: "restricted"
      warn-version: "v1.36"
    exemptions:
      usernames: [ ]
      runtimeClasses: [ ]
      namespaces:
      - kube-system
      - cilium
      - spire-system
      - kyverno
      - cert-manager

On managed clusters (EKS, GKE Standard, AKS) where you cannot edit --admission-control-config-file on the managed API server, use an in-process MutatingAdmissionPolicy matching Namespace creation to inject the pod-security.kubernetes.io/enforce: restricted labels automatically whenever a non-system namespace is created.

Layer 2: In-Process CEL (MutatingAdmissionPolicy and ValidatingAdmissionPolicy)

With ValidatingAdmissionPolicy (GA since Kubernetes 1.30) and MutatingAdmissionPolicy (promoted to GA in Kubernetes 1.36), kube-apiserver compiles CEL expressions and executes them in memory with strict CPU/memory cost budgets.

Auto-Hardening Workloads with MutatingAdmissionPolicy (GA 1.36)

One subtle admission-ordering trap catches teams migrating from webhooks to MutatingAdmissionPolicy: the built-in ServiceAccount admission plugin runs before MutatingAdmissionPolicy on Pod CREATE. If you mutate Pod.spec.automountServiceAccountToken: false inside a Pod-targeted MAP, the ServiceAccount plugin has already mounted the kube-api-access-* projected volume onto the Pod spec, so flipping the boolean afterward does not strip the token!

To disable default token mounts cleanly with in-process CEL, split your mutations across two targeted MutatingAdmissionPolicy resources (and enforce a ValidatingAdmissionPolicy backstop below):

  • Target ServiceAccount CREATE (and optionally Deployment / StatefulSet / Job pod templates) to default automountServiceAccountToken: false before any Pod hits the ServiceAccount plugin.
  • Target Pod CREATE to default seccompProfile: RuntimeDefault and hostUsers: false - always guarding hostUsers: false against hostNetwork, hostPID, and hostIPC (because Kubernetes rejects any pod combining host namespaces with a pod user namespace):
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingAdmissionPolicy
metadata:
  name: default-sa-no-automount
spec:
  matchConstraints:
    resourceRules:
    - apiGroups: [""]
      apiVersions: ["v1"]
      operations: ["CREATE"]
      resources: ["serviceaccounts"]
    matchConditions:
    - name: exclude-system-namespaces
      expression: '!(object.metadata.namespace in ["kube-system", "cilium", "spire-system", "kyverno"])'
  failurePolicy: Fail
  reinvocationPolicy: Never
  mutations:
  # Default ServiceAccount.automountServiceAccountToken to false unless the enclosing Namespace carries a platform-admin opt-in label
  - patchType: ApplyConfiguration
    applyConfiguration:
      expression: >
        !(namespaceObject != null && has(namespaceObject.metadata.labels) && "security.bard.sh/allow-automount-sa-token" in namespaceObject.metadata.labels && namespaceObject.metadata.labels["security.bard.sh/allow-automount-sa-token"] == "true") && !has(object.automountServiceAccountToken) ? Object{ automountServiceAccountToken : false } : Object{}
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingAdmissionPolicyBinding
metadata:
  name: default-sa-no-automount-binding
spec:
  policyName: default-sa-no-automount
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingAdmissionPolicy
metadata:
  name: inject-pod-security-defaults
spec:
  matchConstraints:
    resourceRules:
    - apiGroups: [""]
      apiVersions: ["v1"]
      operations: ["CREATE"]
      resources: ["pods"]
    matchConditions:
    - name: exclude-system-namespaces
      expression: '!(object.metadata.namespace in ["kube-system", "cilium", "spire-system", "kyverno"])'
  failurePolicy: Fail
  reinvocationPolicy: Never
  mutations:
  # 1. Default seccompProfile to RuntimeDefault at the Pod level if unset
  - patchType: ApplyConfiguration
    applyConfiguration:
      expression: >
        !has(object.spec.securityContext) | | !has(object.spec.securityContext.seccompProfile) ? Object{ spec : Object.spec{ securityContext : Object.spec.securityContext{ seccompProfile : Object.spec.securityContext.seccompProfile{ type : "RuntimeDefault" } } } } : Object{}
  # 2. Enable Linux user namespaces (hostUsers: false, GA in 1.36) only when no host namespaces are requested
  - patchType: ApplyConfiguration
    applyConfiguration:
      expression: >
        !has(object.spec.hostUsers) && (!has(object.spec.hostNetwork) || !object.spec.hostNetwork) && (!has(object.spec.hostPID) || !object.spec.hostPID) && (!has(object.spec.hostIPC) || !object.spec.hostIPC) && !(namespaceObject != null && has(namespaceObject.metadata.labels) && "security.bard.sh/allow-host-users" in namespaceObject.metadata.labels && namespaceObject.metadata.labels["security.bard.sh/allow-host-users"] == "true") ? Object{ spec : Object.spec{ hostUsers : false } } : Object{}
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingAdmissionPolicyBinding
metadata:
  name: inject-pod-security-defaults-binding
spec:
  policyName: inject-pod-security-defaults

Enforcing Guardrails with ValidatingAdmissionPolicy (GA 1.30)

Next, pair those mutations with an in-process ValidatingAdmissionPolicy that blocks supply-chain, token-mount, and isolation anti-patterns across every container (containers, initContainers, and ephemeralContainers).

Notice that resourceRules.resources explicitly includes both "pods" and "pods/ephemeralcontainers" so kubectl debug (UPDATE on the ephemeralcontainers subresource) cannot slip an unpinned or untrusted debug image past admission:

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: workload-supply-chain-and-isolation-guardrails
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups: [""]
      apiVersions: ["v1"]
      operations: ["CREATE" , "UPDATE"]
      resources: ["pods" , "pods/ephemeralcontainers"]
    matchConditions:
    - name: skip-system-control-plane
      expression: '!(object.metadata.namespace in ["kube-system", "cilium", "spire-system", "kyverno"])'
  variables:
  - name: allContainers
    expression: 'object.spec.containers + (has(object.spec.initContainers) ? object.spec.initContainers : []) + (has(object.spec.ephemeralContainers) ? object.spec.ephemeralContainers : [])'
  - name: approvedRegistries
    expression: '["ghcr.io/bard-sh/", "registry.bard.sh/"]'
  validations:
  # 1. Block mutable :latest tags and require immutable @sha256: digests
  - expression: 'variables.allContainers.all(c, c.image.contains("@sha256:") && !c.image.endsWith(":latest"))'
    message: 'Every container image must be pinned to an immutable @sha256: digest and must not use :latest.'
    reason: Invalid
  # 2. Allow pulls only from approved internal/corporate registries
  - expression: 'variables.allContainers.all(c, variables.approvedRegistries.exists(r, c.image.startsWith(r)))'
    message: 'Container images must originate from ghcr.io/bard-sh/ or registry.bard.sh/.'
    reason: Forbidden
  # 3. Forbid hostPath volumes completely in tenant namespaces
  - expression: '!has(object.spec.volumes) || object.spec.volumes.all(v, !has(v.hostPath))'
    message: 'hostPath volumes are forbidden. Use CSI ephemeral volumes or PersistentVolumeClaims.'
    reason: Forbidden
  # 4. Prevent tenants from spoofing reserved Cilium or platform security labels
  - expression: '!has(object.metadata.labels) || object.metadata.labels.all(k, !k.startsWith("security.bard.sh/admin-"))'
    message: 'Tenants cannot set reserved security.bard.sh/admin-* labels.'
    reason: Forbidden
  # 5. Block auto-mounted default kube-api-access-* tokens unless opted in on the cluster-scoped Namespace
  - expression: >
      (namespaceObject != null && has(namespaceObject.metadata.labels) && "security.bard.sh/allow-automount-sa-token" in namespaceObject.metadata.labels && namespaceObject.metadata.labels["security.bard.sh/allow-automount-sa-token"] == "true") || !has(object.spec.volumes) | | object.spec.volumes.all(v, !v.name.startsWith("kube-api-access-"))
    message: 'Default kube-api-access-* ServiceAccount token volumes are forbidden unless the Namespace carries platform-admin label security.bard.sh/allow-automount-sa-token="true".'
    reason: Forbidden
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
  name: workload-guardrails-enforce
spec:
  policyNa
Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.