Skip to content

feat(vpol): Add Best Practices ValidatingPolicy conversions#1426

Open
AIWithShrey wants to merge 8 commits intokyverno:mainfrom
AIWithShrey:add-best-practices-vpol
Open

feat(vpol): Add Best Practices ValidatingPolicy conversions#1426
AIWithShrey wants to merge 8 commits intokyverno:mainfrom
AIWithShrey:add-best-practices-vpol

Conversation

@AIWithShrey
Copy link

Summary

This PR introduces best-practices-vpol/ - a new folder for ValidatingPolicy versions of Best Practices policies, following the existing naming convention:

  • best-practices/ → ClusterPolicy
  • best-practices-cel/ → CEL ClusterPolicy
  • best-practices-gpol/ → GeneratingPolicy
  • best-practices-mpol/ → MutatingPolicy
  • best-practices-vpol/ → ValidatingPolicy (NEW)

Policies Added

best-practices-vpol/ (5 policies)

Policy Description
disallow-cri-sock-mount Prevents container socket mounts (docker.sock, containerd.sock, etc.)
disallow-default-namespace Prevents use of default namespace for workloads
disallow-helm-tiller Prevents Helm Tiller images
disallow-latest-tag Prevents :latest tag and missing image tags
require-drop-cap-net-raw Requires dropping CAP_NET_RAW capability

other-vpol/ (1 policy)

Policy Description
protect-node-taints Blocks unauthorized Node taint modifications (Security category)

Testing

All policies have been tested with Chainsaw against a kind cluster with Kyverno installed:

  • ✅ Good resources are allowed
  • ✅ Bad resources are denied with appropriate error messages
  • ✅ Policy webhook registers correctly

Checklist

  • Policies use CEL expressions (not JMESPath)
  • Each policy has .chainsaw-test/ with test cases
  • Each policy has artifacthub-pkg.yml with digest and createdAt
  • Follows existing folder structure conventions
  • policy-ready.yaml asserts webhook configuration

Related

These are ValidatingPolicy conversions of existing ClusterPolicies from best-practices/.

Add 5 ValidatingPolicy conversions from the Best Practices category:
- disallow-cri-sock-mount: Prevents container socket mounts
- disallow-default-namespace: Prevents use of default namespace
- disallow-helm-tiller: Prevents Helm Tiller images
- disallow-latest-tag: Prevents :latest tag and missing tags
- require-drop-cap-net-raw: Requires dropping CAP_NET_RAW

All policies include:
- CEL-based ValidatingPolicy implementation
- Chainsaw tests with good/bad test cases
- artifacthub-pkg.yml for Artifact Hub integration

Tested and validated on kind-kyverno cluster.

Signed-off-by: Shreyas Mocherla <shreyas@shreyasm.com>
Add additional ValidatingPolicy conversions:
- block-bare-pods: Prevent bare pods without ownerReferences
- protect-node-taints: Block unauthorized Node taint modifications
- require-corp-version-label: Require semver version label

Note: memory-requests-equal-limits and prevent-cr8escape already
exist in the repo - skipped to avoid overwriting.

All policies include Chainsaw tests and Artifact Hub metadata.

Signed-off-by: Shreyas Mocherla <shreyas@shreyasm.com>
Removed duplicates:
- block-bare-pods (same as upstream prevent-bare-pods)
- require-corp-version-label (same as upstream metadata-match-regex)

Signed-off-by: Shreyas Mocherla <shreyas@shreyasm.com>
Create new best-practices-vpol/ folder to follow upstream convention:
- best-practices/ for ClusterPolicy
- best-practices-cel/ for CEL ClusterPolicy
- best-practices-gpol/ for GeneratingPolicy
- best-practices-mpol/ for MutatingPolicy
- best-practices-vpol/ for ValidatingPolicy (NEW)

Moved 5 policies from other-vpol/ to best-practices-vpol/:
- disallow-cri-sock-mount
- disallow-default-namespace
- disallow-helm-tiller
- disallow-latest-tag
- require-drop-cap-net-raw

protect-node-taints remains in other-vpol/ (Security category)

Signed-off-by: Shreyas Mocherla <shreyas@shreyasm.com>
Generated using the same approach as .hack/update-artifacthub-pkg.sh:
- digest: SHA256 hash of the policy YAML file
- createdAt: UTC timestamp

These fields are required for Artifact Hub integration.

Signed-off-by: Shreyas Mocherla <shreyas@shreyasm.com>
@AIWithShrey AIWithShrey force-pushed the add-best-practices-vpol branch from 3d89fcc to 3c112d8 Compare February 3, 2026 12:31
Update all ValidatingPolicy resources and Chainsaw tests to use
policies.kyverno.io/v1 as v1alpha1 will be removed in the next
Kyverno OSS release.

Signed-off-by: Shreyas Mocherla <shreyas@shreyasm.com>
realshuting
realshuting previously approved these changes Feb 3, 2026
@realshuting realshuting enabled auto-merge (squash) February 3, 2026 13:05
Signed-off-by: Shreyas Mocherla <shreyas@shreyasm.com>
auto-merge was automatically disabled February 3, 2026 13:38

Head branch was pushed to by a user without write access

…test

By default, Kyverno excludes Nodes from processing. This policy targets
Node UPDATE operations, so we need to temporarily enable Node processing
in the Kyverno configmap before applying the policy, similar to other
Node-related policies like restrict-node-label-creation.

Signed-off-by: Shreyas Mocherla <shreyas@shreyasm.com>
@AIWithShrey AIWithShrey force-pushed the add-best-practices-vpol branch from 940241e to 47f88d4 Compare February 3, 2026 14:41
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.

2 participants