Remote SSH Plugin
Experimental — This plugin is under active development. APIs and behavior may change in future releases.
The Remote SSH plugin registers ssh_exec, ssh_upload, and ssh_download so the agent can run commands and transfer files on remote hosts via SSH/SFTP.
asyncssh is a Codumentor dependency (already in requirements.txt).
Configuration
plugins:
- module: codumentor.plugins.remote_ssh
class: RemoteSSHPlugin
args:
enabled: true
target_agents: "main"
allow_adhoc: true
adhoc_key_secret: ssh_private_key
adhoc_auth: encrypted_user_key
unlock_ttl: 3600
unlock_timeout: 300
adhoc_host_key_policy: trust_first
connect_timeout: 15
default_timeout: 30
max_output_size: 10240
keepalive_interval: 30
idle_timeout: 60
max_connections_per_session: 5
known_hosts_path: ./data/ssh_known_hosts
hosts:
prod-server:
hostname: 192.168.1.10
port: 22
username: deploy
key_path: ~/.ssh/id_rsa
host_key_policy: known_hosts
lab:
hostname: lab.example.com
username: ubuntu
host_key_policy: trust_first
Plugin parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
enabled | bool | true | Enable or disable the plugin |
target_agents | string | "main" | Which agents get the tools: "main", "subagent", or "all" |
allow_adhoc | bool | true | Allow connections to hosts not listed in hosts. A user setting can only narrow this, never lift a false |
adhoc_auth | string | "encrypted_user_key" | Identity offered to ad-hoc hosts: "encrypted_user_key" (only the calling user's key secret, which must be passphrase-protected and is unlocked by the user in the conversation), "user_key" (the user's key, passphrase or not) or "server" (this machine's keys/agent, shared by every user — single-user installs only) |
unlock_ttl | int | 3600 | Seconds an unlocked key stays usable in its conversation before the passphrase is asked again |
unlock_timeout | int | 300 | Seconds a tool call waits for the user to answer the key card |
adhoc_key_secret | string | "ssh_private_key" | Name of the per-user host-only secret holding the SSH key for ad-hoc hosts (see Ad-hoc hosts: the user's own key) |
adhoc_host_key_policy | string | "trust_first" | host_key_policy for ad-hoc hosts (see Host key verification) |
connect_timeout | int | 15 | Seconds to establish a connection (TCP, handshake, login) before the call fails |
default_timeout | int | 30 | Default ssh_exec timeout (seconds) |
max_output_size | int | 10240 | Maximum output size per tool call (bytes) |
max_download_size | int | 104857600 | Largest file ssh_download saves to the workspace with local_path (bytes) |
keepalive_interval | int | 30 | SSH keepalive interval (seconds) |
idle_timeout | int | 60 | Close idle pooled connections after this many seconds |
max_connections_per_session | int | 5 | Maximum pooled connections per conversation |
known_hosts_path | string | ./data/ssh_known_hosts | OpenSSH-format file used when a host's host_key_policy is trust_first |
Per-host parameters (args.hosts.<alias>)
| Parameter | Type | Default | Description |
|---|---|---|---|
hostname | string | (required) | Hostname or IP |
port | int | 22 | SSH port |
username | string | "root" | SSH username |
key_path | string | None | Private key file. If unset, default keys / ssh-agent are used |
host_key_policy | string | "known_hosts" | "known_hosts" (system known_hosts), "trust_first" (TOFU into known_hosts_path), or "disabled" (no verification). Unknown values fall back to "known_hosts". |
Tools
ssh_exec
| Parameter | Required | Description |
|---|---|---|
host | Yes | Pre-configured alias, or hostname/IP when ad-hoc is allowed |
command | Yes | Shell command to run |
username | No | Ad-hoc username (pre-configured hosts use their config) |
port | No | Ad-hoc SSH port (default 22) |
timeout | No | Command timeout in seconds |
ssh_upload / ssh_download
| Parameter | Required | Description |
|---|---|---|
host | Yes | Alias or hostname/IP |
local_path | Yes (upload) | Workspace file, resolved and read like read_file (through the sandbox under isolation) — never a raw server path |
remote_path | Yes | Path on the remote host. ~/ is the home directory; a relative path starts in the directory ssh_exec last left this conversation in (home if none) |
local_path | No (download) | Save the file to this workspace path (validated and written like write_file; a Download card follows when workspace_files is on). Without it the file is only shown (text) or described (binary). Up to max_download_size |
username / port | No | Same ad-hoc overrides as ssh_exec |
Approval
Every call asks for approval like shell does, with its own permission type —
remote_ssh.exec (host + command), remote_ssh.upload (host + both paths) and
remote_ssh.download (host + remote path). To pre-approve one, list its
permission type in permissions.allow. Headless (-p) runs deny them unless
named in --allowed-tools.
Ad-hoc hosts: the user's own key
When ad-hoc connections are allowed for a user, the tools authenticate to an
ad-hoc host with that user's SSH private key, read from their User Secrets
— the same host-only secret store, through the same secret_store capability,
that SCM Push uses for its push key. The value is read per tool call on the
host side; only the secret's name travels with the turn, and the key never
reaches the agent, the shell, or the conversation.
- The initial secret name defaults to
adhoc_key_secret; each user can point it at a different secret under Settings → Remote SSH. The connection card discovers the user's valid host-only SSH private-key secrets and lets the user select a different key without changing that global default. - The user's key is the only identity an ad-hoc host is offered: the server's key files and ssh-agent and password fallback are all skipped, and the tools take no
key_path(a key file is a server path). An ad-hoc connection acts as the user, never as Codumentor. - Pre-configured
hostsare unaffected: they keep the operator's auth.
The default: a passphrase-protected key the user unlocks
With adhoc_auth: encrypted_user_key (the default) the stored key must be
passphrase-protected, and an SSH session cannot start without the user:
- The tool call is approved as usual (
remote_ssh.exec, …). - It then shows a Connect over SSH card with the destination, a key selector, a passphrase field, Unlock and connect, and Cancel, and waits (up to
unlock_timeout). Changing keys clears the passphrase field. The passphrase is sent to the server in the request body only; it is never stored, logged or put on an event, and decryption runs off the event loop. Cancel ends this SSH request, not the whole turn. The agent must respect the cancellation rather than automatically retrying it. - Once unlocked, the call carries on by itself (the model does not retry), and the key stays unlocked for that conversation for
unlock_ttlseconds — other conversations ask again, and evicting the conversation forgets it. Parallel calls share one prompt; five wrong passphrases fail the call.
So an "always allow" rule, Auto mode or bypass mode can approve the call, but
none of them can unlock the key. Only the web UI shows the card: TUI,
messaging (Telegram/Slack) and unattended runs fail the call with a message
saying the key must be unlocked in the web UI. For those, an operator can choose
adhoc_auth: user_key (an unprotected user key also works) or, on a single-user
install, server. A key without a passphrase under the default policy is
refused with a message asking for a protected one.
Key selection and remembering successful connections
The selector includes valid SSH private keys stored as the user's host-only
User Secrets, including a key also used for SCM Push. Candidate names are
validated on the server; selecting a key never exposes its value to the model
or browser, and does not overwrite the user's default setting.
If the server rejects authentication, the same call asks the user to choose
another key. Network errors, host-key failures, and errors from an already
started command do not trigger credential selection. There is no automatic
probing of all keys. Pooled connections distinguish the selected key identity.
After successful authentication, the server remembers the choice for this
conversation and destination. The browser also saves only the secret name
in localStorage, scoped to the signed-in user, hostname, port, and SSH username,
so later sessions can preselect it. Unlocking alone does not save a preference.
The remembered name must still appear in the server-provided candidate list,
and is never submitted automatically. No private key or passphrase is stored
in localStorage. Clearing browser storage forgets the browser preference;
other browsers have independent preferences. Secret names and destinations are
metadata visible to scripts running on the same origin.
With no key at all, an ad-hoc call is refused with a message naming the secret
to add. adhoc_auth: server restores the old behaviour (server keys/agent) for
single-user installs, where the server's identity is the user's.
Host key verification
For a preconfigured host the default (host_key_policy: known_hosts) uses the OpenSSH known_hosts files of the account running Codumentor (~/.ssh/known_hosts). The first connection to an unknown host fails, saying so, until that host is in those files.
trust_first records the host key in known_hosts_path on first connect and verifies it afterwards (TOFU); the first call's result names the trusted key's SHA256 fingerprint. A later key mismatch is refused — nothing in a conversation can accept it, since whoever intercepts the connection could talk the agent into that. If the change is expected (server reinstalled), an operator removes the host's line from known_hosts_path. disabled skips verification entirely.
Ad-hoc hosts use adhoc_host_key_policy, trust_first by default: a server install usually has no ~/.ssh/known_hosts, so known_hosts would refuse every ad-hoc host.
User settings
Users can override three settings in the Web UI (Settings → Remote SSH):
- Enable Remote SSH — turn off all SSH tools for their account
- Allow ad-hoc connections — restrict their account to pre-configured hosts even if the server allows ad-hoc
- SSH key secret for ad-hoc connections — which of their User Secrets holds their ad-hoc SSH key (blank = the configured
adhoc_key_secret)
Notes
- Connections are pooled per conversation and closed when the session ends, or after
idle_timeout. Parallel calls to the same host share one connection. ssh_execruns commands with stdin at end-of-file: a command that waits for input (asudopassword prompt) ends instead of hanging until the timeout. On timeout the output printed so far is returned.ssh_execcarries the working directory between calls to the same host (per conversation and login): each command starts where the previous one ended, and every result showscwd:. Environment variables do not carry over — chain them (source .venv/bin/activate && …). It is done by wrapping the command in a POSIX-shellcd/trap EXITprologue, not by a long-lived shell, so a hung or interactive command cannot wedge later calls; a host whose login shell is not POSIX-compatible (fish, csh) cannot run it.ssh_downloadwithoutlocal_pathreads at mostmax_output_sizebytes of a file into the conversation and tells text from binary by its content.hostis never looked up in an~/.ssh/config: for an alias defined there, pass itsHostNameandUser. An unresolvable host's error says so.- Auth is key-based (the user's key secret for ad-hoc hosts; otherwise configured key, default keys, or agent). The only prompt is the ad-hoc key card above; preconfigured hosts get no password/passphrase prompt.