scitex_ssh

SciTeX SSH - SSH primitives (exec/copy/attach) and gated reverse tunnels.

exception scitex_ssh.PolicyError[source]

Bases: RuntimeError

Raised when an action is denied by the allowlist.

class scitex_ssh.SSHResult(returncode, stdout, stderr)[source]

Bases: object

returncode: int
stdout: str
stderr: str
property success: bool
__init__(returncode, stdout, stderr)
scitex_ssh.attach(host, command=None, *, ssh_opts=())[source]

Interactive ssh -t. Replaces current process via os.execvp; returns rc only on failure-to-launch.

Return type:

int

scitex_ssh.copy_from(host, src, dest, *, recursive=False, ssh_opts=(), runner=None)[source]

scp host:src to local dest.

Return type:

SSHResult

scitex_ssh.copy_to(host, src, dest, *, recursive=False, ssh_opts=(), runner=None)[source]

scp local src to host:dest. ssh_opts forwarded via -o.

Return type:

SSHResult

scitex_ssh.exec_remote(host, command, *, ssh_opts=(), check=False, timeout=None, runner=None)[source]

Run a command on host via ssh.

ssh_opts is a list of raw ssh flags (e.g. [‘-A’, ‘-o’, ‘StrictHostKeyChecking=no’]) passed through verbatim. Users opt into agent forwarding by passing ‘-A’ themselves.

Parameters:

runner (callable, optional) – Subprocess invoker matching subprocess.run’s signature. Defaults to subprocess.run. Pass a hand-rolled fake from tests to observe and stub the call without mocks.

Return type:

SSHResult

scitex_ssh.setup(port, bastion_server=None, secret_key_path=None, *, host=None, runner=None, scripts_dir=None)[source]

Set up a persistent SSH reverse tunnel.

Parameters:
  • port (int) – The remote port to forward (e.g. 2222).

  • bastion_server (str, optional) – The bastion/relay server hostname or IP. Falls back to SCITEX_SSH_BASTION_SERVER env var.

  • secret_key_path (str, optional) – Path to the SSH private key for authentication. Falls back to SCITEX_SSH_SECRET_KEY_PATH env var.

Returns:

Result with ‘success’, ‘stdout’, ‘stderr’ keys.

Return type:

dict

Raises:

ValueError – If bastion_server or secret_key_path is not provided and the corresponding environment variable is not set.

scitex_ssh.remove(port, *, host=None, runner=None, scripts_dir=None)[source]

Remove a persistent SSH reverse tunnel.

Parameters:
  • port (int) – The remote port of the tunnel to remove.

  • host (str, optional) – Local host label for allowlist gating. Defaults to local hostname.

Returns:

Result with ‘success’, ‘stdout’, ‘stderr’ keys.

Return type:

dict

scitex_ssh.status(port=None, *, runner=None)[source]

Check status of SSH reverse tunnels.

Parameters:

port (int, optional) – Specific port to check. If None, shows all tunnels.

Returns:

Result with ‘success’, ‘stdout’, ‘stderr’ keys.

Return type:

dict

scitex_ssh.get_version()[source]

Get scitex-ssh version.

Return type:

str