SSH Tunnel Plugin
The SSH Tunnel plugin opens and maintains a persistent SSH port-forward to a fixed remote server (localhost:<local_port> → <server_ip>:<remote_port>), with automatic reconnection if the tunnel drops. It is infrastructural: no agent tools, no UI.
Only one tunnel is managed per Codumentor server process.
Requirements
- OpenSSH client (
ssh) onPATH - An SSH private key at
ssh_key_path, or one of: ~/.ssh/id_rsa~/.ssh/id_ed25519
Configuration
plugins:
- module: codumentor.plugins.ssh_tunnel
class: SSHTunnelPlugin
args:
server_ip: "192.168.1.100"
remote_port: 1248
local_port: 1248
enabled: true
| Parameter | Type | Default | Description |
|---|---|---|---|
server_ip | string | (required) | IP address of the remote server |
remote_port | int | 1248 | Port on the remote server |
local_port | int | 1248 | Port to bind on localhost |
ssh_key_path | string | None | Path to the SSH private key. If unset, auto-detects from the locations above |
check_interval_seconds | int | 30 | How often to check that the tunnel is still forwarding |
ssh_user | string | "root" | Remote SSH username |
enabled | bool | true | Disable without removing the plugin from config |
health_check_timeout_seconds | float | 10 | Timeout of one HTTP probe through the tunnel |
zombie_failure_threshold | int | 3 | Consecutive failed probes (one per check interval) before a listening-but-not-forwarding tunnel is restarted |
Behaviour
ssh runs as a direct child of the Codumentor process (ssh -N -L … -o ExitOnForwardFailure=yes, no -f), so the plugin knows exactly which process it started. It only ever stops that process — never by name or pattern, never a tunnel some other process holds.
On startup, if local_port is already listening, the plugin uses it as-is: whoever holds it (another Codumentor instance on the same host, a host-level tunnel) keeps owning it. Otherwise it starts its own tunnel. When several instances share one forward port, only one can bind it; the others use that tunnel, and if it dies they race to recreate it — the losers' ssh exits on the bind failure and they use the winner's.
A background loop runs every check_interval_seconds:
- Port not listening — the tunnel dropped; start a new one (the race above).
- Port listening — an HTTP GET to
http://127.0.0.1:<local_port>/must return any HTTP response withinhealth_check_timeout_seconds. A timeout or a reset counts as one failed probe; a success resets the count. Only afterzombie_failure_thresholdconsecutive failed probes is the tunnel declared a zombie, so a busy LLM server or a momentarily stalled process does not trigger a restart. Even then the plugin restarts only its own ssh; a zombie held by another process is logged and left alone (its owner will restart it).
Tunnel failure is non-fatal: a warning is logged and the loop keeps retrying.
On shutdown, only a tunnel this process created is stopped.
Security and ops notes
- Host key verification is disabled (
StrictHostKeyChecking=no,UserKnownHostsFile=/dev/null). - SSH keepalive is
ServerAliveInterval=60andServerAliveCountMax=3(drop after ~180 s of unresponsiveness). - Running several instances on one host that all forward the same port works, but the most robust setup is a single host-level tunnel (e.g. a systemd unit running
ssh -N -L …orautossh) with the plugin left enabled: every instance then finds the port listening and simply uses it. - Typical use: forwarding a remote self-hosted LLM (see Model Providers).