From c1a14cd90ebec05207dac64d61f71e03a9204dc6 Mon Sep 17 00:00:00 2001 From: Will Nilges Date: Thu, 7 Jul 2022 00:23:35 -0400 Subject: [PATCH] Oh my god I'm so close. I'm so close. --- Dockerfile | 2 ++ config.py | 4 ++-- proxstar/__init__.py | 19 ++++--------------- proxstar/static/js/script.js | 5 ++++- proxstar/vm.py | 5 +++-- proxstar/vnc.py | 2 ++ 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 23a93e7..67e86d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,6 @@ COPY .git ./.git COPY *.py . COPY proxstar ./proxstar RUN touch proxmox_ssh_key targets && chmod a+w proxmox_ssh_key targets # This is some OKD shit. +# This is so cringe, but it's for development. Comment this before pushing. +#COPY HACKING/ssh_key proxmox_ssh_key ENTRYPOINT ddtrace-run python3 wsgi.py diff --git a/config.py b/config.py index 42c322f..48fb66f 100644 --- a/config.py +++ b/config.py @@ -62,8 +62,8 @@ RQ_DASHBOARD_REDIS_HOST = environ.get('PROXSTAR_REDIS_HOST', 'localhost') REDIS_PORT = int(environ.get('PROXSTAR_REDIS_PORT', '6379')) # VNC -WEBSOCKIFY_PATH = environ.get('PROXSTAR_WEBSOCKIFY_PATH', '/opt/app-root/bin/websockify') -WEBSOCKIFY_TARGET_FILE = environ.get('PROXSTAR_WEBSOCKIFY_TARGET_FILE', '/opt/app-root/src/targets') +WEBSOCKIFY_PATH = environ.get('PROXSTAR_WEBSOCKIFY_PATH', '/usr/local/bin/websockify') +WEBSOCKIFY_TARGET_FILE = environ.get('PROXSTAR_WEBSOCKIFY_TARGET_FILE', '/opt/proxstar/targets') # SENTRY # If you set the sentry dsn locally, make sure you use the local-dev or some diff --git a/proxstar/__init__.py b/proxstar/__init__.py index cda900e..54de896 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -67,8 +67,9 @@ sentry_sdk.init( environment=app.config['SENTRY_ENV'], ) -with open('proxmox_ssh_key', 'w') as ssh_key_file: - ssh_key_file.write(app.config['PROXMOX_SSH_KEY']) +if not os.path.exists('proxmox_ssh_key'): + with open('proxmox_ssh_key', 'w') as ssh_key_file: + ssh_key_file.write(app.config['PROXMOX_SSH_KEY']) ssh_tunnels = [] @@ -277,6 +278,7 @@ def vm_console(vmid): user = User(session['userinfo']['preferred_username']) connect_proxmox() if user.rtp or int(vmid) in user.allowed_vms: + # import pdb; pdb.set_trace() vm = VM(vmid) stop_ssh_tunnel(vm.id, ssh_tunnels) port = str(5900 + int(vmid)) @@ -291,19 +293,6 @@ def vm_console(vmid): else: return '', 403 -@app.route('/novnc') -def get_resource(): # pragma: no cover - mimetypes = { - ".css": "text/css", - ".html": "text/html", - ".js": "application/javascript", - } - complete_path = os.path.join('/opt/proxstar/proxstar/', 'static/noVNC/vnc.html') - # ext = os.path.splitext(path)[1] - # mimetype = mimetypes.get(ext, "text/html") - content = open(complete_path).read() - return Response(content) - @app.route('/vm//cpu/', methods=['POST']) @auth.oidc_auth def vm_cpu(vmid, cores): diff --git a/proxstar/static/js/script.js b/proxstar/static/js/script.js index ad2cc96..77f610a 100644 --- a/proxstar/static/js/script.js +++ b/proxstar/static/js/script.js @@ -652,7 +652,10 @@ $("#console-vm").click(function(){ }).then((response) => { return response.text() }).then((token) => { - window.open(`/static/noVNC/vnc.html?autoconnect=true&encrypt=true&host=proxstar-vnc.csh.rit.edu&port=443&path=path?token=${token}`, '_blank'); + // window.open(`/static/noVNC/vnc.html?autoconnect=true&encrypt=true&host=proxstar-vnc.csh.rit.edu&port=443&path=path?token=${token}`, '_blank'); + // TODO (willnilges): encrypt=true + // TODO (willnilges): set host and port to an env variable + window.open(`/static/noVNC/vnc.html?autoconnect=true&host=freedom.csh.rit.edu&port=8081&path=path?token=${token}`, '_blank'); }).catch(err => { if (err) { swal("Uh oh...", `Unable to start console for ${vmname}. Please try again later.`, "error"); diff --git a/proxstar/vm.py b/proxstar/vm.py index 2b6009f..0e260bd 100644 --- a/proxstar/vm.py +++ b/proxstar/vm.py @@ -4,7 +4,7 @@ import urllib from flask import current_app as app from tenacity import retry, stop_after_attempt, wait_fixed -from paramiko import SSHClient +import paramiko from proxstar import db, starrs from proxstar.db import delete_vm_expire, get_vm_expire @@ -281,7 +281,8 @@ class VM: # proxmox = connect_proxmox() config = f'args: -object secret,id=secvnc{self.id},data=chomchom1 -vnc 127.0.0.1:{int(self.id)+5900},password-secret=secvnc{self.id}' path = f'/etc/pve/local/qemu-server/{self.id}.conf' - with SSHClient() as ssh: + with paramiko.SSHClient() as ssh: + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(self.node, port=22, username=ssh_user, key_filename='proxmox_ssh_key', passphrase=ssh_pass) ssh.exec_command(f"if grep -- '-vnc' {path}; then echo found config; else echo {config} >> {path}; fi") diff --git a/proxstar/vnc.py b/proxstar/vnc.py index 11209d2..dd1562f 100644 --- a/proxstar/vnc.py +++ b/proxstar/vnc.py @@ -38,6 +38,7 @@ def get_vnc_targets(): def add_vnc_target(port): + # TODO (willnilges): This doesn't throw an error if the target file is wrong. targets = get_vnc_targets() target = next((target for target in targets if target['port'] == port), None) if target: @@ -66,6 +67,7 @@ def start_ssh_tunnel(node, port): to the proxstar container """ port = int(port) + server = SSHTunnelForwarder( node, ssh_username=app.config['PROXMOX_SSH_USER'],