Repository navigation
feat: add auditAnnotations to MutatingPolicySpec - #119
Merged
Merged
Conversation
Add AuditAnnotations []admissionregistrationv1.AuditAnnotation to MutatingPolicySpec, following the same pattern used by ValidatingPolicy, ImageValidatingPolicy and GeneratingPolicy. The field carries CEL expressions evaluated by Kyverno after mutations are applied successfully; results are surfaced as properties in policy report results. It provides migration parity for the legacy ClusterPolicy spec.rules[].reportProperties field. Ref: kyverno/kyverno#16719 Signed-off-by: realshuting <shuting@nirmata.com>
5 of 8 tasks
There was a problem hiding this comment.
Pull request overview
Adds spec.auditAnnotations support to MutatingPolicySpec so Kyverno can evaluate CEL expressions after successful mutations and surface the evaluated values as policy report result properties, aligning mutate policies with other CEL-based policy types.
Changes:
- Add optional
AuditAnnotations []admissionregistrationv1.AuditAnnotationtoMutatingPolicySpec(v1alpha1; aliased through v1beta1/v1). - Regenerate deepcopy code to copy the new
AuditAnnotationsslice.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| api/policies.kyverno.io/v1alpha1/mutating_policy.go | Introduces the new AuditAnnotations field on MutatingPolicySpec with documentation. |
| api/policies.kyverno.io/v1alpha1/zz_generated.deepcopy.go | Updates autogenerated deepcopy logic to copy AuditAnnotations. |
Files not reviewed (1)
- api/policies.kyverno.io/v1alpha1/zz_generated.deepcopy.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…artifact on CI failure - Regenerate CRDs, helm chart CRDs and API docs for the new MutatingPolicySpec auditAnnotations field (make codegen). - Port the kyverno/kyverno codegen CI improvement: on verify-codegen failure, upload the regenerated diff as a patch artifact so contributors can 'git apply' the fix instead of re-running codegen locally. Signed-off-by: realshuting <shuting@nirmata.com>
realshuting
marked this pull request as ready for review
July 23, 2026 08:54
realshuting
enabled auto-merge (squash)
July 23, 2026 08:54
fjogeleit
approved these changes
Jul 23, 2026
realshuting
disabled auto-merge
July 23, 2026 09:03
realshuting
force-pushed
the
realshuting/mpol-audit-annotations
branch
from
July 23, 2026 09:07
d83cd20 to
ffdc0e8
Compare
realshuting
added a commit
to realshuting/kyverno
that referenced
this pull request
Jul 23, 2026
Point the api dependency at the kyverno/api main commit that includes the MutatingPolicySpec auditAnnotations field (kyverno/api#119, merged as fb27857), replacing the PR-branch pseudo-version. Signed-off-by: realshuting <shuting@nirmata.com>
realshuting
added a commit
to kyverno/kyverno
that referenced
this pull request
Jul 24, 2026
* feat(mpol): add auditAnnotations support to MutatingPolicy Add report properties support to MutatingPolicy following the ValidatingPolicy/ImageValidatingPolicy/GeneratingPolicy auditAnnotations pattern, providing migration parity for the legacy ClusterPolicy spec.rules[].reportProperties field. Changes: - api: bump github.com/kyverno/api to include AuditAnnotations []admissionregistrationv1.AuditAnnotation on MutatingPolicySpec - mpol compiler: compile auditAnnotations CEL programs with the shared compiler.CompileAuditAnnotations; store in the compiled Policy - mpol compiler evaluate: add evaluateAuditAnnotations that evaluates each key's valueExpression after all mutations apply successfully (policy variables and the patched object in scope); empty results are omitted; results returned via EvaluationResult.AuditAnnotations - mpol engine: pass evaluated annotations into the success RulePass response properties so they surface in mutation policy report results; covers both the admission path and the mutate-existing/background path through the shared handlePolicy - mpol validate: include auditAnnotation valueExpressions in the HTTP expression scan for namespaced policy validation - codegen: regenerate mpol/nmpol CRDs and CLI-embedded CRDs - tests: compiler/evaluation/engine unit tests and a chainsaw E2E test asserting report result properties Note: auditAnnotations is Kyverno-report-only and intentionally not projected into generated Kubernetes MutatingAdmissionPolicy resources. Closes: #16719 Ref: #16504 Signed-off-by: realshuting <shuting@nirmata.com> * chore: bump github.com/kyverno/api to merged main commit Point the api dependency at the kyverno/api main commit that includes the MutatingPolicySpec auditAnnotations field (kyverno/api#119, merged as fb27857), replacing the PR-branch pseudo-version. Signed-off-by: realshuting <shuting@nirmata.com> * chore: regenerate CRD reference docs for auditAnnotations Apply the codegen-docs-patch artifact from the Verify codegen (docs) CI job; the api dependency bump required codegen-all-docs in addition to codegen-all-code (make codegen-api-bump covers both). Signed-off-by: realshuting <shuting@nirmata.com> --------- Signed-off-by: realshuting <shuting@nirmata.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Adds
AuditAnnotations []admissionregistrationv1.AuditAnnotationtoMutatingPolicySpec(v1alpha1, exposed through the v1beta1/v1 aliases).The field carries CEL expressions that Kyverno evaluates after mutations are applied successfully; the results are surfaced as properties in policy report results (
results[].properties). It is intentionally not projected into generated KubernetesMutatingAdmissionPolicyresources, since native MAP has no equivalent.Why
Migration parity for the legacy ClusterPolicy
spec.rules[].reportPropertiesfield (cpol mutate → mpol migration, kyverno/kyverno#16504). This mirrors the field already present onValidatingPolicySpec,ImageValidatingPolicySpecand — as of #108/kyverno/kyverno#16505 —GeneratingPolicySpec.Related
Changes
api/policies.kyverno.io/v1alpha1/mutating_policy.go: new optionalAuditAnnotationsfield onMutatingPolicySpecapi/policies.kyverno.io/v1alpha1/zz_generated.deepcopy.go: regenerated (make deepcopy-gen)