machine icon indicating copy to clipboard operation
machine copied to clipboard

Recommended way to install CA certificate on local VM docker machine

Open vpusher opened this issue 11 years ago • 34 comments

Commonly, company's root CA certificate are installed by IT on developpers machines and servers (They not come with the OS). When using docker machine with local VMs (virtualbox), do we need to install the company root CA certificate on the VM to talk with a docker registry hosted on the company's network ?

I'm wondering what is the recommanded way to install CA certificate on my local VM? Seems to be a beginning of answer here but nothing convincing/proper.

And if there are intermediate company CAs, what's the recommended way ? Bundle all the certs ?

vpusher avatar Sep 03 '15 09:09 vpusher

I'd also like to know this. I've followed the procedure (https://docs.docker.com/articles/https/) to create a new CA and certificates. I've tried putting files /var/lib/boot2docker and /var/lib/boot2docker/tls but having trouble with the /etc/init.d/docker start script overwriting the certificate I've generated.

oobles avatar Sep 04 '15 11:09 oobles

I've looked into this a bit more and it looks like docker-machine will overwrite anything in the host .docker/machines/machine/default with certificates it generates. It also replaces files in the boot2docker vm in /var/lib/boot2docker. It is possible to login and replace files in the vm and update /var/lib/boot2docker/profile but this is also replaced on startup (not sure by what, but possibly by 'docker-machine env default').

oobles avatar Sep 04 '15 13:09 oobles

@oobles you should be able to use the --tls-ca-cert, --tls-cert and --tls-key options to specify existing certificates.

ehazlett avatar Sep 11 '15 17:09 ehazlett

When using docker-machine --tls-ca-cert=my_company_ca.pem create --driver virtualbox vm, the command fails into:

Error creating machine: error generating server cert: crypto/tls: private key does not match public key

The point here (and I guess in most companies) is i can't give the --tls-ca-key option because I do not manage the company CA, so I do not know the private key.

What am i missing here ? Are those options only usefull for people managing their own CA, signing their own certifcates ?

I just want my docker client (on my VM) to docker login onto our company registry which shows a certifcate signed by the company CA.

Any help ?

vpusher avatar Sep 16 '15 15:09 vpusher

Same problem here any improvements?

kakawait avatar Sep 28 '15 07:09 kakawait

+1. Same problem in our organisation.

smiler avatar Dec 01 '15 15:12 smiler

The way I work around the situation was: On the Registry Server:

  1. create the self signed certificates as state in the docker documentation.
  2. create a .pem file concatenating the key and cert file

On the Docker Machine:

  1. copy via scp the pem file to your [email protected]:/home/docker
  2. via ssh [email protected] (password: tcuser) move the pem file to: /var/lib/boot2docker/certs/
  3. Restart Docker machine

cesarhernandezgt avatar Dec 01 '15 18:12 cesarhernandezgt

My containers builds hit unable to find valid certification when downloading from https connection. My company uses an intermediate ZScaler CA root cert & also uses a PAC file to automatically configure the proxy.

dkirrane avatar Mar 31 '16 10:03 dkirrane

+1 on this. If it was possible to re-use existing CA (cert and key) and client certificates (cert and key) it really should be possible to re-use existing TLS infrastructure when deploying certificates to docker engine with docker-machine, e.g.

  • --tls-server-cert
  • --tls-server-key
docker-machine create -d ... \
  --tls-ca-cert cacert.pem \
  --tls-ca-key cacert.key \
  --tls-client-cert local_user.pem \
  --tls-client-key local_user.key \
  --tls-server-cert server.pem \
  --tls-server-key server.key

Error creating machine: Error running provisioning: error generating server cert: crypto/tls: failed to parse private key kicks in for me because cacert.key is password protected.

ghost avatar Apr 25 '16 12:04 ghost

+1

danielwhatmuff avatar Apr 28 '16 00:04 danielwhatmuff

👍 , as this is a major blocker for us. Our enterprise IT organization puts a custom HTTPS cert on all requests going from inside our corporate firewall to the public internet, so we cannot even contact docker hub for containers without being able to configure these certs correctly.

wadetandy avatar May 16 '16 17:05 wadetandy

Has anybody found a solution to this yet? Our enterprise IT does a MitM to replace all HTTPS certs.

When I tried... docker-machine --tls-ca-cert root.cer create --driver virtualbox default it throws the following error

Error creating machine: Error running provisioning: error generating server cert: crypto/tls: private key does not match public key

reustonium avatar Aug 11 '16 14:08 reustonium

I ended up skipping the tls cert at machine creation time. Once creating the machine:

docker-machine scp certfile default:ca.crt docker-machine ssh default sudo mv ~/ca.crt /etc/docker/certs.d/docker.io/ca.crt

Then it should work. You may have to mkdir the subdirectories before the mv command. Substitute docker.io for an internal registry host if necessary.

On Thursday, August 11, 2016, Andy Ruestow [email protected] wrote:

Has anybody found a solution to this yet? Our enterprise IT does a MitM to replace all HTTPS certs.

When I tried... docker-machine --tls-ca-cert root.cer create --driver virtualbox default it throws the following error

Error creating machine: Error running provisioning: error generating server cert: crypto/tls: private key does not match public key

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/docker/machine/issues/1799#issuecomment-239175647, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJD9p1tfX97V_OW4DgJkzxP86URi-C5ks5qezAsgaJpZM4F3GTM .

wadetandy avatar Aug 12 '16 02:08 wadetandy

+ 1 GE is using Zscaler and doing MitM cert mangling and docker is un-usable from all of our developer machines right now.

rpomeroy avatar Nov 29 '16 22:11 rpomeroy

+1, trying to solve this right now too.

ecottd avatar Dec 07 '16 16:12 ecottd

+1, also trying to solve this in a corporate environment

Ettery avatar Dec 21 '16 14:12 Ettery

+1 also corporate environment, proxy does MitM cert mangling. Need a way to install certs.

mikehaller avatar Jan 11 '17 07:01 mikehaller

This took a lot of digging and the solution is embarrassingly simple (but not obvious). And there are a couple things to note. The answer was here - but you have to read past the code section to the alternative approach.

Basically, copy pem (Base64 encoded) versions of your CA trust chain into /var/lib/boot2docker/certs/. You can't use ca bundles. The boot2docker boot script will automatically pick up pem files there and add them to the ssl config. Also, this is a special directory and will be preserved across restarts.

$ docker-machine ssh default 'sudo mkdir /var/lib/boot2docker/certs'
$ docker-machine scp corp-ca.pem default:
$ docker-machine ssh default 'sudo mv corp-ca.pem /var/lib/boot2docker/certs/'
$ docker-machine restart default 

This should be simpler so I support (#1799). Furthermore, we should be able to specify a directory full of pem files so adding multiple certs (as in whole trust chains) is easy.

rpomeroy avatar Jan 13 '17 22:01 rpomeroy

@rpomeroy thanks a lot, I was doing all the same but didn't know that VM restart was needed and due to that was copying the certificate all over the place to make it work

mlushpenko avatar Mar 03 '17 15:03 mlushpenko

Any fix for Docker for Windows

dkirrane avatar Jul 18 '17 09:07 dkirrane