Skip to content

feat: support spec.background on CEL PolicyException - #129

Open
anushkagupta200615-jpg wants to merge 1 commit into
kyverno:mainfrom
anushkagupta200615-jpg:feat-polex-background
Open

anushkagupta200615-jpg wants to merge 1 commit into
kyverno:mainfrom
anushkagupta200615-jpg:feat-polex-background

Conversation

@anushkagupta200615-jpg

Copy link
Copy Markdown

Explanation

This PR adds support for .spec.background on CEL-based PolicyException resources (policies.kyverno.io), bringing parity with legacy kyverno.io/v2 PolicyExceptions.

Currently, CEL PolicyExceptions apply unconditionally to both admission reviews and background report scans. In enterprise environments, security and compliance teams often grant exceptions to allow resource deployments at admission time without blocking developers, while requiring non compliant resources to continue being reported as violations during background scans (PolicyReports) for audit tracking. Adding .spec.background: false allows users to disable applying exceptions during background scans while preserving admission bypass behavior.

Related issue

Part of kyverno/kyverno#17847 (API changes)
Discussed with @JimBugwadia on the #kyverno Kubernetes Slack channel.

Proposed Changes

  • API Specification: Added optional pointer field Background *bool (json:"background,omitempty") to PolicyExceptionSpec in api/policies.kyverno.io/v1alpha1 (and exposed via v1beta1).
  • Backward Compatibility: Added helper method BackgroundProcessingEnabled() bool which returns true if Background is nil or true. Existing exceptions without this field maintain identical behavior.
  • Code Generation:
    • Regenerated deepcopy implementations (zz_generated.deepcopy.go).
    • Regenerated CRD manifests: config/crds/policies.kyverno.io_policyexceptions.yaml, config/crds.yaml, and Helm chart templates in charts/kyverno-api/templates/crds/.
  • Testing: Added unit test coverage for BackgroundProcessingEnabled() in api/policies.kyverno.io/v1beta1/policy_exception_test.go covering nil, true, and false values.

Checklist

  • I have read the contributing guidelines.
  • I have read the PR documentation guide and followed the process including adding proof manifests to this PR.
  • This is a bug fix and I have added unit tests that prove my fix is effective.

Further Comments

This is Part 1 of the implementation for kyverno/kyverno#17847:

  1. Part 1 (this PR in kyverno/api): Defines the API field, helpers, and regenerated CRDs.
  2. Part 2 (follow-up PR in kyverno/kyverno): Updates FetchCELPolicyExceptions in pkg/controllers/report/utils/utils.go to filter out exceptions where BackgroundProcessingEnabled() == false.

Support configuring spec.background on CEL PolicyExceptions to allow disabling exceptions during background scans, matching legacy kyverno.io/v2 PolicyExceptions.

Refs: kyverno/kyverno#17847
Signed-off-by: anushkagupta200615-jpg <anushkagupta200615@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant