mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
Fix regression in wildcard matches in In/AnyIn operators (#3686)
Signed-off-by: Sambhav Kothari <skothari44@bloomberg.net> Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com>
This commit is contained in:
parent
8c930134ef
commit
25badfe4fb
4 changed files with 24 additions and 2 deletions
|
@ -63,7 +63,7 @@ func anyKeyExistsInArray(key string, value interface{}, log logr.Logger) (invali
|
||||||
|
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
for _, val := range valuesAvailable {
|
for _, val := range valuesAvailable {
|
||||||
if wildcard.Match(fmt.Sprint(val), key) {
|
if wildcard.Match(fmt.Sprint(val), key) || wildcard.Match(key, fmt.Sprint(val)) {
|
||||||
return false, true
|
return false, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ func keyExistsInArray(key string, value interface{}, log logr.Logger) (invalidTy
|
||||||
|
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
for _, val := range valuesAvailable {
|
for _, val := range valuesAvailable {
|
||||||
if wildcard.Match(fmt.Sprint(val), key) {
|
if wildcard.Match(fmt.Sprint(val), key) || wildcard.Match(key, fmt.Sprint(val)) {
|
||||||
return false, true
|
return false, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,3 +44,8 @@ results:
|
||||||
resource: example
|
resource: example
|
||||||
kind: Pod
|
kind: Pod
|
||||||
result: pass
|
result: pass
|
||||||
|
- policy: example
|
||||||
|
rule: wildcard-match
|
||||||
|
resource: example
|
||||||
|
kind: Pod
|
||||||
|
result: pass
|
||||||
|
|
|
@ -146,3 +146,20 @@ spec:
|
||||||
- key: "{{ to_string(obj.notName) }}"
|
- key: "{{ to_string(obj.notName) }}"
|
||||||
operator: NotEquals
|
operator: NotEquals
|
||||||
value: 'null'
|
value: 'null'
|
||||||
|
- name: wildcard-match
|
||||||
|
context:
|
||||||
|
- name: obj
|
||||||
|
variable:
|
||||||
|
value:
|
||||||
|
- A=ATest
|
||||||
|
- B=BTest
|
||||||
|
match:
|
||||||
|
resources:
|
||||||
|
kinds:
|
||||||
|
- Pod
|
||||||
|
validate:
|
||||||
|
deny:
|
||||||
|
conditions:
|
||||||
|
- key: "A=*"
|
||||||
|
operator: AnyNotIn
|
||||||
|
value: "{{ obj }}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue