mcp-ssh-manager 3.8.6 → 3.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +24 -0
- package/package.json +6 -4
- package/server.json +2 -2
- package/skills/ssh-manager/SKILL.md +80 -0
- package/src/backup-manager.js +46 -0
- package/src/config-loader.js +5 -0
- package/src/index.js +20 -5
- package/src/ssh-manager.js +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,42 @@ All notable changes to MCP SSH Manager will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.8.7] - 2026-10-25
|
|
9
|
+
|
|
10
|
+
### Security
|
|
11
|
+
|
|
12
|
+
Two advisories, both reported to us. **Upgrade.**
|
|
13
|
+
|
|
14
|
+
- **A partial server name or an alias escaped `readonly` and `restricted`
|
|
15
|
+
mode** (GHSA-mq9f-5385-rjf4, high, reported by @nikhilagrawalsf). The policy
|
|
16
|
+
looked a server up by its exact name, while the connection resolved aliases,
|
|
17
|
+
case, a unique part of a name and host matches. So `"p"` instead of `"prod"`,
|
|
18
|
+
an alias the agent had just created with `ssh_alias`, or the host itself
|
|
19
|
+
found no policy — unrestricted — and the command then ran on the protected
|
|
20
|
+
server. The policy now resolves the name exactly as the connection does; an
|
|
21
|
+
ambiguous name is refused by both. A session keeps the server's own name, not
|
|
22
|
+
what was typed to open it.
|
|
23
|
+
- **Remote command execution through `ssh_backup_restore`'s `backupId`**
|
|
24
|
+
(GHSA-2wjh-xm9c-7qf9, high, reported by @NYBaywatch). The metadata path built
|
|
25
|
+
from it went to the server inside `cat "…"`, where `$(…)` and backticks still
|
|
26
|
+
run — through a tool that was only meant to restore. `ssh_backup_create`'s
|
|
27
|
+
`mkdir -p "…"` had the same flaw with `backupDir`, the half of
|
|
28
|
+
GHSA-qwwm-vrm9-4mw8 the earlier fix missed. Both are quoted now, a backup ID
|
|
29
|
+
must be a plain file name (no separator, no `..`, no control character), and
|
|
30
|
+
a test fails if any remote command in `index.js` splices a value inside double
|
|
31
|
+
quotes again.
|
|
32
|
+
- Dependencies: `zod` 4.6.7, `body-parser` 2.4.0, `fast-uri` 3.1.9,
|
|
33
|
+
`ip-address` 10.7.5, for the advisories published since 3.8.6.
|
|
34
|
+
`npm audit` is clean.
|
|
35
|
+
|
|
36
|
+
### Added
|
|
37
|
+
|
|
38
|
+
- **Per-server OpenSSH user certificates: `CERTPATH` / `cert_path`.** The
|
|
39
|
+
certificate is passed to `ssh2` as `publicKey` next to `privateKey`, read on
|
|
40
|
+
every connection (renewed short-lived certificates need no restart), and a
|
|
41
|
+
missing file fails the connection. Needs an `ssh2` release with certificate
|
|
42
|
+
support (mscdex/ssh2#1495); with `ssh2` 1.17.0 the option has no effect.
|
|
43
|
+
|
|
8
44
|
## [3.8.6] - 2026-10-08
|
|
9
45
|
|
|
10
46
|
### Security
|
package/README.md
CHANGED
|
@@ -738,6 +738,7 @@ SSH_SERVER_[NAME]_HOST=hostname_or_ip
|
|
|
738
738
|
SSH_SERVER_[NAME]_USER=username
|
|
739
739
|
SSH_SERVER_[NAME]_PASSWORD=password # For password auth
|
|
740
740
|
SSH_SERVER_[NAME]_KEYPATH=~/.ssh/key # For SSH key auth
|
|
741
|
+
SSH_SERVER_[NAME]_CERTPATH=~/.ssh/key-cert.pub # Optional: OpenSSH user certificate for KEYPATH (needs ssh2 with certificate support; see SSH Certificates)
|
|
741
742
|
SSH_SERVER_[NAME]_PASSPHRASE=key_passphrase # Optional, for passphrase-protected keys
|
|
742
743
|
SSH_SERVER_[NAME]_PORT=22 # Optional, defaults to 22
|
|
743
744
|
SSH_SERVER_[NAME]_DEFAULT_DIR=/path/to/dir # Optional, default working directory
|
|
@@ -896,6 +897,29 @@ forward_agent = true
|
|
|
896
897
|
|
|
897
898
|
> ⚠️ **Security warning:** agent forwarding lets any process that can read the forwarded agent socket on the remote host — including anyone with **root** there — use your loaded keys to impersonate you against other hosts *for the life of the connection*. Only enable it for servers you trust, mirroring the same caution `ssh_config(5)` advises for `ForwardAgent`.
|
|
898
899
|
|
|
900
|
+
### 📜 SSH User Certificates
|
|
901
|
+
|
|
902
|
+
If your servers trust an OpenSSH certificate authority (`TrustedUserCAKeys` in `sshd_config`), point `CERTPATH` at the certificate signed for `KEYPATH` (usually `<key>-cert.pub`). The certificate is sent as the identity and the private key signs, like `ssh -i key -o CertificateFile=key-cert.pub`.
|
|
903
|
+
|
|
904
|
+
`.env` format:
|
|
905
|
+
```env
|
|
906
|
+
SSH_SERVER_MYSERVER_KEYPATH=~/.ssh/id_ed25519
|
|
907
|
+
SSH_SERVER_MYSERVER_CERTPATH=~/.ssh/id_ed25519-cert.pub
|
|
908
|
+
```
|
|
909
|
+
|
|
910
|
+
TOML format:
|
|
911
|
+
```toml
|
|
912
|
+
[ssh_servers.myserver]
|
|
913
|
+
key_path = "~/.ssh/id_ed25519"
|
|
914
|
+
cert_path = "~/.ssh/id_ed25519-cert.pub"
|
|
915
|
+
```
|
|
916
|
+
|
|
917
|
+
- The certificate file is read on every connection, so a short-lived certificate renewed on disk is used on the next connection without restarting the server.
|
|
918
|
+
- If `CERTPATH` is set and the file is missing, the connection fails instead of falling back to the bare key.
|
|
919
|
+
- `CERTPATH` is ignored without `KEYPATH`. Without `CERTPATH` nothing changes.
|
|
920
|
+
- **Requires an `ssh2` release with certificate support** ([mscdex/ssh2#1495](https://github.com/mscdex/ssh2/pull/1495)). With `ssh2` 1.17.0 the option is ignored and the plain key is offered.
|
|
921
|
+
- `ssh_sync` uses the system `rsync`/`ssh` and does not use `CERTPATH` yet; OpenSSH picks up `<key>-cert.pub` next to the key on its own.
|
|
922
|
+
|
|
899
923
|
## 📚 Advanced Usage
|
|
900
924
|
|
|
901
925
|
### ProxyJump / Bastion Host
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-ssh-manager",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.7",
|
|
4
4
|
"mcpName": "io.github.bvisible/mcp-ssh-manager",
|
|
5
5
|
"description": "MCP SSH Manager: Model Context Protocol server for SSH remote server management. Control SSH connections from Claude Code and OpenAI Codex - execute commands, transfer files, database operations, backups, health monitoring, and DevOps automation. NEW: Tool activation system reduces context usage by 92%",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"setup": "npm install && pip install -r tools/requirements.txt",
|
|
15
15
|
"configure": "python tools/server-manager.py",
|
|
16
16
|
"test-connection": "python tools/test-connection.py",
|
|
17
|
-
"test": "npm run test:lockfile && npm run test:sudostdin && npm run test:redaction && npm run test:profiles && npm run test:aliases && npm run test:hooks && npm run test:hostkeys && npm run test:tools && npm run test:policy && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:groups && npm run test:agentforward && npm run test:lifecycle && npm run test:tunnel && npm run test:sync && npm run test:sync-path && npm run test:dbquoting && npm run test:dbinjection && npm run test:backupinjection && npm run test:dbrowcount && npm run test:cli-edit",
|
|
17
|
+
"test": "npm run test:lockfile && npm run test:sudostdin && npm run test:redaction && npm run test:profiles && npm run test:aliases && npm run test:hooks && npm run test:hostkeys && npm run test:tools && npm run test:policy && npm run test:policynames && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:groups && npm run test:agentforward && npm run test:certpath && npm run test:lifecycle && npm run test:tunnel && npm run test:sync && npm run test:sync-path && npm run test:dbquoting && npm run test:dbinjection && npm run test:backupinjection && npm run test:dbrowcount && npm run test:cli-edit",
|
|
18
18
|
"test:lockfile": "node tests/test-lockfile.js",
|
|
19
19
|
"test:sudostdin": "node tests/test-sudo-stdin.js",
|
|
20
20
|
"test:redaction": "node tests/test-logger-redaction.js",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"test:fieldnames": "node tests/test-config-field-names.js",
|
|
30
30
|
"test:groups": "node tests/test-server-groups.js",
|
|
31
31
|
"test:agentforward": "node tests/test-agent-forward.js",
|
|
32
|
+
"test:certpath": "node tests/test-cert-path.js",
|
|
32
33
|
"test:lifecycle": "node tests/test-lifecycle.js",
|
|
33
34
|
"test:tunnel": "node tests/test-tunnel-listen.js",
|
|
34
35
|
"test:sync": "node tests/test-sync-stats.js",
|
|
@@ -42,7 +43,8 @@
|
|
|
42
43
|
"validate": "./scripts/validate.sh",
|
|
43
44
|
"typecheck": "tsc -p tsconfig.json",
|
|
44
45
|
"lint": "eslint src/*.js",
|
|
45
|
-
"format": "prettier --write 'src/**/*.js' 'tests/**/*.js'"
|
|
46
|
+
"format": "prettier --write 'src/**/*.js' 'tests/**/*.js'",
|
|
47
|
+
"test:policynames": "node tests/test-policy-name-resolution.js"
|
|
46
48
|
},
|
|
47
49
|
"keywords": [
|
|
48
50
|
"mcp",
|
|
@@ -98,7 +100,7 @@
|
|
|
98
100
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
99
101
|
"dotenv": "^16.4.5",
|
|
100
102
|
"ssh2": "^1.17.0",
|
|
101
|
-
"zod": "^4.
|
|
103
|
+
"zod": "^4.6.7"
|
|
102
104
|
},
|
|
103
105
|
"devDependencies": {
|
|
104
106
|
"eslint": "^8.56.0",
|
package/server.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
"url": "https://github.com/bvisible/mcp-ssh-manager",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "3.8.
|
|
9
|
+
"version": "3.8.7",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "mcp-ssh-manager",
|
|
14
|
-
"version": "3.8.
|
|
14
|
+
"version": "3.8.7",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ssh-manager
|
|
3
|
+
description: |
|
|
4
|
+
How to use the MCP SSH Manager core tools (ssh_list_servers, ssh_execute, ssh_upload,
|
|
5
|
+
ssh_download, ssh_sync) without breaking a server: server names, the remote shell, time
|
|
6
|
+
limits and long commands, file transfer pitfalls, security modes, host keys. Use it whenever
|
|
7
|
+
a task runs a command or moves a file on a remote machine through these tools.
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Using the SSH Manager tools
|
|
11
|
+
|
|
12
|
+
This skill covers the five **core** tools, the ones exposed in the default `minimal` mode. If
|
|
13
|
+
more groups are enabled (`ssh-manager tools list`), prefer the specific tool over a raw command.
|
|
14
|
+
|
|
15
|
+
| Tool | What it does | Changes the server? |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| `ssh_list_servers` | Lists configured servers: name, host, user, port, auth type, default directory, group. Never returns secrets. | no |
|
|
18
|
+
| `ssh_execute` | Runs one command line, returns `stdout`, `stderr`, `code`. | depends on the command |
|
|
19
|
+
| `ssh_upload` | Copies ONE local file over SFTP, overwriting the target. No backup, no sudo. | yes |
|
|
20
|
+
| `ssh_download` | Copies ONE remote file to a local path (overwrites the local file). | no |
|
|
21
|
+
| `ssh_sync` | rsync over SSH. One side `local:`, the other `remote:`. `dryRun` previews, `delete` removes extras at the destination. | yes |
|
|
22
|
+
|
|
23
|
+
## Before the first command
|
|
24
|
+
|
|
25
|
+
- Call `ssh_list_servers` once and use the exact names. A name is lowercase and every character
|
|
26
|
+
that is not a letter or a digit became `_` (`my-site.ch` → `my_site_ch`). Several names can
|
|
27
|
+
share one host with different users: take the user with the rights you need and no more.
|
|
28
|
+
- `ssh_execute` runs `cd -- '<cwd, or the server's default directory>' && <your command>`.
|
|
29
|
+
Pass `cwd` when the default is wrong. A missing directory fails the whole call.
|
|
30
|
+
- A server can be in `readonly` mode (destructive commands and uploads refused) or `restricted`
|
|
31
|
+
mode (only commands matching its patterns). A refusal is the configuration working: do not
|
|
32
|
+
look for a way around it, ask whoever owns the server.
|
|
33
|
+
|
|
34
|
+
## Writing the command
|
|
35
|
+
|
|
36
|
+
- Assume the remote shell is `sh`/`dash`, not bash: no `<(…)`, no `[[ … ]]`, no arrays, no
|
|
37
|
+
`{a,b}`, no `$'…'`. A syntax error aborts the whole line **before any part of it ran**. Pipe
|
|
38
|
+
instead, or wrap in `bash -c '…'`.
|
|
39
|
+
- Heredocs work (`<<'EOF'`). Quote the delimiter so nothing is expanded by the remote shell.
|
|
40
|
+
- Chain with `&&` when step two must not run after a failure.
|
|
41
|
+
- `pgrep -f` and `pkill -f` match every command line, including the shell that carries your
|
|
42
|
+
command. Bracket one letter (`pgrep -f '[n]ginx -g'`) and kill in one call, relaunch in the next.
|
|
43
|
+
- Never put a password or token in the command line: it ends up in the remote process list and in
|
|
44
|
+
logs. Use a file with mode 600 or an environment variable set on the remote side.
|
|
45
|
+
|
|
46
|
+
## Time limits and long commands
|
|
47
|
+
|
|
48
|
+
- Default timeout 120 s, maximum 300 s (`timeout`, in ms). In practice a call can be cut after
|
|
49
|
+
about three minutes. A command killed halfway leaves its work half done.
|
|
50
|
+
- Anything long or that restarts a service (builds, migrations, big copies, restarts): start it
|
|
51
|
+
detached and poll with short calls.
|
|
52
|
+
`setsid nohup <command> > ~/job.log 2>&1 &` then `tail -n 20 ~/job.log`.
|
|
53
|
+
Never run a service restart straight inside `ssh_execute`: if the call is cut, the restart stops
|
|
54
|
+
halfway and workers stay stopped.
|
|
55
|
+
- `ssh_sync` has its own timeout, 30 s by default: raise it for a big tree.
|
|
56
|
+
|
|
57
|
+
## Moving files
|
|
58
|
+
|
|
59
|
+
- `ssh_upload` replaces the target completely. On a directory other people edit (a shared git tree),
|
|
60
|
+
never upload a whole file over an existing one: you silently revert what changed in it since
|
|
61
|
+
your copy. Apply a targeted edit on the remote, or upload to your own directory.
|
|
62
|
+
- For trees, run `ssh_sync` with `dryRun: true` first and read the list. Never `delete: true`
|
|
63
|
+
without having read it.
|
|
64
|
+
- To read a big file (a log, a dump), `ssh_download` it instead of `cat` inside `ssh_execute`.
|
|
65
|
+
|
|
66
|
+
## Host keys and secrets
|
|
67
|
+
|
|
68
|
+
- Hosts are checked against `known_hosts`: a changed key is refused. A rebuilt server legitimately
|
|
69
|
+
changes its key, but never accept it blindly: compare the new key seen from two machines
|
|
70
|
+
(`ssh-keyscan` from yours and from another trusted host), then replace the old line.
|
|
71
|
+
- Prefer key authentication. Password servers need `sshpass` locally for `ssh_sync`.
|
|
72
|
+
- The configuration file (`~/.ssh-manager/.env`) holds passwords and key paths: never print it
|
|
73
|
+
and never paste it in a message.
|
|
74
|
+
|
|
75
|
+
## Good habits
|
|
76
|
+
|
|
77
|
+
- Look before you change (`ls -la`, `git status`, `systemctl status`) and use read-only calls to find
|
|
78
|
+
out what is wrong before restarting anything.
|
|
79
|
+
- Do not retry a destructive command that failed until you know why it failed.
|
|
80
|
+
- When you report back, name the servers you touched and the commands that changed something.
|
package/src/backup-manager.js
CHANGED
|
@@ -37,6 +37,52 @@ export function getBackupMetadataPath(backupId, backupDir = DEFAULT_BACKUP_DIR)
|
|
|
37
37
|
return path.join(backupDir, `${backupId}.meta.json`);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Refuse a backup ID that is not one.
|
|
42
|
+
*
|
|
43
|
+
* GHSA-2wjh-xm9c-7qf9: ssh_backup_restore took `backupId` from the caller and
|
|
44
|
+
* spliced the path built from it into `cat "…"`, where `$(...)` and backticks
|
|
45
|
+
* still run — remote code execution through a tool that was only meant to
|
|
46
|
+
* restore. Quoting (buildReadMetadataCommand) is the fix; this is the second
|
|
47
|
+
* wall. An ID is a file name inside the backup directory, so a path separator,
|
|
48
|
+
* a `..` segment or a control character can only mean somebody is reaching
|
|
49
|
+
* elsewhere. Spaces and dots stay allowed: IDs carry the backup's name, and a
|
|
50
|
+
* name that worked before must still restore.
|
|
51
|
+
*
|
|
52
|
+
* @param {unknown} backupId - As the caller sent it
|
|
53
|
+
* @returns {string} The same ID, known to be a plain file name
|
|
54
|
+
*/
|
|
55
|
+
export function assertSafeBackupId(backupId) {
|
|
56
|
+
const id = String(backupId ?? '');
|
|
57
|
+
// eslint-disable-next-line no-control-regex
|
|
58
|
+
if (!id || /[/\\\u0000-\u001f\u007f]/.test(id) || id === '.' || id === '..') {
|
|
59
|
+
throw new Error(`Invalid backup ID: ${JSON.stringify(id)}`);
|
|
60
|
+
}
|
|
61
|
+
return id;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Build the command that reads a backup's metadata (ssh_backup_restore).
|
|
66
|
+
* @param {string} backupId - Checked with assertSafeBackupId
|
|
67
|
+
* @param {string} [backupDir]
|
|
68
|
+
* @returns {string}
|
|
69
|
+
*/
|
|
70
|
+
export function buildReadMetadataCommand(backupId, backupDir = DEFAULT_BACKUP_DIR) {
|
|
71
|
+
return `cat ${shellQuote(getBackupMetadataPath(assertSafeBackupId(backupId), backupDir))}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Build the command that makes sure the backup directory exists
|
|
76
|
+
* (ssh_backup_create). Quoted like every other use of the directory: the
|
|
77
|
+
* inline `mkdir -p "…"` it replaces was the half of GHSA-qwwm-vrm9-4mw8 that
|
|
78
|
+
* the 3.8.x fix missed.
|
|
79
|
+
* @param {string} [backupDir]
|
|
80
|
+
* @returns {string}
|
|
81
|
+
*/
|
|
82
|
+
export function buildEnsureBackupDirCommand(backupDir = DEFAULT_BACKUP_DIR) {
|
|
83
|
+
return `mkdir -p ${shellQuote(backupDir)}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
40
86
|
/**
|
|
41
87
|
* Get backup file path
|
|
42
88
|
*/
|
package/src/config-loader.js
CHANGED
|
@@ -23,6 +23,7 @@ import { VALID_MODES } from './policy.js';
|
|
|
23
23
|
* @property {string} [user] SSH user.
|
|
24
24
|
* @property {string} [password] Password for password authentication.
|
|
25
25
|
* @property {string} [keyPath] Path to the private key (`KEYPATH` / `key_path`).
|
|
26
|
+
* @property {string} [certPath] OpenSSH user certificate for keyPath (`CERTPATH` / `cert_path`).
|
|
26
27
|
* @property {string} [passphrase] Passphrase for a protected private key.
|
|
27
28
|
* @property {number} [port] TCP port; defaults to 22.
|
|
28
29
|
* @property {string} [defaultDir] Working directory used when a tool omits `cwd`.
|
|
@@ -178,6 +179,7 @@ export class ConfigLoader {
|
|
|
178
179
|
user: serverConfig.user || serverConfig.username,
|
|
179
180
|
password: serverConfig.password,
|
|
180
181
|
keyPath: serverConfig.key_path || serverConfig.keypath || serverConfig.ssh_key,
|
|
182
|
+
certPath: serverConfig.cert_path,
|
|
181
183
|
passphrase: serverConfig.passphrase,
|
|
182
184
|
port: serverConfig.port || 22,
|
|
183
185
|
defaultDir: serverConfig.default_dir || serverConfig.default_directory || serverConfig.cwd,
|
|
@@ -251,6 +253,7 @@ export class ConfigLoader {
|
|
|
251
253
|
user: env[`SSH_SERVER_${match[1]}_USER`],
|
|
252
254
|
password: env[`SSH_SERVER_${match[1]}_PASSWORD`],
|
|
253
255
|
keyPath: env[`SSH_SERVER_${match[1]}_KEYPATH`],
|
|
256
|
+
certPath: env[`SSH_SERVER_${match[1]}_CERTPATH`],
|
|
254
257
|
passphrase: env[`SSH_SERVER_${match[1]}_PASSPHRASE`],
|
|
255
258
|
port: parseInt(env[`SSH_SERVER_${match[1]}_PORT`] || '22'),
|
|
256
259
|
defaultDir: env[`SSH_SERVER_${match[1]}_DEFAULT_DIR`],
|
|
@@ -317,6 +320,7 @@ export class ConfigLoader {
|
|
|
317
320
|
|
|
318
321
|
if (server.password) serverConfig.password = server.password;
|
|
319
322
|
if (server.keyPath) serverConfig.key_path = server.keyPath;
|
|
323
|
+
if (server.certPath) serverConfig.cert_path = server.certPath;
|
|
320
324
|
if (server.passphrase) serverConfig.passphrase = server.passphrase;
|
|
321
325
|
if (server.defaultDir) serverConfig.default_dir = server.defaultDir;
|
|
322
326
|
if (server.sudoPassword) serverConfig.sudo_password = server.sudoPassword;
|
|
@@ -359,6 +363,7 @@ export class ConfigLoader {
|
|
|
359
363
|
lines.push(`SSH_SERVER_${upperName}_USER=${server.user}`);
|
|
360
364
|
if (server.password) lines.push(`SSH_SERVER_${upperName}_PASSWORD="${server.password}"`);
|
|
361
365
|
if (server.keyPath) lines.push(`SSH_SERVER_${upperName}_KEYPATH=${server.keyPath}`);
|
|
366
|
+
if (server.certPath) lines.push(`SSH_SERVER_${upperName}_CERTPATH=${server.certPath}`);
|
|
362
367
|
if (server.passphrase) lines.push(`SSH_SERVER_${upperName}_PASSPHRASE="${server.passphrase}"`);
|
|
363
368
|
lines.push(`SSH_SERVER_${upperName}_PORT=${server.port || 22}`);
|
|
364
369
|
if (server.defaultDir) lines.push(`SSH_SERVER_${upperName}_DEFAULT_DIR=${server.defaultDir}`);
|
package/src/index.js
CHANGED
|
@@ -89,6 +89,9 @@ import {
|
|
|
89
89
|
generateBackupId,
|
|
90
90
|
getBackupMetadataPath,
|
|
91
91
|
getBackupFilePath,
|
|
92
|
+
assertSafeBackupId,
|
|
93
|
+
buildReadMetadataCommand,
|
|
94
|
+
buildEnsureBackupDirCommand,
|
|
92
95
|
buildMySQLDumpCommand,
|
|
93
96
|
buildPostgreSQLDumpCommand,
|
|
94
97
|
buildMongoDBDumpCommand,
|
|
@@ -268,7 +271,13 @@ async function loadServerConfig() {
|
|
|
268
271
|
async function getServerConfig(serverName) {
|
|
269
272
|
if (!serverName) return null;
|
|
270
273
|
const servers = await loadServerConfig();
|
|
271
|
-
|
|
274
|
+
// The same resolution getConnection() applies: aliases, case, a unique part
|
|
275
|
+
// of a name, a host match. This used to be an exact-key lookup, so "p" or a
|
|
276
|
+
// freshly added alias found no configuration here — no policy, unrestricted —
|
|
277
|
+
// while the connection resolved it to the readonly "prod" and ran the command
|
|
278
|
+
// there (GHSA-mq9f-5385-rjf4). An ambiguous name throws here as it does there.
|
|
279
|
+
const name = resolveServerName(String(serverName), servers);
|
|
280
|
+
return (name && servers[String(name).toLowerCase()]) || null;
|
|
272
281
|
}
|
|
273
282
|
|
|
274
283
|
// Apply policy + audit a denial in one shot. Returns null when allowed; returns
|
|
@@ -1645,7 +1654,11 @@ registerToolConditional(
|
|
|
1645
1654
|
async ({ server: serverName, name }) => {
|
|
1646
1655
|
try {
|
|
1647
1656
|
const ssh = await getConnection(serverName);
|
|
1648
|
-
|
|
1657
|
+
// The session keeps the server's own name, not what the caller typed: a
|
|
1658
|
+
// partial name or an alias resolved now must not resolve to another
|
|
1659
|
+
// server, or to none, for every command sent later (GHSA-mq9f-5385-rjf4).
|
|
1660
|
+
const canonical = resolveServerName(serverName, await loadServerConfig()) || serverName;
|
|
1661
|
+
const session = await createSession(canonical, ssh);
|
|
1649
1662
|
|
|
1650
1663
|
const sessionName = name || `Session on ${serverName}`;
|
|
1651
1664
|
|
|
@@ -3461,7 +3474,7 @@ registerToolConditional(
|
|
|
3461
3474
|
const metadataPath = getBackupMetadataPath(backupId, backupDirectory);
|
|
3462
3475
|
|
|
3463
3476
|
// Ensure backup directory exists with proper error handling
|
|
3464
|
-
const mkdirResult = await ssh.execCommand(
|
|
3477
|
+
const mkdirResult = await ssh.execCommand(buildEnsureBackupDirCommand(backupDirectory));
|
|
3465
3478
|
if (mkdirResult.code !== 0) {
|
|
3466
3479
|
throw new Error(`Failed to create backup directory: ${mkdirResult.stderr || mkdirResult.stdout}`);
|
|
3467
3480
|
}
|
|
@@ -3732,12 +3745,14 @@ registerToolConditional(
|
|
|
3732
3745
|
if (denied) return denied;
|
|
3733
3746
|
|
|
3734
3747
|
try {
|
|
3748
|
+
// Checked before anything connects: an ID that is not a plain file name
|
|
3749
|
+
// is refused outright, and the one that passes is still quoted.
|
|
3750
|
+
assertSafeBackupId(backupId);
|
|
3735
3751
|
const ssh = await getConnection(serverName);
|
|
3736
3752
|
const backupDirectory = backupDir || DEFAULT_BACKUP_DIR;
|
|
3737
|
-
const metadataPath = getBackupMetadataPath(backupId, backupDirectory);
|
|
3738
3753
|
|
|
3739
3754
|
// Read backup metadata
|
|
3740
|
-
const metadataResult = await ssh.execCommand(
|
|
3755
|
+
const metadataResult = await ssh.execCommand(buildReadMetadataCommand(backupId, backupDirectory));
|
|
3741
3756
|
if (metadataResult.code !== 0) {
|
|
3742
3757
|
throw new Error(`Backup not found: ${backupId}`);
|
|
3743
3758
|
}
|
package/src/ssh-manager.js
CHANGED
|
@@ -142,6 +142,14 @@ class SSHManager {
|
|
|
142
142
|
if (keyPath) {
|
|
143
143
|
const resolvedKeyPath = keyPath.replace('~', os.homedir());
|
|
144
144
|
connConfig.privateKey = fs.readFileSync(resolvedKeyPath);
|
|
145
|
+
// OpenSSH user certificate (<key>-cert.pub): sent to the server as the
|
|
146
|
+
// identity while privateKey signs. Read on every connect, so a renewed
|
|
147
|
+
// short-lived certificate is picked up without restarting the server.
|
|
148
|
+
// Requires an ssh2 release with certificate support (mscdex/ssh2#1495);
|
|
149
|
+
// older ssh2 ignores the unknown option and authenticates with the key.
|
|
150
|
+
if (this.config.certPath) {
|
|
151
|
+
connConfig.publicKey = fs.readFileSync(this.config.certPath.replace('~', os.homedir()));
|
|
152
|
+
}
|
|
145
153
|
if (this.config.passphrase) {
|
|
146
154
|
connConfig.passphrase = this.config.passphrase;
|
|
147
155
|
}
|