-
Notifications
You must be signed in to change notification settings - Fork 147
k8s_cp nor k8s_exec cannot work with http proxy authentication. #246
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
Comments
how to setup http proxy with basic authentication, powered by squid /etc/squid/squid.conf:
setup account and run squid and test proxying: htpasswd -b -c /etc/squid/passwd demo demo
squid -f /etc/squid/squid.conf -NYCd 1 --foreground
# following should work fine
https_proxy=http://demo:demo@yourIP:3128/
curl -sSL https://google.com/
# following should not 200 ok when 'requiring basic authentication' enabled
https_proxy=http://yourIP:3128/
curl -sSL https://google.com/ k8s_cp and k8s_exec failed if squid proxy has above configuration. |
@itaru2622 Thanks for the detailed bug report. This looks to be a problem with the underlying kubernetes client. I believe the proxy auth is not being set on the connection here: https://github.com/kubernetes-client/python-base/blob/b0afc93ffabb66d930abcdfb1255214d167bf8d5/stream/ws_client.py#L450. I'll take a closer look and try and get a PR submitted soon. |
@gravesm thank you for your investigation. I found kubernetes-client/python-base#230 which requests fixing same issue, but it was closed before merging by bot. I'm glad your help for this issue. |
@gravesm I checked sources and found the following lines in common.py kubernetes.core/plugins/module_utils/common.py Lines 202 to 204 in d01e4a6
so, the patch for this issue could be something below, because configuration.proxy_headers are stored as HTTP header dictionary: diff --git a/stream/ws_client.py b/stream/ws_client.py
--- a/stream/ws_client.py
+++ b/stream/ws_client.py
@@ -429,6 +429,10 @@ def create_websocket(configuration, url, headers=None):
else:
header.append("sec-websocket-protocol: v4.channel.k8s.io")
+ if configuration.proxy_headers:
+ for key, value in configuration.proxy_headers.items():
+ header.append("%s: %s" % (key, value))
+
if url.startswith('wss://') and configuration.verify_ssl: I don't know how to implement e2e_test for above for https://github.com/kubernetes-client/python |
@gravesm please let me know how to debug plugins/modules/k8s_xxx.py and/or plugins/module_utils/*.py I want to print debugging message but It couldn't succeed it. even messages by plugins/connection/kubectl.py out. I know that: plugins/connection/kubectl.py using "ansible.utils.display.Display" |
@itaru2622 The problem is that modules are run in a separate process, so the messages won't go to stdout for the main controller process. The easiest thing to do is to use something like https://github.com/zestyping/q. |
@gravesm thank you for your help. I finally got a test-ok code different than the above through debugging. I will post PR to https://github.com/kubernetes-client/python-base ... |
@itaru2622 thanks for submitting the PR on the client! This is really helpful. Have you had a chance to test your client changes against this collection? |
Yes.
unfortunately, new kubernetes-client with my PR is not released yet( I mean new version number is not assigned yet), anyway, you can use proxy authentication feature by the above command. |
@gravesm latest official python kubernetes library supports proxy authentication since 19.15.0. now it is available by usual installation as below command:
so I close this issue. |
SUMMARY
k8s_cp nor k8s_exec cannot work with http proxy authentication.
both can work only when http proxy need no authentiation.
I tested most patterns for http proxy auth as described in docs/kubernetes.core.k8s_xxx_module.rst
but always it fails by following message.
deloying pod with kubernetes.core.k8s via http proxy authentication works.
ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
debian 11 (bullseye)
STEPS TO REPRODUCE
Following are my test codes.
ansible-playbook -i hosts -e test=alpine:latest
EXPECTED RESULTS
as it described in docs, both of k8s_cp and k8s_exec can work with http proxy authentication.
ACTUAL RESULTS
both k8s_cp and k8s_exec failed when http proxy requires authentication.
The text was updated successfully, but these errors were encountered: