Skip to content

PolicyExceptions: KCA practice questions

A PolicyException lets chosen resources bypass chosen rules without editing the policy itself. In the legacy kyverno.io API, version v2, the spec has an exceptions list, where each entry names a policyName and the ruleNames it covers, and a match block, in the familiar match and exclude format, describing which resources are exempt.

By Ibrahim Yesilay · Published · Updated

Independent community practice, not affiliated with or endorsed by CNCF or The Linux Foundation.

What PolicyExceptions covers in KCA

A PolicyException lets chosen resources bypass chosen rules without editing the policy itself. In the legacy kyverno.io API, version v2, the spec has an exceptions list, where each entry names a policyName and the ruleNames it covers, and a match block, in the familiar match and exclude format, describing which resources are exempt. An optional conditions block refines the selection with expressions in the style of preconditions, so an exemption can depend on the content of a resource rather than only its kind, namespace and name.

Exceptions are disabled by default. They are enabled with the enablePolicyException container flag, default false, on the admission, background and reports controllers, and the exceptionNamespace flag names the namespace where PolicyExceptions are permitted; it is required once the feature is enabled. A PolicyException is a namespaced object, but its own namespace has no relationship to the namespaces of the resources it exempts, and it can exempt cluster-scoped resources too. When a ClusterPolicy and a namespaced Policy share a name, policyName takes the form namespace/name for the namespaced one.

Names must line up. ruleNames accepts wildcards. Rules created by auto-generation for Pod controllers must be listed along with the original rule, because an exemption for a Deployment does not cover the rules Kyverno generated for it, and since those generated names can include hashes, a wildcard is often needed. Exceptions also may not match on the same fields that validate rules forbid. In reports, a resource covered by an exception shows skip instead of fail, and background scanning respects exceptions as well.

The legacy resource includes a podSecurity block for exempting specific Pod Security Standards controls, optionally only for certain images or field values. The whole kyverno.io PolicyException is deprecated as of Kyverno 1.19 and scheduled for removal in 1.20 together with ClusterPolicy. Its replacement lives in policies.kyverno.io and works with the CEL-based policy types: it references policies through policyRefs with a name and kind, selects requests with CEL matchConditions, can list images and allowedValues that the policy reads as exceptions.allowedImages and exceptions.allowedValues, and can set reportResult to pass instead of the default skip. It applies in both admission and background modes.

Exceptions are not the only way to carve out scope, and they are not always the right one. When a policy should never apply to some resources, such as a system namespace, an exclude block in the policy expresses that directly and is visible to anyone reading it. Kyverno's own configuration already keeps the kube-system and kyverno namespaces out of its webhooks by default. Exceptions are for the cases where the policy is right in general and a specific, named workload needs to differ, and policies can also be written with exceptions inside their rules.

Key points

  • PolicyExceptions are off by default; enablePolicyException and exceptionNamespace turn them on.
  • The exception's own namespace is unrelated to the namespaces of the resources it exempts.
  • Auto-generated Pod controller rules must be named too, often with a ruleNames wildcard.
  • An exempted resource is reported as skip rather than fail.

Three sample questions

10 KCA questions on PolicyExceptions, 10 with explanations. How practice works

Question 1

You create a PolicyException on a freshly installed Kyverno v1.13.2 cluster. kubectl get policyexception shows it, but the policy keeps blocking the workload. What is the most likely cause?
  1. A.PolicyException only works against namespaced Policy objects, never ClusterPolicy.
  2. B.The exception must be created in the kyverno namespace.
  3. C.PolicyExceptions are disabled by default; --enablePolicyException=true must be set on the controllers, along with a matching --exceptionNamespace.
  4. D.The exception needs several minutes to propagate to the webhook.

Correct answer: C

The CRD is installed by default but the feature is off. Without --enablePolicyException=true, the object is stored happily by the API server and has no effect whatsoever — no error, no event, no warning. --exceptionNamespace then restricts which namespace's exceptions are honoured.

Question 2

You enable exceptions on kyverno-admission-controller only. Your exempted Deployment now deploys successfully, but your compliance dashboard still shows it failing. Why?
  1. A.Reports always record the pre-exception result for audit purposes.
  2. B.The reports controller also needs --enablePolicyException=true; without it, background scans do not honour the exception and keep recording fail instead of skip.
  3. C.Exceptions never affect reports, by design.
  4. D.The dashboard is caching stale data.

Correct answer: B

Three controllers carry the flag and each applies it to its own work: the admission controller decides whether the resource is admitted, the reports controller decides whether a background scan records skip, and the background controller applies it to generate/mutateExisting processing. Setting it on only one produces exactly this enforcement-versus-record mismatch.

Question 3

A ClusterPolicy has exactly one rule, named check-limits, matching kinds: [Pod]. A Deployment is being blocked by it. Your exception lists ruleNames: [check-limits] and matches kinds: [Pod]. Why does the Deployment stay blocked?
  1. A.Autogen generates a parallel autogen-check-limits rule for Pod-owning controllers, and it is that rule blocking the Deployment request — the exception must name it and match kind: Deployment.
  2. B.The Deployment must be annotated to accept exceptions.
  3. C.ruleNames requires a wildcard to work.
  4. D.Exceptions cannot exempt Deployments at all.

Correct answer: A

Kyverno's autogen mechanism silently adds autogen--prefixed copies of a Pod-scoped rule for Deployment, StatefulSet, DaemonSet, Job, CronJob and ReplicaSet. The admission request being rejected is the Deployment request, evaluated by autogen-check-limits. An exception must therefore list both rule names and match the Deployment kind as well as Pod.

Practice this topic

Focus mode keeps every question on PolicyExceptions until you leave it. 10 free guest answers, then a free account; no credit card.

Or open KCA practice across all topics.

Sources

The explanation above was checked against these official documents.

Frequently asked questions

Why does my PolicyException not stop a Deployment from being blocked?

Check that the feature is enabled, that the exception lives in the namespace set by exceptionNamespace, and that ruleNames includes the auto-generated rule for Deployments as well as the original Pod rule. A wildcard in ruleNames is often used for those generated names.