diff --git a/cmd/cli/kubectl-kyverno/utils/common/regex.go b/cmd/cli/kubectl-kyverno/utils/common/regex.go deleted file mode 100644 index 8e74c25494..0000000000 --- a/cmd/cli/kubectl-kyverno/utils/common/regex.go +++ /dev/null @@ -1,8 +0,0 @@ -package common - -import ( - "regexp" -) - -// RegexVariables represents regex for '{{}}' -var RegexVariables = regexp.MustCompile(`\{\{[^{}]*\}\}`) diff --git a/pkg/validation/policy/validate.go b/pkg/validation/policy/validate.go index 2b41157bd6..44cd533a50 100644 --- a/pkg/validation/policy/validate.go +++ b/pkg/validation/policy/validate.go @@ -16,7 +16,6 @@ import ( "github.com/kyverno/go-jmespath" "github.com/kyverno/kyverno/api/kyverno" kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1" - "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common" "github.com/kyverno/kyverno/pkg/autogen" "github.com/kyverno/kyverno/pkg/clients/dclient" openapicontroller "github.com/kyverno/kyverno/pkg/controllers/openapi" @@ -43,6 +42,7 @@ var ( allowedVariablesBackground = regexp.MustCompile(`request\.|element|elementIndex|@|images|images\.|image\.|([a-z_0-9]+\()[^{}]`) allowedVariablesInTarget = regexp.MustCompile(`request\.|serviceAccountName|serviceAccountNamespace|element|elementIndex|@|images|images\.|image\.|target\.|([a-z_0-9]+\()[^{}]`) allowedVariablesBackgroundInTarget = regexp.MustCompile(`request\.|element|elementIndex|@|images|images\.|image\.|target\.|([a-z_0-9]+\()[^{}]`) + regexVariables = regexp.MustCompile(`\{\{[^{}]*\}\}`) // wildCardAllowedVariables represents regex for the allowed fields in wildcards wildCardAllowedVariables = regexp.MustCompile(`\{\{\s*(request\.|serviceAccountName|serviceAccountNamespace)[^{}]*\}\}`) errOperationForbidden = errors.New("variables are forbidden in the path of a JSONPatch") @@ -542,7 +542,7 @@ func objectHasVariables(object interface{}) error { return err } - if len(common.RegexVariables.FindAllStringSubmatch(string(objectJSON), -1)) > 0 { + if len(regexVariables.FindAllStringSubmatch(string(objectJSON), -1)) > 0 { return fmt.Errorf("invalid variables") }