Failed to pull image with x509: certificate signed by unknown authority error when using mirrored registries in OpenShift 4
Environment
- Red Hat OpenShift Container Platform (RHOCP)
- 4
- Disconnected environment
- Mirrored registry
Issue
-
Using a mirrored registry, there are pods in
ImagePullBackOfferror, and the images cannot be pulled with errorFailed to pull imageandx509: certificate signed by unknown authority errorerrors. -
The image pull fails with the following message shown in the events:
Failed to pull image "quay.io/openshift-release-dev/ocp-release@sha256:xxxxxx": rpc error: code = Unknown desc = (Mirrors also failed: custom-image-registry-mirror.example.com:[port]/[namespace]0@sha256:xxxxxx: pinging container registry custom-image-registry-mirror.example.com:[port]: Get "https://custom-image-registry-mirror.example.com:[port]/v2/": x509: certificate signed by unknown authority]): quay.io/openshift-release-dev/ocp-release@sha256:xxxxxx: pinging container registry quay.io: Get "https://quay.io/v2/": dial tcp: lookup quay.io on 10.0.0.1:53: server misbehaving
Resolution
Refer to the documentation for configuring a new mirror registry in the cluster for adding the required CA certificate to allow pulling images from the registry. For additional information, refer to configuring additional trust stores for image registry access.
- Please obtain the certificate from the mirror registry using below command:
# openssl s_client -connect QUAY_HOSTNAME:443 -showcerts 2>/dev/null </dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > mirror-registry-cert.crt
- Create a configmap with the certificate using below command:
$ oc create configmap mirror-registry-ca -n openshift-config --from-file=<registry-url>..<port>=/path/to/mirror-registry-cert.crt
- Modify the image configuration to include the registry and port using below command:
$ oc patch image.config.openshift.io/cluster --patch '{"spec":{"additionalTrustedCA":{"name":"mirror-registry-ca"}}}' --type=merge
IMPORTANT: If the image registry is using a custom port, the key in the
configmapfor the CA needs to be set with..instead of:as explained in above documents:[mirror_address_host]..[port](like for examplecustom-image-registry-mirror.example.com..8443).
If the CA is not added to the nodes after following the steps in the documentation, please refer to: A registry CA is not added/renewed into nodes when adding it as additionalTrustedCA to the image configuration in OpenShift 4.
Root Cause
A disconnected environment needs a mirror image registry to be set up. In case the mirror image registry needs to be reconfigured, or additional one needs to be added, it is needed to:
- Add the mirror registry credentials to the global pull secret.
- Add the CA-signed mirror registry server certificate to the
image.configresource. - Create an
ImageContentSourcePolicycustom resource (ICSP), which associates the mirror registry with the source registry.
Diagnostic Steps
-
For
podsfailing withImagePullBackOfferror, check theeventsof thepod, or for thenamespacewhere it is failing:$ oc get pods -A -o wide | grep ImagePullBackOff [...] $ oc get events -n [namespace_name] [...] 94m Warning Failed pod/[pod_name] Failed to pull image "quay.io/openshift-release-dev/ocp-release@sha256:xxxxxx": rpc error: code = Unknown desc = (Mirrors also failed: custom-image-registry-mirror.example.com:[port]/[namespace]0@sha256:xxxxxx: pinging container registry custom-image-registry-mirror.example.com:[port]: Get "https://custom-image-registry-mirror.example.com:[port]/v2/": x509: certificate signed by unknown authority]): quay.io/openshift-release-dev/ocp-release@sha256:xxxxxx: pinging container registry quay.io: Get "https://quay.io/v2/": dial tcp: lookup quay.io on 10.0.0.1:53: server misbehaving -
Check if the same error is shown trying to pull the image from a node following the steps in manual podman pull fails within OCP 4 nodes.
-
Check if the
additionalTrustedCAis configured in theimage.configresource, and if the referredconfigmapexists and contains the correct CA certificate:$ oc get image.config cluster -o yaml [...] additionalTrustedCA: name: [configmap_name] [...] $ oc get configmap [configmap_name] -n openshift-config -o yaml [...] -
After creating the
configmapand add theadditionalTrustedCAto theimage.configresource, check that the CA is added to the nodes in a directory inside/etc/docker/certs.d/:$ oc debug node/[node_name] [...] sh-4.4# chroot /host bash [root@node_name /]# ls -ltrh /etc/docker/certs.d/ [root@node_name /]# ls -ltrh /etc/docker/certs.d/[mirror_address_host]:[port]/ -
With the CA in the right place in the nodes, check again to manually pull manually pull the images as explained in: manual podman pull fails within OCP 4 nodes.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.