sec-websocket-protocol
header defaults to v4.channel.k8s.io
causing HTTP 400
#2355
Labels
help wanted
Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
kind/bug
Categorizes issue or PR as related to a bug.
What happened (please include outputs or screenshots):
We are running our tool Gefyra to fetch environment variables from a running pod/container via a usual
stream
overconnect_get_namespaced_pod_exec
:https://github.com/gefyrahq/gefyra/blob/42879723d8a9265ed77faab3b23c47763950a461/client/gefyra/cluster/utils.py#L26-L36
In one of our environments, I am receiving an HTTP 400 for the WebSocket upgrade call. However, the equivalent
kubectl exec ...
executes properly.From somewhere in the stack trace:
websocket._exceptions.WebSocketBadStatusException: Handshake status 400 Bad Request - ...
So I looked for the differences between
kubectl
(v1.31.1) and the Python package (31.0.0). I was able to trace the problem back to thesec-websocket-protocol
header, which defaults tov4.channel.k8s.io
python/kubernetes/base/stream/ws_client.py
Lines 468 to 472 in 230925f
The value of the
sec-websocket-version
is set to13
with bothkubectl
andkubernetes-python
.Unfortunately, I couldn't find many sources on this, except https://kubernetes.io/blog/2024/08/20/websockets-transition/.
After patching the content of
kubernetes/base/stream/ws_client.py
in my site-packages tov5.channel.k8s.io
it started to work again.Now I am looking for a solution to pass this header from our code to get rid of the monkeypatch, but without constructing the
WSClient
myself.Is this some special setting in our environment (I mean to prevent
v4.channel.k8s.io
from working) or does that apply to all K8s clusters starting from 1.30.x?What you expected to happen:
The
stream
overconnect_get_namespaced_pod_exec
to work withsec-websocket-protocol
set tov5.channel.k8s.io
.How to reproduce it (as minimally and precisely as possible):
Anything else we need to know?:
Environment:
kubectl version
):python --version
)pip list | grep kubernetes
)Thank you for your good work.
The text was updated successfully, but these errors were encountered: