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

Add command to request a VNC console #238

Merged
merged 2 commits into from
Jul 13, 2020

Conversation

minus7
Copy link
Contributor

@minus7 minus7 commented May 11, 2020

Add command to request a VNC console. Also includes a proxy translating WebSocket to a normal TCP socket using the -l flag. This allows a normal VNC viewer to connect to the console by connecting to localhost:5900. (script for that below)

This also updates the version of the hcloud library to make use of the console API added in hetznercloud/hcloud-go#134

Preview:
screenshot

@minus7
Copy link
Contributor Author

minus7 commented Jul 8, 2020

Bump. Rebased onto latest master. The commit for the version bump for the hcloud library is now gone. This is still good to go from my side.

@LKaemmerling
Copy link
Member

Hey @minus7,

first of all thank you for the MR. We tried it out locally (the proxy option) and on our machines (tested on MacOS and Linux) the VNC connection does not work.

I would prefer to not let the cli proxy the connection, it should just "output" the data.

@LKaemmerling LKaemmerling removed the stale label Jul 9, 2020
@hetznercloud hetznercloud deleted a comment from github-actions bot Jul 9, 2020
@minus7
Copy link
Contributor Author

minus7 commented Jul 9, 2020

We tried it out locally (the proxy option) and on our machines (tested on MacOS and Linux) the VNC connection does not work.

Do you have more info on why it doesn't work? I run ./hcloud server request-console -l zeus and then gvncviewer with localhost or localhost:0. Note that localhost:5900 does not work because gvncviewer adds 5900 to the port number so it ends up at port 11800.

I would prefer to not let the cli proxy the connection, it should just "output" the data.

If you don't specify -l you just get the data. I like having a proxy in there as a convenience tool so you don't need to find a VNC tool that supports WebSocket connection or have a separate proxy first. In fact, I'd love to have it also launch my VNC viewer and enter the VNC password for me (behind a flag of course) to minimize the steps I have to take when opening a console.

@LKaemmerling
Copy link
Member

We (@fhofherr on Linux and i on MacOS) tested it the same way:

  1. Create a server
  2. Request console with -l (hcloud server request-console <idOrName> -l)
  3. Open a random vnc client (@fhofherr used: TigerVNC Viewer 64-bit v1.10.1, i tried the native mac vnc capability and https://apps.apple.com/de/app/remote-desktop-vnc/id472995993?mt=12)
  4. Enter address (tried: localhost, localhost:5900, vnc://localhost,vnc://localhost:5900)
  5. Connect
  6. Enter password
  7. The process from 2. closes itself only with the message: Connected!

As you can see, adding a proxy is mostly not that easy so i would still favor to not have the proxy itself in the hcloud cli. The cli should be as small as possible.

@minus7
Copy link
Contributor Author

minus7 commented Jul 9, 2020

I guess your VNC client connects twice and the proxy exits after the first connection disconnects.

I'll remove the proxy commit then if I can't convince you to take it :)
In that case the credentials should (at least optionally) be output in a machine-readable form, so another tool can grab them. Any suggestions/preferences for that?

@LKaemmerling
Copy link
Member

It would be good if you could add the -o flag (have a look at the list endpoints) with json, so basically output it as json :)

@minus7
Copy link
Contributor Author

minus7 commented Jul 9, 2020

Proxy mode is gone now and JSON added

@LKaemmerling LKaemmerling merged commit 5d6f1bb into hetznercloud:master Jul 13, 2020
@LKaemmerling
Copy link
Member

Thank you! Will be available with the next release version.

@sjaeckel
Copy link

I would have preferred if the proxy option would have been merged, but OK ...

FTR: connecting to the websocket URL is possible via websocat

$ hcloud server request-console <server>
Console for server 00000:
WebSocket URL: wss://web-console.hetzner.cloud/?server_id=00000&token=abc..xyz
VNC Password: abc..xyz
$ websocat --oneshot -b tcp-l:127.0.0.1:5900 'wss://web-console.hetzner.cloud/?server_id=00000&token=abc..xyz'

You have to make sure to enclose the websocket URL in single-quotes ', otherwise your shell will most likely try to interpret some of the URL arguments and it will fail.

A one-liner of this (with some limitations like only 1 parallel instance) is

$ hcloud server request-console <server> | tee /dev/tty | awk -F': ' '/WebSocket/ {print $2}' | xargs -I {} websocat --oneshot -b tcp-l:127.0.0.1:5900 {}

Then connect with your preferred VNC client to localhost:5900 and enter the password that was printed.

@minus7
Copy link
Contributor Author

minus7 commented Jun 14, 2022

I wrapped that up in a shell script for ease of use: $ hcloud-vnc <server>
Requires jq, websocat and tigervnc

#!/bin/bash

j=$(hcloud server request-console -o json "$1")

url=$(echo "$j" | jq -r '.WSSURL')
password=$(echo "$j" | jq -r '.Password')

tmpdir="$(mktemp -d ${XDG_RUNTIME_DIR:-/tmp}/hcloud-vnc.XXXXXXXXXX)"
trap 'rm -rf "$tmpdir"' EXIT

websocat --oneshot --binary unix-listen:"$tmpdir/vnc.sock" "$url" &

VNC_PASSWORD=$password vncviewer "$tmpdir/vnc.sock"
wait

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 this pull request may close these issues.

None yet

4 participants