mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-05 15:37:19 +00:00
Remove regexp, add wildcard checks instead
This commit is contained in:
parent
d0e832b424
commit
4862d03c3c
2 changed files with 2 additions and 23 deletions
|
@ -3,7 +3,6 @@ package v1alpha1
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
@ -66,13 +65,6 @@ func (pr *PolicyResource) Validate() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if pr.Name != nil {
|
|
||||||
// make non-regexp a regexp to match exactly to the given name
|
|
||||||
if _, err := regexp.Compile(*pr.Name); err != nil {
|
|
||||||
return fmt.Errorf("invalied regex, err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package webhooks
|
package webhooks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"github.com/minio/minio/pkg/wildcard"
|
||||||
|
|
||||||
types "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
types "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
||||||
"k8s.io/api/admission/v1beta1"
|
"k8s.io/api/admission/v1beta1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
@ -62,21 +61,9 @@ func IsRuleApplicableToResource(kind string, resourceRaw []byte, policyResource
|
||||||
|
|
||||||
if policyResource.Name != nil {
|
if policyResource.Name != nil {
|
||||||
|
|
||||||
policyResourceName, isRegex := parseRegexPolicyResourceName(*policyResource.Name)
|
if !wildcard.Match(*policyResource.Name, name) {
|
||||||
|
|
||||||
// if no regex used, check if names are matched, return directly
|
|
||||||
if !isRegex && policyResourceName != name {
|
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// validation of regex is peformed when validating the policyResource
|
|
||||||
// refer to policyResource.Validate()
|
|
||||||
if isRegex {
|
|
||||||
match, _ := regexp.MatchString(policyResourceName, name)
|
|
||||||
if !match {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if policyResource.Selector != nil {
|
if policyResource.Selector != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue