SSH Tunnel Plugin
The SSH Tunnel Plugin auto-opens and maintains a persistent SSH port-forward tunnel to a fixed remote server, with automatic reconnection on failure. It runs as an infrastructural background service — it does not register agent tools or event bus handlers.
Overview
The SSH Tunnel plugin:
- Establishes an SSH tunnel at server startup (priority 1) that forwards
localhost:<local_port>→<server_ip>:<remote_port> - Runs a background maintenance loop that checks tunnel health every 30 seconds and reconnects if the tunnel drops
- Uses a module-level singleton so only the first instantiation does real work; subsequent instantiations are zero-cost no-ops
Requirements
- OpenSSH client (
sshcommand) must be installed and available inPATH - An SSH private key must exist at one of the auto-detected locations, or
ssh_key_pathmust be set: ~/.ssh/id_rsa~/.ssh/id_ed25519~/.ssh/datacrunch_key
Configuration
plugins:
- module: codumentor.plugins.ssh_tunnel
class: SSHTunnelPlugin
args:
server_ip: "192.168.1.100"
remote_port: 1248
local_port: 1248
enabled: true
Configuration Parameters
| 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 SSH private key. If unset, auto-detects from ~/.ssh/id_rsa, ~/.ssh/id_ed25519, or ~/.ssh/datacrunch_key |
check_interval_seconds | int | 30 | How often the maintenance loop checks tunnel health |
ssh_user | string | "root" | Remote SSH username |
enabled | bool | true | Disable the plugin without removing it from config |
How It Works
Tunnel Establishment
On registration, the plugin checks if local_port is already listening. If so, it assumes the tunnel is already up and skips creation. Otherwise it kills any stale SSH tunnel processes to the target IP and creates a fresh tunnel via ssh -f -N -L <local_port>:localhost:<remote_port>.
Maintenance Loop
After registration, a background asyncio.Task loops every check_interval_seconds:
- Checks if
local_portis listening - If not, kills stale tunnels and re-establishes the connection
- Handles
CancelledErrorfor clean shutdown
Singleton Behaviour
The first SSHTunnelPlugin instance created becomes the owner — it manages the tunnel and the maintenance task. Every subsequent instance (e.g., per-conversation instantiations in the agent) detects the existing owner and skips all setup work. Cleanup is idempotent: only the owner cancels the maintenance task and kills tunnel processes.
Notes
- Host key verification is disabled (
StrictHostKeyChecking=no,UserKnownHostsFile=/dev/null) for operational convenience - Server alive checks are configured with
ServerAliveInterval=60andServerAliveCountMax=3(timeout after ~180 s of unresponsiveness) - Tunnel failure is non-fatal: the plugin logs a warning and the maintenance loop keeps retrying
- No UI or API endpoints are exposed by this plugin; it is purely infrastructural
- To stop the tunnel manually:
pkill -f 'ssh.*<server_ip>'