kadet-hub logokadet-hub

kyverno

Renders Kyverno ValidatingPolicies, MutatingPolicies, GeneratingPolicies, DeletingPolicies and PolicyExceptions, and the legacy ClusterPolicies, Policies and cleanup policies, from inventory parameters.

kubernetesoperatorssecurity

Latest
1.1.2 ·
License
Apache-2.0
Owners
Moep90
Source
github.com/kadet-hub/generators · 0 repo stars, shared by 35 generators
Thumbs up
👍 0 on GitHub Discussions
Popularity
18 · 540 pulls

Request a feature Report a problem

Badge

Show the latest listed version in your README. shields.io draws the badge from this page's badge.json, which every catalog build updates; once no version is listed, it reads "not listed".

[![kadet-hub](https://img.shields.io/endpoint?url=https://kadet-hub.org/generators/kyverno/badge.json)](https://kadet-hub.org/generators/kyverno/)

Kyverno Generator

Published on kadet-hub (catalog): pin a released version by digest from its catalog page.

Kapitan kadet generator for Kyverno policy resources:

Section Kind apiVersion Output key
cluster_policies ClusterPolicy kyverno.io/v1 <name>-cpol
policies Policy kyverno.io/v1 <namespace>/<name>-pol
policy_exceptions PolicyException kyverno.io/v2 <namespace>/<name>-polex
cluster_cleanup_policies ClusterCleanupPolicy kyverno.io/v2 <name>-ccleanup
cleanup_policies CleanupPolicy kyverno.io/v2 <namespace>/<name>-cleanup
validating_policies ValidatingPolicy policies.kyverno.io/v1beta1 <name>-vpol
namespaced_validating_policies NamespacedValidatingPolicy policies.kyverno.io/v1beta1 <namespace>/<name>-nvpol
mutating_policies MutatingPolicy policies.kyverno.io/v1beta1 <name>-mpol
namespaced_mutating_policies NamespacedMutatingPolicy policies.kyverno.io/v1beta1 <namespace>/<name>-nmpol
generating_policies GeneratingPolicy policies.kyverno.io/v1beta1 <name>-gpol
namespaced_generating_policies NamespacedGeneratingPolicy policies.kyverno.io/v1beta1 <namespace>/<name>-ngpol
deleting_policies DeletingPolicy policies.kyverno.io/v1beta1 <name>-dpol
namespaced_deleting_policies NamespacedDeletingPolicy policies.kyverno.io/v1beta1 <namespace>/<name>-ndpol
cel_policy_exceptions PolicyException policies.kyverno.io/v1beta1 <namespace>/<name>-celpolex

Built for Kyverno 1.19.1.

At 1.19.1 Kyverno marks every version of ClusterPolicy, Policy, PolicyException, ClusterCleanupPolicy and CleanupPolicy deprecated in favour of the CEL-based policies.kyverno.io kinds and plans to remove them in 1.20 (ClusterPolicy, Policy, PolicyException, ClusterCleanupPolicy, CleanupPolicy, migration guide). For these legacy kinds the generator emits the storage versions kyverno.io/v1 and kyverno.io/v2, and the API server prints a deprecation warning when they are applied. The policies.kyverno.io kinds are emitted at v1beta1, their storage version at 1.19.1; v1 is served with the same schema and becomes the storage version in 1.20 (storage version).

Usage

Kapitan Configuration

parameters:
  kapitan:
    dependencies:
      - type: oci
        source: ghcr.io/kadet-hub/kyverno@sha256:<digest>
        output_path: lib/kyverno
    compile:
      - output_path: manifests/kyverno/
        input_type: kadet
        output_type: yml
        input_paths:
          - lib/kyverno

Inventory Contract

All keys live under parameters.generators.kyverno. namespace at that level sets the default namespace of the namespaced kinds, falling back to parameters.namespace, then default.

Every resource entry accepts name (overrides the map key), labels, annotations and spec; namespaced kinds also accept namespace. For the same field, spec loses to the flat keys and shorthands below, and a flat key that overrides a spec value logs a warning.

Flat keys are the snake_case spelling of the CRD spec fields; values pass through unchanged unless a shorthand or the mapping of deprecated keys below applies:

Kind Flat keys
ClusterPolicy, Policy rules, validation_failure_action, validation_failure_action_overrides, background, admission, failure_policy, webhook_timeout_seconds, apply_rules, schema_validation, mutate_existing_on_policy_update, generate_existing_on_policy_update, use_server_side_apply, webhook_configuration
PolicyException match, match_kinds, exceptions, background, conditions, pod_security
ClusterCleanupPolicy, CleanupPolicy match, match_kinds, exclude, schedule, context, conditions
ValidatingPolicy, NamespacedValidatingPolicy match_kinds, match_constraints, match_conditions, validations, validation_actions, failure_policy, audit_annotations, variables, autogen, evaluation, webhook_configuration
MutatingPolicy, NamespacedMutatingPolicy match_kinds, match_constraints, match_conditions, mutations, failure_policy, audit_annotations, variables, autogen, evaluation, reinvocation_policy, target_match_constraints, target_match_conditions, webhook_configuration
GeneratingPolicy, NamespacedGeneratingPolicy match_kinds, match_constraints, match_conditions, generate, audit_annotations, variables, evaluation, use_server_side_apply, webhook_configuration
DeletingPolicy, NamespacedDeletingPolicy match_kinds, match_constraints, schedule, conditions, variables, deletion_propagation_policy
PolicyException (cel_policy_exceptions) policy_refs, match_conditions, images, allowed_values, report_result, expires_at, properties, evaluation_mode

A rule accepts name, context, match, match_kinds, exclude, preconditions, cel_preconditions, validate, mutate, generate, verify_images and image_extractors; any other rule key, such as skipBackgroundRequests, passes through verbatim. An exception entry takes policy_name and rule_names.

Shorthands:

Input Result Source
match_kinds: [<kind>, ...] on a rule, a legacy PolicyException or a cleanup policy match: {any: [{resources: {kinds: [<kind>, ...]}}]}; replaces match match and exclude, MatchResources
match_kinds: [<kind>, ...] on a policies.kyverno.io policy matchConstraints.resourceRules, one entry per kind with its API groups, GA version and resource, and the operations CREATE, UPDATE, or * on deleting policies; replaces resourceRules from match_constraints and spec, other matchConstraints keys stay Kubernetes 1.37.1 discovery, operations as in Kyverno’s migration example and DeletingPolicy example

Kyverno’s admission rejects a policies.kyverno.io policy without a resource rule in matchConstraints (validate.go). match_kinds there knows the GA built-in kinds of Kubernetes 1.37.1; any other kind, such as one from a CRD, stops the compile with a ValueError and belongs under match_constraints.resourceRules, where its API group and resource are explicit. A key that a policies.kyverno.io kind does not take also stops the compile, since an ignored key such as match_kinds on a PolicyException would leave the exception wider than written.

No defaults are added. A field left unset gets Kyverno’s default:

Field Kinds Kyverno’s default Source
validation_failure_action ClusterPolicy, Policy Audit: violations are only reported spec_types.go
validation_actions ValidatingPolicy, NamespacedValidatingPolicy [Deny]: a violating request is rejected ValidationActions
failure_policy validating and mutating policies Fail; GeneratingPolicy always uses Ignore validating, mutating, generating
webhook_configuration.timeoutSeconds validating, mutating, generating policies 10 seconds WebhookConfiguration
evaluation.admission.enabled, evaluation.background.enabled validating, mutating, generating policies true EvaluationConfiguration
autogen.validatingAdmissionPolicy.enabled, autogen.mutatingAdmissionPolicy.enabled validating, mutating policies false validating, mutating
reinvocation_policy, evaluation.mutateExisting.enabled mutating policies Never, false reinvocation, mutateExisting
evaluation.synchronize.enabled, evaluation.generateExisting.enabled, evaluation.orphanDownstreamOnPolicyDelete.enabled generating policies false GeneratingPolicySpec
report_result PolicyException (cel_policy_exceptions) skip PolicyExceptionSpec

PolicyExceptions apply only when Kyverno runs with enablePolicyException and lists their namespace in exceptionNamespace (exceptions). A policies.kyverno.io PolicyException exempts every resource its match_conditions select, in any namespace; its own namespace does not limit it, so state the namespace in a condition (ListExceptions).

On ClusterPolicy and Policy the deprecated spec-level keys are rendered as their replacements. failure_policy and webhook_timeout_seconds become webhookConfiguration.failurePolicy and webhookConfiguration.timeoutSeconds, which Kyverno reads before the deprecated fields (spec_types.go). Setting one of them together with the same field in webhook_configuration stops the compile, because Kyverno rejects a policy with both (validateDeprecatedFields).

generate_existing_on_policy_update becomes generateExisting in the generate block of each rule, because Kyverno rejects the spec-level field even when it is false (validateDeprecatedFields); a rule that sets its own generateExisting keeps it and logs a warning.

validation_failure_action becomes failureAction, capitalised, in the validate block of every rule; Kyverno resolves a rule’s own action before the spec-level one (ruleAction). It stays at spec level where the move would change a resolved action:

  • a validate rule sets its own failureAction: the policy-wide action is the first rule-level one (GetValidationFailureAction)
  • the policy has validation_failure_action_overrides, which a rule-level action would outrank (failureActionForRule)
  • the policy has a verifyImages rule, which reads the spec-level action (validate.go)

Invalid values of validation_failure_action, failure_policy and webhook_timeout_seconds (1 to 30) raise ValueError and stop the compile.

With the reclass-rs inventory backend, keys that start with = lose that character, because reclass treats = as its constant-key prefix. A Kyverno equality anchor =(field) in a pattern then becomes the conditional anchor (field) without any error, which changes what the policy checks. Use the omegaconf backend for policies with equality anchors, or write those checks as validate.cel or deny conditions.

Example

parameters:
  generators:
    kyverno:
      namespace: shop
      cluster_policies:
        disallow-privileged-containers:
          annotations:
            policies.kyverno.io/title: Disallow Privileged Containers
            policies.kyverno.io/category: Pod Security Standards (Baseline)
          validation_failure_action: Enforce
          webhook_configuration:
            failurePolicy: Fail
            timeoutSeconds: 10
          rules:
            - name: privileged-containers
              match_kinds: [Pod]
              validate:
                cel:
                  expressions:
                    - expression: >-
                        object.spec.containers.all(c, !has(c.securityContext) ||
                        !has(c.securityContext.privileged) || c.securityContext.privileged == false)
                      message: Privileged mode is disallowed.
      policies:
        require-memory-limits:
          rules:
            - name: check-memory-limits
              match_kinds: [Pod]
              validate:
                failureAction: Audit
                message: Memory limits are required
                pattern:
                  spec:
                    containers:
                      - resources:
                          limits:
                            memory: "?*"
      policy_exceptions:
        node-exporter-host-access:
          namespace: monitoring
          match:
            any:
              - resources:
                  kinds: [Pod]
                  namespaces: [monitoring]
                  names: ["node-exporter-*"]
          exceptions:
            - policy_name: disallow-privileged-containers
              rule_names: [privileged-containers]
      cluster_cleanup_policies:
        failed-jobs:
          schedule: "0 0 * * *"
          match_kinds: [Job]
          conditions:
            all:
              - key: "{{ target.status.failed || `0` }}"
                operator: GreaterThan
                value: 0
      cleanup_policies:
        preview-pods:
          schedule: "*/30 * * * *"
          spec:
            deletionPropagationPolicy: Foreground
          match:
            any:
              - resources:
                  kinds: [Pod]
                  selector:
                    matchLabels:
                      env: preview
      validating_policies:
        require-team-label:
          match_kinds: [Deployment, StatefulSet]
          validation_actions: [Deny]
          validations:
            - expression: "has(object.metadata.labels) && has(object.metadata.labels.team)"
              message: "label team is required"
      cel_policy_exceptions:
        legacy-billing:
          namespace: billing
          policy_refs:
            - name: require-team-label
              kind: ValidatingPolicy
          match_conditions:
            - name: billing-namespace
              expression: "object.metadata.namespace == 'billing'"
            - name: legacy-deployment
              expression: "object.metadata.name == 'billing-legacy'"
      deleting_policies:
        succeeded-jobs:
          schedule: "0 1 * * *"
          match_kinds: [Job]
          conditions:
            - name: succeeded
              expression: "has(object.status.succeeded) && object.status.succeeded > 0"

Versions

Add a version's inventory entry, then compile with the consumer workflow, which verifies the artifact and runs Kapitan in the sandbox.

Free of charge, as is and on a best-effort basis: use at your own risk, and review the compiled output before you apply it. Terms

This catalog was built from index serial 47. Set index_serial: 47 in .kapitan-sandbox.yaml and the consumer workflow refuses any older index, so a rolled-back index cannot bring back a yanked version.

Checks find known patterns; they do not prove a generator safe. What a listing covers

VersionBuilt for (schema-checked)
1.1.2Kyverno 1.19.1
1.1.1Kyverno 1.19.1
1.1.0Kyverno 1.19.1
1.0.0Kyverno 1.19.1
1.1.2

Inventory

parameters:
  kapitan:
    dependencies:
      - type: oci
        source: ghcr.io/kadet-hub/kyverno:1.1.2@sha256:7dd42bef9a0cbc7a4806aedd164e4183d7ed8e87eda010031c07ad5fa3030d4a
        output_path: lib/kyverno

Verify

gh attestation verify \
  oci://ghcr.io/kadet-hub/kyverno@sha256:7dd42bef9a0cbc7a4806aedd164e4183d7ed8e87eda010031c07ad5fa3030d4a \
  --owner kadet-hub \
  --cert-identity https://github.com/kadet-hub/registry/.github/workflows/release.yml@refs/heads/main

Transparency log: Rekor entry 3250301237, in Sigstore's public, append-only log, so the attestation stays checkable independent of this site.

Kapitan declared
>=0.36.3,<0.37
Kapitan checked
0.36.3
Backends checked
not recorded
With --cache
not recorded
krab
compatible
Built for (schema-checked)
Kyverno 1.19.1
Source
kyverno-v1.1.2 · e4891e8fd85ca0a19ebf361e8b54fd6473fd8a2f · kyverno
Binaries
none
Output capabilities
none
Digest
sha256:7dd42bef9a0cbc7a4806aedd164e4183d7ed8e87eda010031c07ad5fa3030d4a

Checks

Checked by the release run on , gate at fe9998b5168d.

  • Secrets gitleaks 8.30.1
    No secret matched the marketplace's gitleaks rules.
  • Malware ClamAV 1.5.4
    No file matched a ClamAV signature.
  • Malicious package heuristics GuardDog 3.2.0
    No GuardDog threat rule matched.
  • Dangerous code Semgrep 1.180.0
    No marketplace Semgrep rule matched, such as eval, subprocess or network calls.
  • Python errors Ruff 0.17.0
    No syntax error or undefined name (Ruff, error rules only).
  • File tree tree_check.py
    No symlink, executable or banned file; imports within the allowlist.
  • Sandboxed compile gVisor 20261005, Kapitan 0.36.3
    The fixture compiled without network, with decoy credentials; no undeclared program ran, no decoy was read.
  • Output capabilities Conftest 0.71.1
    The compiled output uses only the capabilities the manifest declares.
  • CI detection Kapitan 0.36.3
    The output is the same with CI variables set.

SBOM (SPDX 2.3)

Output diff

No output diff recorded: this version was published before the release run recorded one.

1.1.1

Inventory

parameters:
  kapitan:
    dependencies:
      - type: oci
        source: ghcr.io/kadet-hub/kyverno:1.1.1@sha256:4c497d16eb6f9d8f08511e0d07decb0f0e843cda36ef3ead767a57a00c5b30b2
        output_path: lib/kyverno

Verify

gh attestation verify \
  oci://ghcr.io/kadet-hub/kyverno@sha256:4c497d16eb6f9d8f08511e0d07decb0f0e843cda36ef3ead767a57a00c5b30b2 \
  --owner kadet-hub \
  --cert-identity https://github.com/kadet-hub/registry/.github/workflows/release.yml@refs/heads/main

Transparency log: Rekor entry 3244272841, in Sigstore's public, append-only log, so the attestation stays checkable independent of this site.

Kapitan declared
>=0.36.3,<0.37
Kapitan checked
0.36.3
Backends checked
not recorded
With --cache
not recorded
krab
compatible
Built for (schema-checked)
Kyverno 1.19.1
Source
kyverno-v1.1.1 · 9166cb30e0ae4874bc8f229c6a6823eff7451d04 · kyverno
Binaries
none
Output capabilities
none
Digest
sha256:4c497d16eb6f9d8f08511e0d07decb0f0e843cda36ef3ead767a57a00c5b30b2

Checks

Checked by the release run on , gate at cb64712208f8.

  • Secrets gitleaks 8.30.1
    No secret matched the marketplace's gitleaks rules.
  • Malware ClamAV 1.5.4
    No file matched a ClamAV signature.
  • Malicious package heuristics GuardDog 3.2.0
    No GuardDog threat rule matched.
  • Dangerous code Semgrep 1.180.0
    No marketplace Semgrep rule matched, such as eval, subprocess or network calls.
  • Python errors Ruff 0.17.0
    No syntax error or undefined name (Ruff, error rules only).
  • File tree tree_check.py
    No symlink, executable or banned file; imports within the allowlist.
  • Sandboxed compile gVisor 20261005, Kapitan 0.36.3
    The fixture compiled without network, with decoy credentials; no undeclared program ran, no decoy was read.
  • Output capabilities Conftest 0.71.1
    The compiled output uses only the capabilities the manifest declares.
  • CI detection Kapitan 0.36.3
    The output is the same with CI variables set.

SBOM (SPDX 2.3)

Output diff

No output diff recorded: this version was published before the release run recorded one.

1.1.0

Inventory

parameters:
  kapitan:
    dependencies:
      - type: oci
        source: ghcr.io/kadet-hub/kyverno:1.1.0@sha256:893d6c319379dbd3d27d92efecc164f432a01caf723503e2bd6b584b40badf9a
        output_path: lib/kyverno

Verify

gh attestation verify \
  oci://ghcr.io/kadet-hub/kyverno@sha256:893d6c319379dbd3d27d92efecc164f432a01caf723503e2bd6b584b40badf9a \
  --owner kadet-hub \
  --cert-identity https://github.com/kadet-hub/registry/.github/workflows/release.yml@refs/heads/main

Transparency log: Rekor entry 3241341971, in Sigstore's public, append-only log, so the attestation stays checkable independent of this site.

Kapitan declared
>=0.36.3,<0.37
Kapitan checked
0.36.3
Backends checked
not recorded
With --cache
not recorded
krab
compatible
Built for (schema-checked)
Kyverno 1.19.1
Source
kyverno-v1.1.0 · a4937dfc696b9c61c48edf4501da517db574b8ab · kyverno
Binaries
none
Output capabilities
none
Digest
sha256:893d6c319379dbd3d27d92efecc164f432a01caf723503e2bd6b584b40badf9a

Checks

Checked by the release run on , gate at 195f89da6f48.

  • Secrets gitleaks 8.30.1
    No secret matched the marketplace's gitleaks rules.
  • Malware ClamAV 1.5.4
    No file matched a ClamAV signature.
  • Malicious package heuristics GuardDog 3.2.0
    No GuardDog threat rule matched.
  • Dangerous code Semgrep 1.180.0
    No marketplace Semgrep rule matched, such as eval, subprocess or network calls.
  • Python errors Ruff 0.17.0
    No syntax error or undefined name (Ruff, error rules only).
  • File tree tree_check.py
    No symlink, executable or banned file; imports within the allowlist.
  • Sandboxed compile gVisor 20261005, Kapitan 0.36.3
    The fixture compiled without network, with decoy credentials; no undeclared program ran, no decoy was read.
  • Output capabilities Conftest 0.71.1
    The compiled output uses only the capabilities the manifest declares.
  • CI detection Kapitan 0.36.3
    The output is the same with CI variables set.

SBOM (SPDX 2.3)

Output diff

No output diff recorded: this version was published before the release run recorded one.

1.0.0

Inventory

parameters:
  kapitan:
    dependencies:
      - type: oci
        source: ghcr.io/kadet-hub/kyverno:1.0.0@sha256:4d409aa575f4ae48992794be30eceeca342bc0f08743468d4611f07356f0ba53
        output_path: lib/kyverno

Verify

gh attestation verify \
  oci://ghcr.io/kadet-hub/kyverno@sha256:4d409aa575f4ae48992794be30eceeca342bc0f08743468d4611f07356f0ba53 \
  --owner kadet-hub \
  --cert-identity https://github.com/kadet-hub/registry/.github/workflows/release.yml@refs/heads/main

Transparency log: Rekor entry 3212108021, in Sigstore's public, append-only log, so the attestation stays checkable independent of this site.

Kapitan declared
>=0.36.3,<0.37
Kapitan checked
0.36.3
Backends checked
not recorded
With --cache
not recorded
krab
compatible
Built for (schema-checked)
Kyverno 1.19.1
Source
kyverno-v1.0.0 · c3fd859273b2e76315c54f56052dc743669ac318 · kyverno
Binaries
none
Output capabilities
none
Digest
sha256:4d409aa575f4ae48992794be30eceeca342bc0f08743468d4611f07356f0ba53

Checks

Checked by the release run on , gate at 4f27fde613c7.

  • Secrets gitleaks 8.30.1
    No secret matched the marketplace's gitleaks rules.
  • Malware ClamAV 1.5.4
    No file matched a ClamAV signature.
  • Malicious package heuristics GuardDog 3.2.0
    No GuardDog threat rule matched.
  • Dangerous code Semgrep 1.180.0
    No marketplace Semgrep rule matched, such as eval, subprocess or network calls.
  • Python errors Ruff 0.17.0
    No syntax error or undefined name (Ruff, error rules only).
  • File tree tree_check.py
    No symlink, executable or banned file; imports within the allowlist.
  • Sandboxed compile gVisor 20261005, Kapitan 0.36.3
    The fixture compiled without network, with decoy credentials; no undeclared program ran, no decoy was read.
  • Output capabilities Conftest 0.71.1
    The compiled output uses only the capabilities the manifest declares.
  • CI detection Kapitan 0.36.3
    The output is the same with CI variables set.

SBOM (SPDX 2.3)

Output diff

No output diff recorded: this version was published before the release run recorded one.