-
Notifications
You must be signed in to change notification settings - Fork 952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] automatically escape -
within strings for JMESPath
#4206
Comments
This might be relevant as well: jmespath/go-jmespath#58 @chipzoller as stated here, we can add this workaround jmespath/go-jmespath#58 (comment) until it it fixed in the go-jmespath library itself |
Could we still add this? |
@chipzoller We can either
What is the best approach here? |
Are we using Kyverno's fork of go-jmespath currently? If so, I would do 3 and then 2. If we're using upstream go-jmespath currently, I would do 1 and then 2. |
/assign |
This get compiled as well key: "{{ \"image-data\".{{element}} }}"
key: "{{ \"image-data\".user }}" This get compiled but the key does not get resolved key: "{{ \"image-data.user\" }}" Discussion in jmespath/jmespath.py#109 (comment) suggests that this is by design
Is it worth changing this, if it is in the jmespath specification? We can put the key in hyphens in quotes like apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: check-trustable-images
spec:
validationFailureAction: Enforce
rules:
- name: only-allow-trusted-images
match:
any:
- resources:
kinds:
- Pod
preconditions:
- key: "{{request.operation}}"
operator: NotEquals
value: DELETE
validate:
message: "images with root user are not allowed"
foreach:
- list: "request.object.spec.containers"
context:
- name: image-data
imageRegistry:
reference: "{{ element.image }}"
jmesPath: "{user: configData.config.User || '', registry: registry}"
deny:
conditions:
all:
- key: "{{ \"image-data\".user }}"
operator: Equals
value: ""
- key: "{{ \"image-data\".{{element}} }}"
operator: NotEquals
value: "ghcr.io"
|
It would just be easier this way and to always do it: deny:
conditions:
all:
- key: '{{ "image-data".{{element}} }}'
operator: NotEquals
value: ghcr.io |
Kyverno Version
1.7.2
Description
JMESPath does not allow a
-
in an expression. See: jmespath/jmespath.py#109However, JSON keys (especially for Kubernetes resource names, etc.) commonly have dashes.
This requires all usage of such strings to be quoted:
This does not work:
"{{ my-map.data.{{image.name}} }}"
(image.name resolves to a string with a
-
)This works:
"{{ \"my-\".data.\"{{image.name}}\" }}"
It would be good if Kyverno can automatically quote any string with a
-
in it.Slack discussion
No response
Troubleshooting
The text was updated successfully, but these errors were encountered: