kyverno: [Bug] Incorrect NetworkPolicy causes Kyverno to remove its own webhook config

Following steps below, a NetworkPolicy which results in comms between Kyverno and the API server causes Kyverno to remove its own webhook rule from resource validating webhooks which results in resources bypassing validations.

Kyverno 1.10.1

To reproduce, please try this:

  1. Deploy kyverno with the helm chart v3.0.2 and this config (so calls from api-server are blocked)
      admissionController: 
        networkPolicy:
          enabled: true
          ingressFrom:
            - namespaceSelector:
                matchLabels:
                  kubernetes.io/metadata.name: monitoring
              podSelector:
                matchLabels:
                  app: prometheus
    
  2. Restart admission-controller (not sure if required)
  3. Create some admission request (pod creation, this one should fail)
  4. Wait max 10min (sorry, couldn’t nail it down further yet).
  5. The webhook should be removed from the validatingwebhookconfiguration by now and the subsequent admission requests are passing

_Originally posted by @wiegandf in https://github.com/kyverno/kyverno/issues/6554#issuecomment-1642024960_

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

Hi @realshuting, sorry for the long time without reply. I have overlooked your question and we also didn’t face this issue anymore.

Until recently, when we had some network issues and the webhook was deleted from the validatingwebhookconfiguration.

I was able to reproduce with the steps outlined in https://github.com/kyverno/kyverno/issues/7852#issue-1811889710.

I noticed that you’re deploying a new Networkpolicy that denies Egress traffic - so kyverno is also not able to update the validatingwebhookconfiguration. Could you try to install kyverno with the helm chart and the snippet from the steps above?

After restarting, all validatingwebhookconfigurations are correct:

kg validatingwebhookconfiguration
NAME                                           WEBHOOKS   AGE
...
kyverno-exception-validating-webhook-cfg       1          208d
kyverno-policy-validating-webhook-cfg          1          208d
kyverno-resource-validating-webhook-cfg        1          208d

A new resource should now be denied to be created because of a timeout:

kubectl create ingress kyverno-smoke-test --rule='example.com/test=test:8080'

error: failed to create ingress: Internal error occurred: failed calling webhook "validate.kyverno.svc-fail": failed to call webhook: Post "https://kyverno-svc.kyverno.svc:443/validate/fail?timeout=10s": context deadline exceeded

So now, it’s important to wait some time - I guess kyverno is reconciling after some time? Anyway, after let’s say maximum 5-10mins, it should look like:

kg validatingwebhookconfiguration
NAME                                           WEBHOOKS   AGE
...
kyverno-exception-validating-webhook-cfg       1          208d
kyverno-policy-validating-webhook-cfg          1          208d
kyverno-resource-validating-webhook-cfg        0          208d

Please note that kyverno-resource-validating-webhook-cfg is now missing the webhook.