kyverno: [BUG] Mutating `image` with custom JMESPath function `regex_replace_all` overwrites all instances
Software version numbers State the version numbers of applications involved in the bug.
- Kubernetes version: v1.21.3+k3s1
- Kyverno version: v1.4.2-rc3
Describe the bug When using a mutate rule with regex_replace_all on a Pod with multiple containers, the mutated image name of the first container’s image is used to overwrite all subsequent container images.
To Reproduce Steps to reproduce the behavior:
- Apply the sample policy here.
- Apply this Pod definition with two containers.
apiVersion: v1
kind: Pod
metadata:
annotations:
annotation.corp.com/restrict1: foo1
labels:
app: busybox
name: mypod
spec:
automountServiceAccountToken: false
containers:
- name: nginx
image: ghcr.io/nginx:1.28
- name: busybox
image: quay.io/busybox:1.1241
- See the mutation occur successfully in the logs and check the result.
- See the result:
$ k get po mypod -o yaml | yq e .spec.containers[].image -
myregistry.corp.com/nginx:1.28
myregistry.corp.com/nginx:1.28
- Notice that both images in the Pod were replaced with the same mutated image name rather than just the first.
Expected behavior Each image is mutated independently given the field’s original input.
Screenshots If applicable, add screenshots to help explain your problem.
Additional context This was initially described in this Slack thread and further fleshed out here. The first thread links to https://github.com/kyverno/kyverno/issues/2028 as the description but it’s not applicable.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 26 (22 by maintainers)
@realshuting. I think I know where to look to fix the issue, so my high level estimate is half a day.
@sjentzsch @chipzoller Good to know. I’m closing the issue . Please feel free to reopen if you face any other issue regarding this. Thanks.
@sjentzsch can you please test with following image: vyankatesh/kyverno:foreach-initcontainer
result.yaml