From c00230384fe8c9bac9fa29cd2b6bc0933a4ab041 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 26 Oct 2026 13:28:36 -0400 Subject: [PATCH] Add ssh://' support for CONFLUENT_HOST This handles Unix domain forwarding over ssh on behalf of the user. Extends to the nodeconsole -tv, which is particularly handy for faster video (VNC over ssh instead of base64 whole screen updates). --- confluent_client/bin/nodeconsole | 21 ++++++++++++++++++ confluent_client/confluent/asynclient.py | 28 ++++++++++++++++++++++-- confluent_client/confluent/client.py | 28 ++++++++++++++++++++++-- 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/confluent_client/bin/nodeconsole b/confluent_client/bin/nodeconsole index 962db035..99344736 100755 --- a/confluent_client/bin/nodeconsole +++ b/confluent_client/bin/nodeconsole @@ -1213,6 +1213,27 @@ async def do_vnc(node, url, outputfile=None): global streaming keeprunning = True retries = 5 + if os.path.abspath(url) and 'ssh://' in os.environ.get('CONFLUENT_HOST', ''): + if not os.path.exists(url): + localpath = os.path.join(os.environ['XDG_RUNTIME_DIR'], 'confluent', 'vinz', os.path.basename(url)) + os.makedirs(os.path.dirname(localpath), exist_ok=True, mode=0o700) + if os.path.exists(localpath): + try: + rdr, writer = await asyncio.open_unix_connection(localpath) + writer.close() + except Exception: + os.unlink(localpath) + if not os.path.exists(localpath): + sshhost = os.environ.get('CONFLUENT_HOST')[6:].split('/', 1)[0] + # would do '-fNT' like elsewhere, but the video tunnel exiting on close + # is nice, since we end up with another port forward for each node + sshproc = await asyncio.create_subprocess_exec( + 'ssh', '-fT', '-o', 'StreamLocalBindUnlink=yes', + '-L', localpath + ':' + url, sshhost, 'sleep', '30', + stdout=asyncio.subprocess.DEVNULL, + stderr=asyncio.subprocess.DEVNULL) + await sshproc.wait() + url = localpath while keeprunning: try: async with await vnc.VNCClient.create(url, outputfile=outputfile) as client: diff --git a/confluent_client/confluent/asynclient.py b/confluent_client/confluent/asynclient.py index 7ce4fafd..57bb4cbd 100644 --- a/confluent_client/confluent/asynclient.py +++ b/confluent_client/confluent/asynclient.py @@ -27,6 +27,7 @@ import os import shlex import socket import ssl +import subprocess import sys import confluent.asynctlvdata as tlvdata import confluent.sortutil as sortutil @@ -194,14 +195,37 @@ class Command(object): self.serverloc = '/var/run/confluent/api.sock' else: self.serverloc = server + if self.serverloc.startswith('ssh://'): + if '/' not in self.serverloc[6:]: + self.serverloc += '/var/run/confluent/api.sock' + userhost, apipath = self.serverloc[6:].split('/', 1) + if apipath[0] != '/': + apipath = '/' + apipath + serverpath = os.path.join(os.environ['XDG_RUNTIME_DIR'], 'confluent') + serverpath = os.path.join(serverpath, userhost) + localsock = os.path.join(serverpath, 'api.sock') + self.serverloc = localsock + os.makedirs(serverpath, exist_ok=True, mode=0o700) + if os.path.exists(localsock): + try: + self._connect_unix() + self.unixdomain = True + except Exception as e: + os.remove(localsock) + if not os.path.exists(localsock): + subprocess.check_call([ + 'ssh', '-fNT', '-o', 'StreamLocalBindUnlink=yes', + '-L', localsock + ':' + apipath, + userhost]) self.connected = False async def ensure_connected(self): if self.connected: return True if os.path.isabs(self.serverloc) and os.path.exists(self.serverloc): - self._connect_unix() - self.unixdomain = True + if not self.unixdomain: + self._connect_unix() + self.unixdomain = True elif self.serverloc == '/var/run/confluent/api.sock': raise Exception('Confluent service is not available') else: diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index 8cb481b1..3d9b1df4 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -27,6 +27,7 @@ import os import shlex import socket import ssl +import subprocess import sys import confluent.tlvdata as tlvdata import confluent.sortutil as sortutil @@ -169,9 +170,32 @@ class Command(object): self.serverloc = '/var/run/confluent/api.sock' else: self.serverloc = server + if self.serverloc.startswith('ssh://'): + if '/' not in self.serverloc[6:]: + self.serverloc += '/var/run/confluent/api.sock' + userhost, apipath = self.serverloc[6:].split('/', 1) + if apipath[0] != '/': + apipath = '/' + apipath + serverpath = os.path.join(os.environ['XDG_RUNTIME_DIR'], 'confluent') + serverpath = os.path.join(serverpath, userhost) + os.makedirs(serverpath, exist_ok=True, mode=0o700) + localsock = os.path.join(serverpath, 'api.sock') + self.serverloc = localsock + if os.path.exists(localsock): + try: + self._connect_unix() + self.unixdomain = True + except Exception: + os.remove(localsock) + if not os.path.exists(localsock): + subprocess.check_call([ + 'ssh', '-fNT', '-o', 'StreamLocalBindUnlink=yes', + '-L', localsock + ':' + apipath, + userhost]) if os.path.isabs(self.serverloc) and os.path.exists(self.serverloc): - self._connect_unix() - self.unixdomain = True + if not self.unixdomain: + self._connect_unix() + self.unixdomain = True elif self.serverloc == '/var/run/confluent/api.sock': raise Exception('Confluent service is not available') else: