Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zulhfreelancer/36d451b172637c3f4df32c63fb2d2244 to your computer and use it in GitHub Desktop.
Save zulhfreelancer/36d451b172637c3f4df32c63fb2d2244 to your computer and use it in GitHub Desktop.
How to fix Nginx ingress controller "certificate signed by unknown authority" error?

Problem

How to fix Nginx ingress controller "certificate signed by unknown authority" error?

Error:

"Internal error occurred: failed calling webhook \"validate.nginx.ingress.kubernetes.io\": failed to call webhook: Post \"https://nginx-ingress-ingress-nginx-controller-admission.default.svc:443/networking/v1/ingresses?timeout=10s\": x509: certificate signed by unknown authority"

Solution

  1. Compare the CA stored in ValidatingWebhookConfiguration vs in the secret where the *nginx-controller* pods are running

    In this case, the *nginx-controller* pods are in default namespace - yours may be in different namespace

    $ k get ValidatingWebhookConfiguration nginx-ingress-ingress-nginx-admission -o jsonpath='{.webhooks[0].clientConfig.caBundle}' | md5
    d41d8cd98f00b204e9800998ecf8427e
    
    $ k -n default get secret nginx-ingress-ingress-nginx-admission -o jsonpath='{.data.ca}' | md5
    bbf6ef16566994f9f65facc7e8f07b16
  2. It's clear that they are not same because the MD5 hashes are different. Let's fix this...

  3. Copy the CA from the secret where the *nginx-controller* pods are running

    In this case, the *nginx-controller* pods are in default namespace - yours may be in different namespace

    $ CA=$(kubectl -n default get secret nginx-ingress-ingress-nginx-admission -o jsonpath='{.data.ca}')
  4. Patch the ValidatingWebhookConfiguration

    $ kubectl patch validatingwebhookconfigurations nginx-ingress-ingress-nginx-admission --type='json' -p='[{"op": "add", "path": "/webhooks/0/clientConfig/caBundle", "value":"'$CA'"}]'
  5. Repeat step 1 and make sure both MD5 hashes are same

    $ k get ValidatingWebhookConfiguration nginx-ingress-ingress-nginx-admission -o jsonpath='{.webhooks[0].clientConfig.caBundle}' | md5
    bbf6ef16566994f9f65facc7e8f07b16
    
    $ k -n default get secret nginx-ingress-ingress-nginx-admission -o jsonpath='{.data.ca}' | md5
    bbf6ef16566994f9f65facc7e8f07b16
@DovydasNavickas
Copy link

For k3s clusters

Checking

# Validating webhook CA
k get validatingwebhookconfigurations ingress-nginx-admission -o jsonpath='{.webhooks[0].clientConfig.caBundle}' | md5sum

# CA in secret
k get secrets -n ingress-nginx ingress-nginx-admission -o jsonpath='{.data.ca}'

Fixing

CA=$(k get secrets -n ingress-nginx ingress-nginx-admission -o jsonpath='{.data.ca}')
k patch validatingwebhookconfigurations ingress-nginx-admission --type='json' -p='[{"op": "add", "path": "/webhooks/0/clientConfig/caBundle", "value":"'$CA'"}]'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment