Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL verification on python2.7 failing #36

Closed
sebgoa opened this issue Nov 23, 2016 · 22 comments · Fixed by #43
Closed

SSL verification on python2.7 failing #36

sebgoa opened this issue Nov 23, 2016 · 22 comments · Fixed by #43

Comments

@sebgoa
Copy link
Contributor

sebgoa commented Nov 23, 2016

I saw a commit flying by that said this was fixed but I get:

>>> import os
>>> config.load_kube_config(os.environ["HOME"] + '/.kube/config')
>>> v1=client.CoreV1Api()
>>> ret = v1.list_pod_for_all_namespaces(watch=False)
2016-11-23 10:26:29,195 ERROR Certificate did not match expected hostname: 192.168.99.100. Certificate: {'subjectAltName': (('DNS', 'kubernetes.default.svc.cluster.local'), ('DNS', 'kubernetes.default.svc'), ('DNS', 'kubernetes.default'), ('DNS', 'kubernetes'), ('IP Address', '192.168.99.100'), ('IP Address', '10.0.0.1')), 'notBefore': u'Nov 16 09:38:49 2016 GMT', 'serialNumber': u'02', 'notAfter': 'Nov 16 09:38:49 2017 GMT', 'version': 3L, 'subject': ((('commonName', u'minikube'),),), 'issuer': ((('commonName', u'minikubeCA'),),)}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "kubernetes/client/apis/core_v1_api.py", line 14377, in list_pod_for_all_namespaces
    (data) = self.list_pod_for_all_namespaces_with_http_info(**kwargs)
  File "kubernetes/client/apis/core_v1_api.py", line 14475, in list_pod_for_all_namespaces_with_http_info
    collection_formats=collection_formats)
  File "kubernetes/client/api_client.py", line 326, in call_api
    _return_http_data_only, collection_formats, _preload_content, _request_timeout)
  File "kubernetes/client/api_client.py", line 150, in __call_api
    _request_timeout=_request_timeout)
  File "kubernetes/client/api_client.py", line 349, in request
    headers=headers)
  File "kubernetes/client/rest.py", line 222, in GET
    query_params=query_params)
  File "kubernetes/client/rest.py", line 199, in request
    raise ApiException(status=0, reason=msg)
kubernetes.client.rest.ApiException: (0)
Reason: SSLError
hostname '192.168.99.100' doesn't match either of 'kubernetes.default.svc.cluster.local', 'kubernetes.default.svc', 'kubernetes.default', 'kubernetes', '192.168.99.100', '10.0.0.1'
@sebgoa
Copy link
Contributor Author

sebgoa commented Nov 23, 2016

it does work with python3.5

@sebgoa sebgoa mentioned this issue Nov 23, 2016
4 tasks
@mbohlool
Copy link
Contributor

mbohlool commented Nov 23, 2016

are you using latest urllib3? can you run setup.py install and try this again or try to manually update urllib3.

pip show urllib3
Name: urllib3
Version: 1.19.1
Summary: HTTP library with thread-safe connection pooling, file post, and more.

Also what is your python version?

$ python --version
Python 2.7.12

@mbohlool
Copy link
Contributor

I figured this out. We had a patch that we removed because urllib3 is already doing the patch, however it only does that if package "ipaddress" is installed. I added that as a dependency so we should be good.

@mbohlool mbohlool reopened this Nov 23, 2016
@mbohlool
Copy link
Contributor

@sebgoa
Copy link
Contributor Author

sebgoa commented Nov 24, 2016

ok confirmed that it solved the issue.

@madhavmalhotra3089
Copy link

Still not working for python 2.x windows 10

@mbohlool
Copy link
Contributor

@madhavmalhotra3089
Copy link

madhavmalhotra3089 commented May 28, 2017 via email

@tahir24434
Copy link

Hi,
I followed the instructions described in this thread and I am still hitting the issue.

Exception when calling CoreV1Api->connect_post_namespaced_pod_exec: (0)
Reason: hostname '1.0.0.14' doesn't match either of 'minion-1-0-0-14', 'kubernetes', 'kubernetes.default', 'kubernetes.default.svc', 'kubernetes.default.svc.cluster.local'

I have following versions of packages

python --version
Python 2.7.6

pip show ipaddress
Name: ipaddress
Version: 1.0.18
Summary: IPv4/IPv6 manipulation library
Home-page: https://github.com/phihag/ipaddress
Author: Philipp Hagemeister
Author-email: phihag@phihag.de
License: Python Software Foundation License
Location: /usr/local/lib/python2.7/dist-packages
Requires:

pip show urllib3
Name: urllib3
Version: 1.20
Summary: HTTP library with thread-safe connection pooling, file post, and more.
Home-page: https://urllib3.readthedocs.io/
Author: Andrey Petrov
Author-email: andrey.petrov@shazow.net
License: MIT
Location: /usr/local/lib/python2.7/dist-packages
Requires:

Any ideas please?
Regards

@mbohlool
Copy link
Contributor

mbohlool commented Jul 12, 2017

What is your kubernetes package version? what framework this is on? (os, anaconda?, etc.). Also please confirm that kubectl works.

@flavianmissi
Copy link

flavianmissi commented Jul 28, 2017

Same problem here:

$ python --version
Python 2.7.13

$ pip show ipaddress
Name: ipaddress
Version: 1.0.18
Summary: IPv4/IPv6 manipulation library
Home-page: https://github.com/phihag/ipaddress
Author: Philipp Hagemeister
Author-email: phihag@phihag.de
License: Python Software Foundation License
Location: $HOME/my-venv/lib/python2.7/site-packages
Requires:

$ pip show urllib3
Name: urllib3
Version: 1.22
Summary: HTTP library with thread-safe connection pooling, file post, and more.
Home-page: https://urllib3.readthedocs.io/
Author: Andrey Petrov
Author-email: andrey.petrov@shazow.net
License: MIT
Location: $HOME/my-venv/lib/python2.7/site-packages
Requires:

$ pip show kubernetes
Name: kubernetes
Version: 2.0.0
Summary: Kubernetes python client
Home-page: https://github.com/kubernetes-incubator/client-python
Author: Kubernetes
Author-email: UNKNOWN
License: Apache License Version 2.0
Location: /Users/flavia/go/src/mindoktor.io/md-venv/lib/python2.7/site-packages
Requires: websocket-client, ipaddress, setuptools, oauth2client, six, urllib3, pyyaml, python-dateutil, certifi

The actual error looks a little different, though the underlying problem seems exactly the same

c.connect_get_namespaced_pod_exec("podname", "namespace", command="/bin/bash -c 'ls'")
[...]
ApiException: (0)
Reason: hostname 'MY.IPADDR' doesn't match either of 'kubernetes', 'kubernetes.default', 'kubernetes.default.svc', 'kubernetes.default.svc.cluster.local'

Additionally, kubectl works just fine.

@mbohlool
Copy link
Contributor

You are calling exec. We use websocket library for exec. They introduced some bug and we limited the version in the dependency file (requirements.txt). If you search issues for websocket or just make sure you are using compatible websocket version, that should fix your problem.

@flavianmissi
Copy link

flavianmissi commented Jul 31, 2017

Thanks for the info! I have noticed that.
With websocket-client==0.44.0 I get

ApiException: (0)
Reason: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)

The error I posted previously I got using websocket-client==0.40.0 (sorry I missed posting the info for it). Looking at some more examples I found that I needed to stop hostname assertion (doh):

from kubernetes.client import configuration
configuration.assert_hostname = True

After doing that I was able to move forward a bit, but not without another failure. Here's my full code:

from kubernetes.client import configuration
from kubernetes import config
from kubernetes.client.apis import core_v1_api

configuration.assert_hostname = False
config.load_kube_config()
c = core_v1_api.CoreV1Api()
c.connect_get_namespaced_pod_exec("mypod", "namespace", command="/bin/bash -c 'ls'")
# stacktrace...
# ApiException: (0)
# Reason: Handshake status 404

