Our app works as follows:
- Multiple remote machines connect to a central server using SSH connections
- The central server has various Python processes which process data sent over these SSH connections and store it in a database
- The central server also runs a bunch of Flask-based HTTP servers which process user requests and respond with data extracted from the DB; this forms the backend for the website which users access
We have been asked to add support for in-browser VNC connections to the remote machines to the app. This will require the user's browser to connect with a service running on the remote machines via a websocket. The way this would work is:
- The remote machine, let's say
foo, would run the VNC service, which will listen on a specific port expecting a websocket connection. - When
fooconnects to the central server via SSH, this socket will be forwarded, usingssh -R, to a socket file on the central server, let's say/remote/vnc_websocket/foo/websocket.sock - When a user, let's call them Alice, want to VNC into machine
foo, their browser sends a websocket request tocentral.server/vnc/foo - The
/vnc/{machine}route in our Flask app processes the request:- It checks the login token, sent in the request header, to confirm Alice is logged in
- It accesses the DB to confirm that machine
foois connected, and that Alice has permission to access it
- Assuming all is well, the flask app then connects the incoming request from Alice to
/remote/vnc_websocket/foo/websocket.sock, forwarding all traffic both ways
I know how to handle steps 1-4, but I have no idea how to implement step 5. I've looked at Flask-SockerIO and Flask-Websockets, but they're both focussed on implementing a Websocket server; I just want to connect a request to an existing server and then get out of the way.
I would prefer to integrate this solution into our existing Flask-based microservices, since we already have the code to handle things like checking logins, but if absolutely necessary I could implement a separate non-Flask-based microservice just for handling websocket requests. It would still have to be Python, though.