mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
feat: add config exclusions in the engine (#7420)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
5d5011d5d9
commit
ff7cda2694
1 changed files with 8 additions and 2 deletions
|
@ -183,11 +183,17 @@ func (e *engine) ContextLoader(
|
|||
}
|
||||
|
||||
// matches checks if either the new or old resource satisfies the filter conditions defined in the rule
|
||||
func matches(
|
||||
func (e *engine) matches(
|
||||
rule kyvernov1.Rule,
|
||||
policyContext engineapi.PolicyContext,
|
||||
resource unstructured.Unstructured,
|
||||
) error {
|
||||
if policyContext.AdmissionOperation() {
|
||||
request := policyContext.AdmissionInfo()
|
||||
if e.configuration.IsExcluded(request.AdmissionUserInfo.Username, request.AdmissionUserInfo.Groups, request.Roles, request.ClusterRoles) {
|
||||
return fmt.Errorf("excluded by configuration")
|
||||
}
|
||||
}
|
||||
gvk, subresource := policyContext.ResourceKind()
|
||||
err := engineutils.MatchesResourceDescription(
|
||||
resource,
|
||||
|
@ -236,7 +242,7 @@ func (e *engine) invokeRuleHandler(
|
|||
fmt.Sprintf("RULE %s", rule.Name),
|
||||
func(ctx context.Context, span trace.Span) (unstructured.Unstructured, []engineapi.RuleResponse) {
|
||||
// check if resource and rule match
|
||||
if err := matches(rule, policyContext, resource); err != nil {
|
||||
if err := e.matches(rule, policyContext, resource); err != nil {
|
||||
logger.V(4).Info("rule not matched", "reason", err.Error())
|
||||
return resource, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue