0

I am trying to follow the instructions on https://learn.microsoft.com/en-us/azure/aks/tutorial-kubernetes-prepare-app. My woes start right away with the docker-compose up -d command:

...
Status: Downloaded newer image for tiangolo/uwsgi-nginx-flask:python3.6
 ---> a16ce562e863
Step 2/3 : RUN pip install redis
 ---> Running in ffef7d7a575f
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/redis/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/redis/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/redis/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/redis/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/redis/
Could not fetch URL https://pypi.org/simple/redis/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/redis/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)) - skipping
ERROR: Could not find a version that satisfies the requirement redis (from versions: none)
ERROR: No matching distribution found for redis
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)) - skipping
ERROR: Service 'azure-vote-front' failed to build: The command '/bin/sh -c pip install redis' returned a non-zero code: 1
C:\work\azure-voting-app-redis [master ≡]>

Now I think I know what is the problem - some certificates are missing from the docker trust chain (not sure what is the right terminology here).

I have already faced this problem in the past when I tried to run an Azure DevOps build agent in a docker container. I have identified the two certificates that were missing, saved them and worked around the problem by:

  1. Copying the certificates into the docker image
  2. Running the command to import them as the very first thing.
Get-ChildItem /certificates | ForEach-Object {
    $null = Import-Certificate -FilePath $_.FullName -CertStoreLocation Cert:\LocalMachine\Root
}

But that was easy because the base image was mcr.microsoft.com/windows/servercore:ltsc2019

In the tutorial above the Dockerfile is:

FROM tiangolo/uwsgi-nginx-flask:python3.6
RUN pip install redis
ADD /azure-vote /app 

And this is a Linux image - no idea how to configure the certificates there.

So, given that I think I know what certificates are missing, how do I configure them in that docker container?

EDIT 1

To figure out the right procedure I have run the docker image interactively:

docker run  --mount 'type=bind,source=c:\work\azure-voting-app-redis\azure-vote\ca-certs,target=/ca-certs' -it tiangolo/uwsgi-nginx-flask:python3.6 bash

This opens bash from the docker container with /ca-certs containing the two pem files corresponding to my missing certificates. Next, I installed the ca-certificates package:

root@8f64c6b3381c:/app# apt-get update -y
Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:2 http://deb.debian.org/debian buster InRelease [122 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:4 http://security.debian.org/debian-security buster/updates/main amd64 Packages [226 kB]
Get:5 http://deb.debian.org/debian buster/main amd64 Packages [7906 kB]
Get:6 http://deb.debian.org/debian buster-updates/main amd64 Packages [7868 B]
Fetched 8380 kB in 2s (5123 kB/s)
Reading package lists... Done
root@8f64c6b3381c:/app# apt-get install ca-certificates -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  openssl
The following NEW packages will be installed:
  ca-certificates openssl
0 upgraded, 2 newly installed, 0 to remove and 48 not upgraded.
Need to get 1002 kB of archives.
After this operation, 1885 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian buster/main amd64 openssl amd64 1.1.1d-0+deb10u3 [844 kB]
Get:2 http://deb.debian.org/debian buster-updates/main amd64 ca-certificates all 20200601~deb10u1 [158 kB]
Fetched 1002 kB in 0s (3682 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package openssl.
(Reading database ... 24611 files and directories currently installed.)
Preparing to unpack .../openssl_1.1.1d-0+deb10u3_amd64.deb ...
Unpacking openssl (1.1.1d-0+deb10u3) ...
Selecting previously unselected package ca-certificates.
Preparing to unpack .../ca-certificates_20200601~deb10u1_all.deb ...
Unpacking ca-certificates (20200601~deb10u1) ...
Setting up openssl (1.1.1d-0+deb10u3) ...
Setting up ca-certificates (20200601~deb10u1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
Updating certificates in /etc/ssl/certs...
126 added, 0 removed; done.
Processing triggers for ca-certificates (20200601~deb10u1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
root@8f64c6b3381c:/app#

Now I wonder if I can proceed with the pem files? The /etc/ssl/certs directory contains both pem and crt files. How do I add a CA root certificate inside a docker image? suggests I must convert pem to crt. I am going to try it, but I prefer avoid any conversions, if possible.

mark
  • 59,016
  • 79
  • 296
  • 580
  • It might be easier to slightly modify their Dockerfile on this line: https://github.com/Azure-Samples/azure-voting-app-redis/blob/master/azure-vote/Dockerfile#L2 and change it to include this sort of thing `--trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org` https://stackoverflow.com/questions/56131677/run-pip-install-there-was-a-problem-confirming-the-ssl-certificate-ssl-certi – Howard_Roark Sep 14 '20 at 23:11
  • This totally works. Even though it does not answer my question, it does unblock me. Still I am curious what is the right way to install the certificates. – mark Sep 15 '20 at 00:41
  • It is very weird that you’re running into that error. It’s not like this is some obscure self signed cert — it would be surprising if their base image doesn’t have it. Especially considering it looks like lots of people use this project— someone would have raised an issue I would think. On the host itself if you pip install redis does it work? – Howard_Roark Sep 15 '20 at 00:54
  • We have ZScaler installed. All the outgoing traffic from the workstation goes through it. What missing is the zscaler root certificate. In addition, the digicert CA certificate is needed. So, all in all 2 certificates. I do not know about digicert, but zscaler is not something installed out of the box, so it makes sense a fresh new container does not have it. As I have mentioned, this is not the first time. I faced the same issue when tried to run Azure DevOps agent in a docker. – mark Sep 15 '20 at 01:10
  • Oh gotcha I would just include the cert chains as you’re describing in your edit. I’ll :disappear: now though as I know you were looking for a potentially better way – Howard_Roark Sep 15 '20 at 01:23
  • I do not think registering the certificates is the better way in this particular context. I am just curious how to register them properly. Trusting python sites is perfectly legit in my eyes. – mark Sep 15 '20 at 01:28

0 Answers0