SecurityKubernetes
Kyverno policies: block what should never deploy
Kyverno runs as an admission controller and applies the policies that match each request it receives from the API server. Since release 1.20 its policies are CEL-based kinds, and the older ClusterPolicy no longer executes.

What Kyverno is
Kyverno runs as a dynamic admission controller in a Kubernetes cluster. It receives validating and mutating admission webhook callbacks from the API server and applies the matching policies. The result enforces a policy or rejects the request.
Policies are written in the Common Expression Language (CEL). They validate, mutate, generate and delete resources, and they verify container images. Kyverno also performs runtime scans on matching resources, and its CLI applies policies to resource files.
The quick start installs the current release with Helm:
helm repo add kyverno https://kyverno.github.io/kyverno/
helm repo update
helm install kyverno kyverno/kyverno -n kyverno --create-namespaceThat page marks its guides as proof-of-concept or lab demonstrations. For production it sends you to the installation page.
Five policy types
All five use apiVersion: policies.kyverno.io/v1.
ValidatingPolicyvalidates Kubernetes resources or JSON payloads.MutatingPolicymutates new or existing resources.GeneratingPolicycreates or clones resources based on triggers.DeletingPolicydeletes matching resources based on a schedule.ImageValidatingPolicyverifies container image signatures and attestations.
Each type also has a namespaced variant, such as NamespacedValidatingPolicy. A namespaced policy applies only to resources in the namespace where it is created.
ClusterPolicy and older tutorials
Kyverno 1.20 is the release where the CEL-based types replace the legacy ones. Per its announcement, no Kyverno controller and no CLI command executes these any longer: ClusterPolicy, Policy, CleanupPolicy, ClusterCleanupPolicy and the legacy kyverno.io PolicyException.
The same announcement lists what changes on upgrade:
- Creates and spec updates of legacy policies are blocked.
- Existing objects are preserved. They show as not ready.
- The Helm chart ships a gate, on by default, that halts an install or an upgrade as long as legacy policy resources are present.
- The legacy CRDs are planned for full removal in v1.21.
A tutorial that shows kind: ClusterPolicy describes the legacy engine. The announcement links to the migration guide.
One policy example
This is the validation policy from the Kyverno quick start. It requires all pods in the namespace quick-start-validation to have the team label:
apiVersion: policies.kyverno.io/v1
kind: ValidatingPolicy
metadata:
name: require-labels
spec:
validationActions:
- Deny
autogen:
podControllers:
controllers:
- deployments
matchConstraints:
namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: quick-start-validation
resourceRules:
- apiGroups: ['']
apiVersions: ['v1']
operations: ['CREATE', 'UPDATE']
resources: ['pods']
validations:
- message: "label 'team' is required"
expression: >-
has(object.metadata.labels) && has(object.metadata.labels.team)
&& object.metadata.labels.team != ''Setting validationActions to Deny blocks every non-compliant pod. The policy matches pods. With the autogen block, Kyverno also applies it to pod controllers such as Deployments. The quick start creates a Deployment without the label, and the admission request is denied with the message label 'team' is required.
Kyverno describes ValidatingPolicy as a superset of the Kubernetes ValidatingAdmissionPolicy. Its comparison table lists bindings as manual for ValidatingAdmissionPolicy and automatic for ValidatingPolicy. Kyverno can also generate a ValidatingAdmissionPolicy from a ValidatingPolicy for the API server to execute. That option and pod controller auto-generation are mutually exclusive.
Audit and Deny
The reports page describes the two actions:
- With
validationActions: [Audit], a non-compliant resource is created and the failure is recorded in a report. - With
validationActions: [Deny], non-compliant admission requests are blocked.
Read the audit results first: they show what a policy would affect before you set it to Deny. That instruction is Kyverno's own.
The reports controller also evaluates resources that already exist, among them resources older than the policy. A background scan never blocks or deletes an existing resource, and that holds for a policy set to Deny too.
Policy reports and exceptions
Policy reports are custom resources that Kyverno generates and manages. A PolicyReport is about a namespaced resource, and Kyverno creates it in the namespace of that resource. A ClusterPolicyReport describes a cluster-scoped resource. Both use the wgpolicyk8s.io/v1alpha2 API.
kubectl get policyreport -A
kubectl get clusterpolicyreport
kubectl describe policyreport <report-name> -n defaultA result is pass, skip, fail, warn or error. Reports represent the current state of resources in the cluster. They are not a historical audit log, and a report is removed when its resource is deleted. Reports describe resources that exist, so Kyverno points to metrics and Kubernetes Events for investigating blocked requests.
A PolicyException allows selected resources past a policy. It names the policy under policyRefs and matches resources with CEL matchConditions. PolicyExceptions are disabled by default. They are off until you set the enablePolicyException flag to true. The exceptionNamespace flag names the namespaces where they may be used.
First steps
- Install Kyverno in a lab cluster with the quick start commands and apply the example policy.
- Write new policies with
validationActions: [Audit]and read the reports. - Switch a policy to
Denyafter you have assessed its audit results. - Apply the policies to resource files with the CLI. This is the documented form of the command:
kyverno apply /path/to/policy.yaml /path/to/folderOfPolicies --resource=/path/to/resources/Sources
Want a second pair of eyes on yours? We do this work for a living.
More guides

ValidatingAdmissionPolicy: admission rules without a webhook
Security · 4 min read
A policy, a binding and a CEL expression, evaluated by the API server.

securityContext: the settings every pod should carry
Security · 4 min read
Six settings, where each one goes, and a Deployment you can copy.

S3 bucket security: the settings to check on every bucket
Security · 4 min read
Seven S3 settings to check on each bucket, with the commands that read and set them.