docker-py does not work respect TLS docker options (fails to connect)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
Configuring docker to talk over TLS involves 3 environment variables and it seems that docker-py library chokes when it cannot verify the TLS certificates, even if docker works correct, as expected.
This is because DOCKER_TLS variable tells docker to use TLS and to ignore TLS verification. If user wants to enforce TLS validation he must define DOCKER_TLS_VERIFY variable.
The library fails to do this because it used python requests which has verify=True by default.
This is very easy to reproduce
export DOCKER_HOST=tcp://1.2.3.4:2376
export DOCKER_TLS=1
python -c "import docker; docker.from_env().ping()"
This will raise an exception similar to:
Traceback (most recent call last):
File "./py-docker", line 8, in <module>
c.ping()
File "/Users/ssbarnea/os/docker-py/docker/client.py", line 187, in ping
return self.api.ping(*args, **kwargs)
File "/Users/ssbarnea/os/docker-py/docker/api/daemon.py", line 166, in ping
return self._result(self._get(self._url('/_ping'))) == 'OK'
File "/Users/ssbarnea/os/docker-py/docker/utils/decorators.py", line 46, in inner
return f(self, *args, **kwargs)
File "/Users/ssbarnea/os/docker-py/docker/api/client.py", line 225, in _get
return self.get(url, **self._set_request_timeout(kwargs))
File "/Users/ssbarnea/.pyenv/versions/2.7.15/lib/python2.7/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/Users/ssbarnea/.pyenv/versions/2.7.15/lib/python2.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/ssbarnea/.pyenv/versions/2.7.15/lib/python2.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/ssbarnea/.pyenv/versions/2.7.15/lib/python2.7/site-packages/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='1.2.3.4', port=2376): Max retries exceeded with url: /v1.35/_ping (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in docker/client.py and follow the request path through docker/api/client.py and docker/api/daemon.py, then reproduce the failure with the DOCKER_HOST and DOCKER_TLS environment variables shown. Done means docker.from_env().ping() connects when TLS verification is not requested, while DOCKER_TLS_VERIFY continues to enforce certificate validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- backend, security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100