Skip to content

Kyverno Policy Exceptions

kyvernoPolicyExceptions generates Kyverno PolicyException resources for workloads in the Helm release namespace. The Kyverno policies.kyverno.io/v1 API must be available in the cluster.

Configuration

Configure exceptions under the bb-common subchart key:

bb-common:
  kyvernoPolicyExceptions:
    thanos-compactor:
      namespace: kyverno
      policyRefs:
        disallow-auto-mount-service-account-token:
          kind: ValidatingPolicy
        disallow-host-namespaces:
          kind: MutatingPolicy

Each policy reference produces its own PolicyException, named <release-namespace>-<workload>-<policy>, in the kyverno namespace by default. The release namespace prefix prevents collisions when multiple releases exempt workloads with the same name and policy. Set namespace directly under the workload name to create its exceptions in a different namespace. The match condition continues to target workloads in the Helm release namespace.

Before install, upgrade, and rollback operations, Helm creates a temporary <release-namespace>-<workload>-<policy>-bootstrap exception. The managed exception is then created or updated with the rest of the release. This ensures the exception is present before Helm submits workload resources for admission. The bootstrap exception has a cleanup.kyverno.io/ttl: 5m label, so Kyverno removes it after five minutes while the managed exception remains in place. Kyverno’s cleanup controller must have permission to delete policies.kyverno.io PolicyExceptions in the exception namespace.

All policy references are included unless enabled is set to false. Every reference requires a kind; supported values are ValidatingPolicy and MutatingPolicy. Name-keyed references merge across Helm values layers, and an inherited reference can be disabled without replacing the others:

bb-common:
  kyvernoPolicyExceptions:
    thanos-compactor:
      policyRefs:
        disallow-auto-mount-service-account-token:
          enabled: false
          kind: ValidatingPolicy

No exception is rendered for a workload when all of its references are disabled.

The example renders exceptions named <release-namespace>-thanos-compactor-disallow-auto-mount-service-account-token and <release-namespace>-thanos-compactor-disallow-host-namespaces in the kyverno namespace. Their generated match conditions apply to the exact workload name and names beginning with thanos-compactor- in the release namespace, which covers Pods and other resources derived from the workload without matching unrelated prefixes.

No resources are rendered when the configuration is empty or the Kyverno API is unavailable. Use extraObjects when a PolicyException needs custom fields or matching logic.