I feel like I'm missing something, appreciate the help!

@flavianmissi
Copy link

BTW I have looked at #144 and updated my snippet (as seen above), and I get the exact same issue there... I have tested on my local machine (OS X, OpenSSL 1.0.2l) and on a VM (Debian OpenSSL 1.0.1t ) both share same requirements versions.

Have also done some debugging and the final url used in the websocket call is wss://my.master.ip/api/v1/namespaces/default/pods/mypod/exec. I've also made sure that mypod actually exists... although I know that 404 is a client error I'm clueless to why this is happening.

@mbohlool
Copy link
Contributor

Interesting. Try kubectl (to call exec on your pod) with -v9 flag to see if it hits the same url. Also what is your cluster running on? GKE? On Prem? AWS? ...

@flavianmissi
Copy link

My cluster is on GKE, master version is 1.5.7, node version 1.4.7.

$ kubectl exec mypod ls -v 9
[...]
https://same.master.ip/api/v1/namespaces/default/pods/mypod/exec

(I've omited query strings on both urls)
So exactly same url, only different protocols.

@mbohlool
Copy link
Contributor

mbohlool commented Jul 31, 2017 via email

@flavianmissi
Copy link

flavianmissi commented Jul 31, 2017

Tried updating it, didn't work...

But I found the issue somewhere else, the problem is on websocket_call:

query_params = [(key, value) for key, value in query_params if
                    key != 'command']

query_params value before the above line is [('command', 'ls')], after it, query_params is empty, and that's where my problem starts. If I don't explicitly give other arguments to connect_get_namespaced_pod_exec (like stdout or stderr), the url building will be inconsistent, my resulting url is /api/v1/namespaces/default/pods/mypod/exec&command=ls, note the lack of ? in the beginning of the query string. So giving connect_get_namespaced_pod_exec actually builds a correctly formed url, e.g: /api/v1/namespaces/default/pods/mypod/exec?stderr=True&command=ls. BAM, it works 🎆

I do believe this is a bug on your side though, since only name and namespace are the only required parameters, but using them alone will break. Shall I open an issue or will you?

@mbohlool
Copy link
Contributor

mbohlool commented Aug 1, 2017

Nice that you figured it out. Both/either issue and PR are welcome.

@prashantabkari
Copy link

prashantabkari commented Oct 10, 2017

Hi - I have hit the same issue with the following log
" raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='192.168.1.108', port=6443): Max retries exceeded with url: /api/v1/pods?watch=False (Caused by SSLError(CertificateError("hostname '192.168.1.108' doesn't match either of 'master', 'kubernetes', 'kubernetes.default', 'kubernetes.default.svc', 'kubernetes.default.svc.cluster.local'",),))"

Following are my configurations
IPaddress
Metadata-Version: 2.0
Name: ipaddress
Version: 1.0.18

urllib3
Metadata-Version: 2.0
Name: urllib3
Version: 1.22


Metadata-Version: 1.1
Name: websocket-client
Version: 0.40.0

python version
Python 2.7.5

K8 cluster
kubectl cluster-info gives the correct info of master and kubedns running server

Is the above version of urllib3 supported?

UPDATE:
Following are the workaround suggested in https://github.com/kelproject/pykube/issues/29

  1. CHange the kubeconfig file or
  2. install python3.5

But looking for solutions with Python 2.7

@czz253861763
Copy link

from kubernetes.client import configuration
config.load_kube_config()
configuration.assert_hostname = False

this works fine for me

@nettyxiong
Copy link

from kubernetes import client
from kubernetes import config
from kubernetes.client.api import core_v1_api

config.load_kube_config('/root/.kube/config')
configuration = client.Configuration()
configuration.assert_hostname = False
configuration.verify_ssl = True
client.Configuration.set_default(configuration)

v1 = core_v1_api.CoreV1Api()
print("Listing pods with their IPs:")

ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
    print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))

this works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants