Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a proposal for introducing the ValidatingPolicy #66

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MariamFahmy98
Copy link
Contributor

This PR adds a proposal to introduce ValidatingPolicy

@MariamFahmy98 MariamFahmy98 force-pushed the new-policy-types branch 5 times, most recently from 84a9486 to a1e660f Compare December 27, 2024 15:14
Copy link
Member

@realshuting realshuting left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great @MariamFahmy98 @KhaledEmaraDev ! Left a few comments below.


While ValidatingAdmissionPolicies and MutatingAdmissionPolicies offer robust features, they fall short in addressing several critical use cases for Policy-as-Code. Below are the limitations and opportunities for improvement:

1. Data Lookups: The built-in policies cannot perform data lookups from the API server or external API endpoints.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...from the API server...

Is this still true?


#### Any/All Resource Filters

Kyverno provides flexible resource matching through the use of `any` and `all` filters. The `any` filter allows you to define multiple resource specifications, where a match occurs if any of the specified conditions are met **(OR logic)**. This means a resource will be matched if it satisfies at least one of the defined criteria. The `all` filter requires all specified conditions to be true for a match **(AND logic)**. This ensures a resource matches only if it satisfies every single criterion.
Copy link
Member

@realshuting realshuting Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this represented in the ValidatingPolicy CRD, is there an example?


Kubernetes VAPs offer a `spec.matchConditions` field for fine-grained request filtering, similar to Kyverno's `preconditions`. This presents two options: utilize the VAP's matchConditions within the webhook configuration, or handle these conditions internally in the Kyverno engine.

Furthermore, VAPs offer a matchPolicy field (set to `Exact` or `Equivalent`) that governs how incoming requests are matched against rules. `Exact` requires precise matching, while `Equivalent` allows for matching across different API groups or versions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Furthermore, VAPs offer a matchPolicy field (set to `Exact` or `Equivalent`) that governs how incoming requests are matched against rules. `Exact` requires precise matching, while `Equivalent` allows for matching across different API groups or versions.
Furthermore, VAPs offer a `matchPolicy` field (set to `Exact` or `Equivalent`) that governs how incoming requests are matched against rules. `Exact` requires precise matching, while `Equivalent` allows for matching across different API groups or versions.


1. `ruleNames`: This field is unnecessary, as ValidatingPolicies don't employ the concept of rules. This field should be removed from the PolicyException spec.

2. `match`: This field filters resources based on Kind. However, ValidatingPolicies utilize `matchConstraints` based on API groups, versions, operations, and resources. Therefore, the PolicyException's match field must be replaced with a matchConstraints field to align with this mechanism.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. `match`: This field filters resources based on Kind. However, ValidatingPolicies utilize `matchConstraints` based on API groups, versions, operations, and resources. Therefore, the PolicyException's match field must be replaced with a matchConstraints field to align with this mechanism.
2. `match`: This field filters resources based on Kind. However, ValidatingPolicies utilize `matchConstraints` based on API groups, versions, operations, and resources. Therefore, the PolicyException's match field must be replaced with a `matchConstraints` field to align with this mechanism.

object.metadata.labels.app == 'busybox'
```

How can we generate Kubernetes ValidatingAdmissionPolicies based on Kyverno's ValidatingPolicy and PolicyException CRDs?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leverage webhook match conditions for exclusions?

proposals/new_policy_types.md Show resolved Hide resolved
Comment on lines 471 to 475
Kubernetes VAPs offer a `spec.matchConditions` field for fine-grained request filtering, similar to Kyverno's `preconditions`. This presents two options: utilize the VAP's matchConditions within the webhook configuration, or handle these conditions internally in the Kyverno engine.

Furthermore, VAPs offer a matchPolicy field (set to `Exact` or `Equivalent`) that governs how incoming requests are matched against rules. `Exact` requires precise matching, while `Equivalent` allows for matching across different API groups or versions.

To maintain consistency and offer similar flexibility, the `ValidatingPolicy` CRD should introduce a `matchPolicy` field too. This presents two options: utilize this field within the webhook configuration, or handle it internally in the Kyverno engine.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this proposal, a webhookConfiguration is added to the validatingpolicy.spec. Both matchConditions and matchPolicy are available for webhook configuraiton.

feat: add webhook registration details for new CRD
Signed-off-by: Mariam Fahmy <[email protected]>
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.

3 participants