Haoyuan Ge
Haoyuan Ge

Reputation: 3699

How to send token within url in Kubernetes?

I want to use websocket to access Kubernetes API, and so it is more convenient to send token like wss://example.com" + url + "&access_token=blahblahblah. The official API doc sends token in header. Where can I find such a token and send it with url?

What I want to do is to exec pods via a web page through websocket:

Container-Terminal via Websocket

Support exec and pod logging over WebSockets

Upvotes: 1

Views: 690

Answers (3)

w3ichen
w3ichen

Reputation: 331

There is currently no way to send Authorization headers using native javascript WebSockets.

My workaround

Currently I'm working around this by using the @kubernetes/client-node in NodeJS to open a WebSocket connection.

The ws WebSocket library in NodeJS does support Authorization headers.

Then forwarding the NodeJS WebSocket messages to the front-end using Socket.io: https://stackoverflow.com/a/62547135.

Upvotes: 1

Jordan Liggitt
Jordan Liggitt

Reputation: 18161

Bearer token authentication in the URL is not supported in Kubernetes currently, only as an Authorization header.

Upvotes: 2

Haoyuan Ge
Haoyuan Ge

Reputation: 3699

After searching over the Internet and reading many discussion on Kubernetes, I post my own answer about accessing kubernetes API with password in url, not header:

wss://username:[email protected]/api/v1/namespaces/default/pods/YourPodName/exec?stdout=1&stdin=1&stderr=1&tty=1&command=%2Fbin%2Fsh

The username and password is in ~/.kube/config

Welcome answers for sending bearer token.

Upvotes: 0

Related Questions