@tomgreen66 There’s a lot of moving parts around VNC in OnDemand, but you can skip most of it to get this done because at the end of the day noVNC is configurable on the client side through query parameters. If you have VNC available via xinetd that handles authentication for you, then you could add a button somewhere on the Interactive Apps page that links to noVNC.
Take a look at how we redirect users to noVNC: https://sourcegraph.com/github.com/OSC/ondemand/-/blob/apps/dashboard/app/helpers/batch_connect/sessions_helper.rb#L184
A URL is built and the user is redirected to the noVNC client which is a static asset:
"/vnc.html?autoconnect=true&password=#{password}&path=rnode/#{connect.host}/#{connect.websocket}/websockify&resize=#{resize}"
A short technical dive into the relationship between noVNC, WebSockify and VNC:
- User launches a VNC session and this shell script is executed on the remote node: https://sourcegraph.com/github.com/OSC/ood_core/-/blob/lib/ood_core/batch_connect/templates/vnc.rb#L83
A few things happen here, a password is generated and used to build the URL #{password}
, and the port the VNC server started on is found:
# Parse output for ports used
display=$(echo "${VNC_OUT}" | awk -F':' '/^Desktop/{print $NF}')
port=$((5900+display))
- After the VNC server has started, WebSockify is booted up: https://sourcegraph.com/github.com/OSC/ood_core/-/blob/lib/ood_core/batch_connect/templates/vnc.rb#L127
A random port is allocated for the WebSocket connection and WebSockify is started. Then a watchdog process is started that watches VNC log files for successful authentication requests and once detected, resets the VNC password for use on the next successful connection (this is a hacky OOD specific process, we’re working on improving internal authentication)
So what purpose does WebSockify serve? It’s a simple TCP proxy that talks over WebSockets, it allows for this data flow to be possible:
Browser <-> noVNC (Remote Frame Buffer) <-> WebSocket <-> WebSockify <-> underlying VNC server
noVNC is responsible for most of the magic, it’s implements the VNC protocol for you through JavaScript.
But since you have a VNC server running already then you only need to spawn WebSockify processes. I think in combination with the Linux Host Adapter, this can be done easily.
Here’s a snippet from the startup script that you could use (the bash script finds a random port, and WebSockify is started in daemon mode):
websocket=$(find_port)
#{websockify_cmd} -D ${websocket} localhost:${port}
If you’re interested in learning more about the internals of WebSockify, I recommend looking at the source https://github.com/novnc/websockify. We use novnc/websockify
at OSC.
I ported WebSockify to Golang which might be easier to understand (you can spin up the batteries included Docker image): https://github.com/msquee/go-websockify