1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-29 10:55:05 +00:00

Fix panic for provides a set to the key of a precondition and deny condition (#3162)

This commit is contained in:
Vyankatesh Kudtarkar 2022-02-03 20:16:58 +05:30 committed by GitHub
parent ed3811ea5a
commit 373f421b07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 0 deletions

View file

@ -1004,6 +1004,16 @@ func validateConditionValues(c kyverno.Condition) (string, error) {
if c.Key == nil || c.Value == nil || c.Operator == "" {
return "", fmt.Errorf("entered value of `key`, `value` or `operator` is missing or misspelled")
}
switch reflect.TypeOf(c.Key).Kind() {
case reflect.String:
value, err := validateValuesKeyRequest(c)
return value, err
default:
return "", nil
}
}
func validateValuesKeyRequest(c kyverno.Condition) (string, error) {
switch strings.ReplaceAll(c.Key.(string), " ", "") {
case "{{request.operation}}":
return validateConditionValuesKeyRequestOperation(c)

View file

@ -0,0 +1,17 @@
name: test-simple
policies:
- policy.yaml
resources:
- resources.yaml
results:
- policy: test-multiple-key
rule: test-multiple-key
resource: test-resource-pass
kind: Pod
status: pass
- policy: test-multiple-key
rule: test-multiple-key
resource: test-resource-fail
kind: Pod
status: fail

View file

@ -0,0 +1,23 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: test-multiple-key
spec:
validationFailureAction: enforce
background: false
rules:
- name: test-multiple-key
match:
resources:
kinds:
- Pod
validate:
deny:
conditions:
any:
- key:
- "{{request.object.metadata.labels.app}}"
operator: NotIn
value:
- "busybox"
- "busybox1"

View file

@ -0,0 +1,22 @@
apiVersion: v1
kind: Pod
metadata:
name: test-resource-pass
labels:
app: busybox
spec:
containers:
- name: nginx
image: nginx:latest
---
apiVersion: v1
kind: Pod
metadata:
name: test-resource-fail
labels:
app: busybox-fail
spec:
containers:
- name: nginx
image: nginx:latest