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

Should match.resources.kinds be required? #1734

Closed
realshuting opened this issue Mar 25, 2021 · 2 comments · Fixed by #1852
Closed

Should match.resources.kinds be required? #1734

realshuting opened this issue Mar 25, 2021 · 2 comments · Fixed by #1852
Assignees
Labels
Documentation Update Documentation enhancement New feature or request

Comments

@realshuting
Copy link
Member

Is your feature request related to a problem? Please describe.
With Kyverno v1.3.4, match.resources.kinds is optional while match.resources is required:

// +optional
Kinds []string `json:"kinds,omitempty" yaml:"kinds,omitempty"`

// MatchResources defines when this policy rule should be applied. The match
// criteria can include resource information (e.g. kind, name, namespace, labels)
// and admission review request information like the user name or role.
// At least one kind is required.
MatchResources MatchResources `json:"match,omitempty" yaml:"match,omitempty"`

This is different from what we have on the website:

At least one element must be specified in a match or exclude block. The kind attribute is optional when working with the resources element, but if it’s not specified the policy rule will only be applicable to metadata that is common across all resource kinds.

Describe the solution you'd like
In most cases, match.resources.kinds is used to apply rules. With this, it seems okay to define this field as required. In case one wants to apply policy to metadata across all types of resources, we can allow any "*" in kinds.

Would like to get thoughts and feedback first on this issue, and then we can finalize and document the expected behaviors.

@realshuting realshuting added enhancement New feature or request Documentation Update Documentation labels Mar 25, 2021
@JimBugwadia JimBugwadia changed the title Can match.resources.kinds be required? Should match.resources.kinds be required? Mar 27, 2021
@chipzoller
Copy link
Member

Supporting a wildcard (*) for match.resources.kinds seems like a good idea if users only want to work with metadata. So making it required but supporting either explicit kinds of * seems like a good approach. Curious to know other perspectives and what alternatives might be.

@realshuting
Copy link
Member Author

I should've explained it in the description.

The reason for this change is that we can build an internal cache of the matched kinds for a fast lookup during admission review. In this issue, the user had to specify a long exclude list to reduce CPU usage, which was a pain. I came up with a solution to add the matched list, but it seems like we can build this list from the defined policies directly. Having kinds as required makes it consistent (with an exception "*"), it informs the user that the rule must match at least one kind to apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Update Documentation enhancement New feature or request
Projects
None yet
3 participants