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

https_proxy not working in v0.8.3 #128

Closed
andyjsharp opened this issue Mar 2, 2023 · 6 comments · Fixed by #129
Closed

https_proxy not working in v0.8.3 #128

andyjsharp opened this issue Mar 2, 2023 · 6 comments · Fixed by #129

Comments

@andyjsharp
Copy link

I was unable to get a working connection to a kubernetes cluster (v1.21.2) while using the environment variable HTTPS_PROXY, connectivity to the cluster is working for kubectl.

Looking at the code it would appear that it is only checking for http_proxy/HTTP_PROXY, and setting those environment variables also failed to successfully connect to the cluster.

        self.api_client.configuration.proxy = environ.get('http_proxy') or environ.get('HTTP_PROXY')

Removing the above code, and adding the following code instead after the config.load_kube_config(...) resolves the issue and proxy works just fine for KubeLibrary.

try:
    config.load_kube_config(kube_config, context)
    # fix for http proxy
    proxy_url = (
        environ.get("https_proxy", None)
        or environ.get("HTTPS_PROXY", None)
        or environ.get("http_proxy", None)
        or environ.get("HTTP_PROXY", None)
    )
    if proxy_url:
        client.Configuration._default.proxy = proxy_url
    # end of fix
@m-wcislo
Copy link
Collaborator

m-wcislo commented Mar 2, 2023

Hi,
thanks for creating the issue. Just want to make sure, you tried setting http_proxy or HTTP_PROXY and it is still not working?
Using which keyword you observed the issue?

@andyjsharp
Copy link
Author

Correct, I tried with all variants of http_proxy https_proxy and in uppercase with no joy. The keywords that I was using to begin with was your own system_smoke.robot tests, and nothing worked.

Once I'd made those changes then I was able to get it running just fine. For info, I am also using kubernetes==22.6.0 if that helps any as well.

@andyjsharp
Copy link
Author

Just some more information based on my tests with v0.8.3 prior to making changes.

$ echo $http_proxy, $HTTP_PROXY, $https_proxy, $HTTPS_PROXY 
http://localhost:8080, http://localhost:8080, http://localhost:8080, http://localhost:8080
$ kubectl get no
NAME           STATUS   ROLES                  AGE     VERSION
172.16.18.20   Ready    control-plane,master   2d20h   v1.21.2
172.16.18.21   Ready    <none>                 2d20h   v1.21.2
172.16.18.22   Ready    <none>                 2d20h   v1.21.2
172.16.18.23   Ready    <none>                 2d20h   v1.21.2

==============================================================================
Kubernetes :: Pre-Checks                  
==============================================================================
[ WARN ] Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x120a36090>, 'Connection to 10.54.154.15 timed out. (connect timeout=None)')': /api/v1/

@m-wcislo
Copy link
Collaborator

m-wcislo commented Mar 9, 2023

So just wondering how do you mimic proxy on your localhost?

Also did some check and seems proxy settings are propagating to all the api clients. Which kubernetes python client version are you using?

Also could you double check if no_proxy is not set?

@andyjsharp
Copy link
Author

andyjsharp commented Mar 9, 2023

So, for proxy I'm actually redirecting my http_proxy over socks5 to reach a server that I can only reach via a jumphost.
I've setup a socks proxy locally on 1080, and then using a http-to-socks proxy which is setup on my local machine, hence my http_proxy points to localhost:8080 but that is getting sent via socks to localhost:1080 which can then reach the server that I have the other side of my jumphost. Nothing is ever easy...!

brew install npm
npm install -g http-proxy-to-socks

hpts -s 127.0.0.1:1080 -p 8080

So I have an SSH session opened to my target server using a ProxyJump and DynamicForward 1080 in my ssh config file etc. Then while keeping that session open, I then have the hpts command running in another terminal, and then I can kubectl to my hearts content...

Re: python client, it is. kubernetes==25.3.0
Yes, I can confirm that I do not have no_proxy set.

@m-wcislo
Copy link
Collaborator

Hi,
Ok setting Configuration._default.proxy seems to be known workaround for proxy problems (kubernetes-client/python#333), and after some test it was the only way I could make it use urllib3.ProxyManager.

The fix is ready in #129 . Review and possible testing is appreciated.

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.

2 participants