larsks / novaconsole

Apache License 2.0
20 stars 10 forks source link

Can I use novaconsole to interact with (send keystrokes to) an instance? #4

Open julianpistorius opened 2 years ago

julianpistorius commented 2 years ago

I'm looking for a way to interact with consoles of OpenStack instances which are inaccessible from the Internet (to help with debugging deployments for example). I've tested this and I can see the console output. When I type anything into the local terminal window running novaconsole it disconnects.

On the instance:

root@serial-console-test:~# echo "I am echoing this into /dev/console from an SSH session on the instance" > /dev/console
root@serial-console-test:~# echo "Now I'm going to type some keys in novaconsole" > /dev/console

On my laptop:

$ nova get-serial-console aaaaaaaa-bbbb-cccc-dddd-eeeeffff0000
+--------+--------------------------------------------------------------------------------+
| Type   | Url                                                                            |
+--------+--------------------------------------------------------------------------------+
| serial | wss://js2.jetstream-cloud.org:6083/?token=deadbeef-dead-beef-dead-beefdeadbeef |
+--------+--------------------------------------------------------------------------------+
$ novaconsole -d -v --url wss://js2.jetstream-cloud.org:6083/?token=deadbeef-dead-beef-dead-beefdeadbeef
WARNING:novaconsole.client:connected to: wss://js2.jetstream-cloud.org:6083/?token=7deadbeef-dead-beef-dead-beefdeadbeef
WARNING:novaconsole.client:type "~." to disconnect
I am echoing this into /dev/console from an SSH session on the instance
Now I'm going to type some keys in novaconsole
ERROR:novaconsole:remote host closed connection: Connection to remote host was lost.

I typed a key on my laptop and then the ERROR:... line was printed.

Is this something which is even possible using Nova serial consoles? Is it something that needs to be configured in Nova?

Background: If this is possible then I'd like to reverse engineer novaconsole to build an in-browser version using xterm.js. I don't want to use the SPICE HTML5 client or noVNC, because I want a proper copy & paste experience in the browser.

Any advice appreciated!

larsks commented 2 years ago

Is this something which is even possible using Nova serial consoles?

It should be! When written it was certainly possible to engage in two-way communication with the serial console.

Is it something that needs to be configured in Nova?

Not to my knowledge. It looks like you already have serial console support enabled, which should be sufficient.

It's been a while since I've had the opportunity to work with this code, but it's really just a simple websocket proxy with a thin wrapper to perform the keystone authentication. It should be trivial to implement in a browser (and these days there are a variety of terminal frameworks already available that might take care of terminal emulation for you).

julianpistorius commented 2 years ago

Thank you @larsks. It's good news that it was possible at some point. I'll use a debugger and see if I can figure out why it's crashing, and why it won't take keyboard input.

Re terminal frameworks: I got xterm.js to work in a duplex fashion with the Docker websocket console. I was hoping to do the same with Nova serial consoles. You can see a video of my efforts on this MR:

https://gitlab.com/exosphere/exosphere/-/merge_requests/619#note_869029857