Openshift: Error pulling image from remote, secure docker registry using certificates

1/27/2017

I use the all-in-one VM of Openshift origin. I am trying to pull images from a private, secure registry using an Image Stream. This is the ImageStream definition:

apiVersion: v1                                                                          
kind: ImageStream                                                                       
metadata:                                                                               
  name: my-image-stream                                                                    
  annotations:                                                                          
    description: Keeps track of changes in the application image                        
  name: my-image                                                              
spec:                                                                                   
  dockerImageRepository: "my.registry.net/myproject/my-image"

The repository is secured with a certificate. On my local machine, i have them in /etc/docker/certs.d/my.registry.net and I can login with docker login my.registry.net.

When I run oc import-image, however, I get the following error:

The import completed with errors.                                                    

Name:                       my-image                                                    
Namespace:          myproject                                                           
Created:            About an hour ago                                                   
Labels:                     <none>                                                      
Description:                Keeps track of changes in the application image             
Annotations:                openshift.io/image.dockerRepositoryCheck=2017-01-27T08:09:49Z
Docker Pull Spec:   172.30.53.244:5000/myproject/my-image                               
Unique Images:              0                                                           
Tags:                       1                                                           

latest                                                                                  
  tagged from my.registry.net/myproject/my-image                                        

    ! error: Import failed (InternalError): Internal error occurred: Get https://my.registry.net/v2/: remote error: handshake failure
          About an hour ago                                                             

I have copied the certificates to the vagrant machine and restarted the docker daemon, but the problem remains. I have not found any documentation on how to properly add the certificates, so I just put them in the usual docker folder.

What is the appropriate way to make this work?

Update in response to rezie's answer:

There is no file etc/origin/master/ca-bundle.crt on my vagrant box. I found the following ca-bundle.crt files :

$ find / -iname ca-bundle.crt
/etc/pki/tls/certs/ca-bundle.crt
##multiple lines like
/var/lib/docker/devicemapper/mnt/something-hash-like/rootfs/etc/pki/tls/certs/ca-bundle.crt
/var/lib/origin/openshift.local.config/master/ca-bundle.crt

I appended the root certificate to /etc/pki/tls/certs/ca-bundle.crt and to var/lib/origin/openshift.local.config/master/ca-bundle.crt, but that did not change anything. Please note, however, that I do not need to have this root certificate in /etc/docker/certs.d/... in order to login directly using docker login my.registry.net

I have appended

-- feob
docker-registry
kubernetes
openshift
openshift-origin

2 Answers

1/28/2017

Try appending your CA (the same one you said you said that was used in the my.registry.net directory) into Openshift's ca bundle (e.g. /etc/origin/master/ca-bundle.crt. Then restart the service and reattempt import-image (making sure that you do not include the --insecure flag).

For reference, check out this issue from the Origin project. As you've mentioned, there's currently no way to supply certificates along with the dockercfg secret, and the suggestion from that issue is to add the CA as a trusted root CA across all the hosts.

-- rezie
Source: StackOverflow

2/8/2017

I cannot comment due tow lo karma so I'll write an answer saying almost the same as rezie.

The error:

! error: Import failed (InternalError): Internal error occurred: Get https://my.registry.net/v2/: remote error: handshake failure
      About an hour ago                                                             

Comes from OpenShift, not from docker, therefore adding it to /etc/docker/certs.d/my.registry.net doesn't prevent the error from happening.

You should add the CA certificate at OS level, my guess is the steps failed for some reason so do it this way:

openssl s_client -connect my.registry.net:443 </dev/null |
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' \
> /etc/pki/ca-trust/source/anchors/my.registry.net.crt &&
update-ca-trust check && update-ca-trust extract

Finally test if it worked running

curl https://my.registry.net/v2

If it doesn't give you a certificate error and you still can't do the oc import restart the atomic-openshift-master-api service

-- Juan Luis de Sousa Valadas
Source: StackOverflow