Codumentor logo Codumentor Enterprise

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

ParameterTypeDefaultDescription
enabledbooltrueEnable or disable the plugin
target_agentsstring"main"Which agents get the tools: "main", "subagent", or "all"
allow_adhocbooltrueAllow connections to hosts not listed in hosts. A user setting can only narrow this, never lift a false
adhoc_authstring"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_ttlint3600Seconds an unlocked key stays usable in its conversation before the passphrase is asked again
unlock_timeoutint300Seconds a tool call waits for the user to answer the key card
adhoc_key_secretstring"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_policystring"trust_first"host_key_policy for ad-hoc hosts (see Host key verification)
connect_timeoutint15Seconds to establish a connection (TCP, handshake, login) before the call fails
default_timeoutint30Default ssh_exec timeout (seconds)
max_output_sizeint10240Maximum output size per tool call (bytes)
max_download_sizeint104857600Largest file ssh_download saves to the workspace with local_path (bytes)
keepalive_intervalint30SSH keepalive interval (seconds)
idle_timeoutint60Close idle pooled connections after this many seconds
max_connections_per_sessionint5Maximum pooled connections per conversation
known_hosts_pathstring./data/ssh_known_hostsOpenSSH-format file used when a host's host_key_policy is trust_first

Per-host parameters (args.hosts.<alias>)

ParameterTypeDefaultDescription
hostnamestring(required)Hostname or IP
portint22SSH port
usernamestring"root"SSH username
key_pathstringNonePrivate key file. If unset, default keys / ssh-agent are used
host_key_policystring"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

ParameterRequiredDescription
hostYesPre-configured alias, or hostname/IP when ad-hoc is allowed
commandYesShell command to run
usernameNoAd-hoc username (pre-configured hosts use their config)
portNoAd-hoc SSH port (default 22)
timeoutNoCommand timeout in seconds

ssh_upload / ssh_download

ParameterRequiredDescription
hostYesAlias or hostname/IP
local_pathYes (upload)Workspace file, resolved and read like read_file (through the sandbox under isolation) — never a raw server path
remote_pathYesPath 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_pathNo (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 / portNoSame 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 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:

  1. The tool call is approved as usual (remote_ssh.exec, …).
  2. 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.
  3. Once unlocked, the call carries on by itself (the model does not retry), and the key stays unlocked for that conversation for unlock_ttl seconds — 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):

Notes