kyverno: [Bug] Segmentation fault in admission controller 1.13
Kyverno Version
1.13.0
Kubernetes Version
1.28.x
Kubernetes Platform
Other (specify in description)
Kyverno Rule Type
Validate
Description
After upgrading to Kyverno 1.13 (Helm chart v3.3.0), the admission controller panics when trying to iterate over a list that is not defined in the resource being validated.
Steps to reproduce
- Define validating policy trying to iterate over an optional list:
apiVersion: kyverno.io/v1 kind: ClusterPolicy metadata: name: restrict-storageclasses-by-namespace-annotation spec: validationFailureAction: Enforce background: false rules: - name: restrict-storageclasses-on-statefulset match: any: - resources: kinds: [StatefulSet] operations: [CREATE, UPDATE] context: - name: allowedStorageClasses apiCall: urlPath: /api/v1/namespaces/{{ request.namespace }} jmesPath: >- split((metadata.annotations."storage/allowed-storageclasses" || ''), ',') validate: message: >- Attempt use of storageclass that is forbidden in this namespace. Please annotate the namespace as needed if this storageclass is required. foreach: - list: request.object.spec.volumeClaimTemplates # <-------- this might not always be defined deny: conditions: any: - key: "{{ element.spec.storageClassName }}" operator: NotIn value: "{{ allowedStorageClasses }}" - Create a resource without the target field, in this case a
StatefulSetwithout.spec.volumeClaimTemplatesdefined
Expected behavior
Up to v1.12, if the key provided in foreach.list does not exist in the validated resource, Kyverno just skips the loop altogether (and thus does not deny the resource in this case), so it basically treats an undefined list just like an empty list.
One could also argue that it should be explicitly stated that only resources having the field defined should be evaluated. E.g. with a precondition or can we express this more elegantly in the foreach.list JMESPath expression?
Anyway, this behavior seems to have changed and it should clearly not lead to panicking admission controllers.
Screenshots
No response
Kyverno logs
2024-10-30T10:07:08Z TRC github.com/kyverno/kyverno/pkg/engine/handlers/validation/validate_resource.go:215 > failed to evaluate list error="JMESPath query failed: Unknown key \"volumeClaimTemplates\" in path" list=request.object.spec.volumeClaimTemplates logger=engine.validate new.kind=StatefulSet new.name=recruit-pg-00-jsdq new.namespace=recruit old.kind=StatefulSet old.name=recruit-pg-00-jsdq old.namespace=recruit policy.apply=All policy.name=restrict-storageclasses-by-namespace-annotation policy.namespace= rule.name=restrict-storageclasses-on-statefulset v=2
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x3521db6]
Slack discussion
No response
Troubleshooting
- I have read and followed the documentation AND the troubleshooting guide.
- I have searched other issues in this repository and mine is not recorded.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 21 (9 by maintainers)
spoke too soon, problem still happens
Thank you @realshuting. Unfortunately, the error still persists with
ghcr.io/kyverno/kyverno:v1.13.1-rc.1:Thanks @bauerjs1 for digging into it! I added it to 1.13.1, we will investigate further and fix the issue.
Running into the same issue.