mcp-ssh-manager 3.4.0 → 3.5.0

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.
@@ -124,7 +124,7 @@
124
124
  {
125
125
  "type": "notification",
126
126
  "name": "use-context",
127
- "command": "echo \"Server: {server}, Error: {error}\" > /Users/jeremy/mcp/mcp-ssh-manager/context-test.txt"
127
+ "command": "echo \"Server: {server}, Error: {error}\" > /tmp/mcp-ssh-manager-context-test.txt"
128
128
  }
129
129
  ]
130
130
  }
package/CHANGELOG.md CHANGED
@@ -5,6 +5,39 @@ 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.5.0] - 2026-05-18
9
+
10
+ ### Added
11
+
12
+ - **Per-server security modes** — opt-in second authorization layer that filters tool invocations and commands *inside* the MCP server, complementing the existing client-side `autoApprove` mechanism. Useful when sharing the MCP with a third-party agent, a CI bot, or any context where you can't fully trust the client. See [docs/SECURITY_MODES.md](docs/SECURITY_MODES.md).
13
+ - New per-server fields (env: `SSH_SERVER_<N>_MODE`, `SSH_SERVER_<N>_ALLOW_PATTERNS`, `SSH_SERVER_<N>_DENY_PATTERNS`, `SSH_SERVER_<N>_AUDIT_LOG` — TOML: `mode`, `allow_patterns`, `deny_patterns`, `audit_log`).
14
+ - Three modes: `unrestricted` (default — identical to v3.4.x), `readonly` (blocks mutating tools + built-in destructive command denylist), `restricted` (require regex allowlist + optional denylist, DENY wins over ALLOW).
15
+ - Gated tools: `ssh_execute`, `ssh_execute_sudo`, `ssh_execute_group`, `ssh_session_send` (command-aware), `ssh_upload`, `ssh_sync`, `ssh_deploy`, `ssh_backup_create`, `ssh_backup_restore`, `ssh_backup_schedule`, `ssh_db_import`, `ssh_db_dump` (tool-level), plus action-gated `ssh_key_manage` (accept/remove), `ssh_alert_setup` (set), `ssh_process_manager` (kill).
16
+ - Command aliases (`ssh_command_alias`) are expanded **before** policy evaluation, so the denylist can't be bypassed via an alias.
17
+ - **Audit log** — opt-in JSONL trail per server (set `SSH_SERVER_<N>_AUDIT_LOG` to a file path). Records `ts`, `server`, `tool`, sanitized `args`, `allowed`, `reason` (on denial), `exitCode`/`success`/`error` (on execution). Credentials (`password`, `passphrase`, `sudoPassword`, `token`, `secret`, `apikey`) are redacted to `***` even if a tool passes them through args. No log rotation built-in — use `logrotate`.
18
+ - **Interactive wizard prompts** (`ssh-manager server add`) for the three new fields, each with default = skip. Pressing Enter on all three produces an `.env` block identical to v3.4.x output.
19
+ - **New test suite** `tests/test-policy.js` — 26 tests covering the three modes, DENY > ALLOW precedence, invalid regex handling, secret redaction, fail-closed for unknown modes, backward-compat fast path.
20
+
21
+ ### Backward compatibility
22
+
23
+ - **Zero impact on existing configs.** A v3.4.x `.env` or TOML file loads identically — no `MODE` field means `unrestricted`, and `evaluatePolicy()` early-returns `{ allowed: true }` without compiling a single regex.
24
+ - No new field is mandatory.
25
+ - The audit log file is never created unless `AUDIT_LOG` is explicitly set.
26
+ - `autoApprove` on the Claude Code side keeps working unchanged — the policy intercepts after the client approves, before the SSH command runs, so the client never sees a new prompt.
27
+ - All pre-existing tests (`test-profiles`, `test-command-aliases`, `test-hooks`, `test-tool-registry` — 13 tests) pass without modification.
28
+
29
+ ## [3.4.1] - 2026-05-16
30
+
31
+ ### Fixed
32
+
33
+ - **SSH handshake failing against OpenSSH 9.x servers (Debian 12 / Ubuntu 24.04)** ([#32](https://github.com/bvisible/mcp-ssh-manager/pull/32) — thanks @YoungHong1992)
34
+ - The hardcoded algorithm list in `src/ssh-manager.js` was missing modern algorithms required by OpenSSH 9.x. The `ssh2` lib would fail the key-exchange phase against stock Debian 12 / Ubuntu 24.04 servers because no common KEX algorithm could be negotiated.
35
+ - **KEX** — added `curve25519-sha256`, `curve25519-sha256@libssh.org`, `diffie-hellman-group15-sha512`, `diffie-hellman-group16-sha512`. `curve25519-sha256` is now OpenSSH's preferred default since 6.5.
36
+ - **Server host key** — added `rsa-sha2-512` and `rsa-sha2-256` (RFC 8332). OpenSSH 8.2+ deprecates the SHA-1-based `ssh-rsa` signature algorithm in the default offer; without SHA-2 variants, RSA host keys could no longer be verified.
37
+ - **Cipher** — added `aes128-gcm@openssh.com` and `aes256-gcm@openssh.com` at the head of the list (preferred GCM variants on modern OpenSSH; the plain `aes*-gcm` names were already present but are not what OpenSSH advertises).
38
+ - **HMAC** — added `hmac-sha2-256-etm@openssh.com`, `hmac-sha2-512-etm@openssh.com`, `hmac-sha1-etm@openssh.com`. Encrypt-then-MAC is both faster and cryptographically stronger than encrypt-and-MAC; OpenSSH prefers ETM variants when both peers support them.
39
+ - **Fully backward-compatible** — every legacy algorithm previously in the list (`diffie-hellman-group14-sha1`, `ssh-rsa`, CBC ciphers, plain `hmac-sha*`) is preserved at lower preference. Connections to older servers (CentOS 7, Debian 10, AIX, network gear with legacy SSH stacks) continue to work unchanged.
40
+
8
41
  ## [3.4.0] - 2026-05-07
9
42
 
10
43
  ### Added
package/README.md CHANGED
@@ -6,7 +6,7 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
6
6
 
7
7
  [![npm version](https://img.shields.io/npm/v/mcp-ssh-manager.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/mcp-ssh-manager)
8
8
  [![npm downloads](https://img.shields.io/npm/dt/mcp-ssh-manager.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/mcp-ssh-manager)
9
- [![Version](https://img.shields.io/badge/Version-3.4.0-brightgreen?style=for-the-badge)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.4.0)
9
+ [![Version](https://img.shields.io/badge/Version-3.4.1-brightgreen?style=for-the-badge)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.4.1)
10
10
  [![Claude Code](https://img.shields.io/badge/Claude_Code-Compatible-5A67D8?style=for-the-badge&logo=anthropic)](https://claude.ai/code)
11
11
  [![OpenAI Codex](https://img.shields.io/badge/OpenAI_Codex-Compatible-00A67E?style=for-the-badge&logo=openai)](https://openai.com/codex)
12
12
  [![MCP](https://img.shields.io/badge/MCP-Server-orange?style=for-the-badge)](https://modelcontextprotocol.io)
@@ -20,28 +20,30 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
20
20
 
21
21
  ---
22
22
 
23
- ## 🎉 What's New in v3.4.0
23
+ ## 🎉 What's New in v3.4.1
24
24
 
25
- **Full Windows OpenSSH support + shell-agnostic session sync** (Released: May 7, 2026)
25
+ **Modern OpenSSH 9.x compatibility** (Released: May 16, 2026)
26
26
 
27
- - **🪟 Windows OpenSSH targets — encoding & syntax fixes** ([#31](https://github.com/bvisible/mcp-ssh-manager/pull/31))
28
- - **Mojibake fix** — Commands on Windows hosts no longer inherit the OEM code page (CP950, CP932, CP1252…). Payloads are now wrapped as `powershell -NoProfile -OutputFormat Text -EncodedCommand <utf16le-base64>` (the same approach used by Ansible / Chef / Puppet for Windows remote execution), sidestepping every `cmd.exe` quoting and code-page issue
29
- - **`cd && ` syntax fix** — `cd ${workingDir} && ${cmd}` is invalid in `cmd.exe`; replaced with `Set-Location '${escapedDir}'; ${cmd}` (PowerShell-native, with `'` → `''` escaping) across `ssh_execute`, `ssh_execute_group`, and `ssh_execute_sudo`
30
- - Strictly gated behind `platform = "windows"` — Linux/macOS targets take the exact same code path as before, zero risk of regression
31
- - Thanks [@WenKingSu](https://github.com/WenKingSu) for the clean, well-documented patch
32
- - **🎯 Marker-based SSH session sync — replaces fragile prompt detection** ([#30](https://github.com/bvisible/mcp-ssh-manager/pull/30))
33
- - The previous `/[$#>]\s*$/` regex broke on custom prompts, ANSI color codes, multiline prompts, slow shells, `.bashrc` noise, AIX-style login flows — `ssh_session_start` would frequently fail with "Timeout waiting for shell prompt"
34
- - Now uses **UUID v4 markers** as protocol boundaries: each command is wrapped with a unique end marker (`set +e; <cmd>; __mcp_status=$?; printf '\n<marker>:%s\n' "$__mcp_status"`), and the PTY is opened with `ECHO: 0` so the buffer contains only command output
35
- - **Bonus**: sessions now report **real exit codes** captured from `$?` instead of the previous `!output.includes('command not found')` heuristic
36
- - Resolves [#20](https://github.com/bvisible/mcp-ssh-manager/issues/20) and supersedes the proposed configurable `prompt_pattern` approach by making the problem disappear entirely — no per-server config required
37
- - Thanks [@MakksSh](https://github.com/MakksSh) for the precise root-cause analysis and the clean refactor
27
+ - **🔐 Expanded SSH algorithm list — handshake against OpenSSH 9.x out of the box** ([#32](https://github.com/bvisible/mcp-ssh-manager/pull/32))
28
+ - The hardcoded algorithm list in `src/ssh-manager.js` was missing modern algorithms used by **OpenSSH 9.x** servers shipped with **Debian 12** and **Ubuntu 24.04**, causing the `ssh2` lib to fail the key-exchange phase against stock distributions
29
+ - **KEX**: added `curve25519-sha256` (+`@libssh.org`), `diffie-hellman-group15-sha512` and `diffie-hellman-group16-sha512`
30
+ - **Server host key**: added `rsa-sha2-512` and `rsa-sha2-256` (RFC 8332 — required since OpenSSH 8.2 deprecated `ssh-rsa` SHA-1 by default)
31
+ - **Cipher**: added `aes128-gcm@openssh.com` and `aes256-gcm@openssh.com` (preferred GCM variants on modern servers)
32
+ - **HMAC**: added `hmac-sha2-256-etm@openssh.com`, `hmac-sha2-512-etm@openssh.com`, `hmac-sha1-etm@openssh.com` (encrypt-then-MAC — both faster and cryptographically stronger than encrypt-and-MAC)
33
+ - **Backward-compatible by design** — all legacy algorithms (`diffie-hellman-group14-sha1`, `ssh-rsa`, CBC ciphers, plain `hmac-sha*`) are preserved at lower preference, so older servers (CentOS 7, Debian 10…) keep working unchanged
34
+ - Thanks [@YoungHong1992](https://github.com/YoungHong1992) for the well-scoped, well-ordered patch
38
35
 
39
- [Read full changelog →](CHANGELOG.md#340---2026-05-07)
36
+ [Read full changelog →](CHANGELOG.md#341---2026-05-16)
40
37
 
41
38
  ---
42
39
 
43
40
  ## Previous Releases
44
41
 
42
+ ### v3.4.0 - Windows OpenSSH support + shell-agnostic session sync (May 7, 2026)
43
+
44
+ - **🪟 Windows OpenSSH encoding & syntax fixes** — UTF-16LE base64 PowerShell payloads (Ansible-style) + `Set-Location` replacing `cd && ` ([#31](https://github.com/bvisible/mcp-ssh-manager/pull/31), thanks [@WenKingSu](https://github.com/WenKingSu))
45
+ - **🎯 Marker-based SSH session sync** — UUID v4 protocol boundaries with `ECHO: 0` PTY, real `$?` exit codes, no more "Timeout waiting for shell prompt" on custom/slow/AIX shells ([#30](https://github.com/bvisible/mcp-ssh-manager/pull/30), thanks [@MakksSh](https://github.com/MakksSh))
46
+
45
47
  ### v3.3.0 - ProxyCommand & Critical Fixes (May 2, 2026)
46
48
 
47
49
  - **🔌 ProxyCommand support** for SOCKS5 / custom proxy commands ([#24](https://github.com/bvisible/mcp-ssh-manager/pull/24))
@@ -305,6 +307,28 @@ Edit `~/.config/claude-code/claude_code_config.json`:
305
307
 
306
308
  For full auto-approval of all SSH tools, see the complete list in [examples/claude-code-config.example.json](examples/claude-code-config.example.json).
307
309
 
310
+ ### 3.5. Security Modes (Optional, v3.5.0+)
311
+
312
+ `autoApprove` is all-or-nothing per tool: once `ssh_execute` is approved, anything goes. If you want a **second layer** that filters what the MCP server actually accepts to run — useful when sharing the MCP with a third-party agent, a CI bot, or a client's server — declare a per-server **security mode**.
313
+
314
+ ```bash
315
+ # In your .env — three optional fields. Omit them all to keep v3.4.x behavior exactly.
316
+ SSH_SERVER_CLIENT_PROD_HOST=client-prod.example.com
317
+ SSH_SERVER_CLIENT_PROD_USER=consultant
318
+ SSH_SERVER_CLIENT_PROD_KEYPATH=~/.ssh/consultant_ed25519
319
+
320
+ SSH_SERVER_CLIENT_PROD_MODE=readonly # unrestricted | readonly | restricted
321
+ SSH_SERVER_CLIENT_PROD_AUDIT_LOG=~/.ssh-manager/audit.jsonl # opt-in JSONL audit trail
322
+ # For mode=restricted, provide an allowlist of regex (DENY wins over ALLOW):
323
+ # SSH_SERVER_CI_ALLOW_PATTERNS="^docker (ps|logs);^kubectl get "
324
+ ```
325
+
326
+ - **`unrestricted`** (default, no field needed) — identical to pre-v3.5.0 behavior. Zero overhead.
327
+ - **`readonly`** — blocks `ssh_upload`, `ssh_deploy`, `ssh_sync`, `ssh_execute_sudo`, backup/db write tools, and built-in destructive commands (`rm`, `mv`, `sudo`, `systemctl restart`, redirects outside `/tmp`, `curl | sh`, …).
328
+ - **`restricted`** — every `ssh_execute` command must match at least one `ALLOW_PATTERNS` regex AND no `DENY_PATTERNS` regex.
329
+
330
+ Existing configs are unaffected — no field is mandatory, no behavior changes unless you opt in. See **[docs/SECURITY_MODES.md](docs/SECURITY_MODES.md)** for the full reference, recipes, and limitations.
331
+
308
332
  ### 4. Start Using!
309
333
 
310
334
  In Claude Code, you can now:
@@ -49,7 +49,29 @@ cmd_server_add() {
49
49
  # Get optional description
50
50
  local description
51
51
  prompt_input "Description (optional)" "" "description"
52
-
52
+
53
+ # ── Security mode (v3.5.0+) — fully optional, defaults preserve pre-v3.5.0 behavior ──
54
+ # Pressing Enter on every prompt below produces an .env entry identical to v3.4.1.
55
+ local mode=""
56
+ local allow_patterns=""
57
+ local audit_log=""
58
+ echo
59
+ print_info "Security mode (optional — press Enter to skip and keep current behavior)"
60
+ print_info " unrestricted = no filter (default, identical to v3.4.x)"
61
+ print_info " readonly = block mutating tools + built-in destructive command denylist"
62
+ print_info " restricted = command must match SSH_SERVER_<N>_ALLOW_PATTERNS"
63
+ prompt_input "Mode [unrestricted|readonly|restricted]" "unrestricted" "mode"
64
+ # Normalize empty input to "unrestricted" (preserves pre-v3.5.0 .env output).
65
+ if [ -z "$mode" ]; then mode="unrestricted"; fi
66
+
67
+ if [ "$mode" = "restricted" ]; then
68
+ print_info "Allow patterns: ';'-separated list of regex (e.g. '^docker (ps|logs);^kubectl get ')"
69
+ prompt_input "ALLOW_PATTERNS (required for restricted)" "" "allow_patterns"
70
+ fi
71
+
72
+ print_info "Audit log: absolute file path to append a JSONL audit record per tool call"
73
+ prompt_input "AUDIT_LOG path (optional)" "" "audit_log"
74
+
53
75
  # Show summary
54
76
  echo
55
77
  print_subheader "Configuration Summary"
@@ -64,10 +86,19 @@ cmd_server_add() {
64
86
  if [ -n "$description" ]; then
65
87
  print_table_row "Description:" "$description"
66
88
  fi
67
-
89
+ if [ "$mode" != "unrestricted" ]; then
90
+ print_table_row "Mode:" "$mode"
91
+ fi
92
+ if [ -n "$allow_patterns" ]; then
93
+ print_table_row "Allow patterns:" "$allow_patterns"
94
+ fi
95
+ if [ -n "$audit_log" ]; then
96
+ print_table_row "Audit log:" "$audit_log"
97
+ fi
98
+
68
99
  echo
69
100
  if prompt_yes_no "Save this configuration?" "y"; then
70
- add_server_to_env "$server_name" "$host" "$user" "$auth_type" "$auth_value" "$port" "$description"
101
+ add_server_to_env "$server_name" "$host" "$user" "$auth_type" "$auth_value" "$port" "$description" "$mode" "$allow_patterns" "$audit_log"
71
102
 
72
103
  echo
73
104
  if prompt_yes_no "Test connection now?" "y"; then
package/cli/lib/config.sh CHANGED
@@ -156,6 +156,10 @@ get_server_config() {
156
156
  }
157
157
 
158
158
  # Add server to .env
159
+ #
160
+ # Trailing security-mode args (8-10) are optional and default to "" — when
161
+ # omitted they are not written, preserving exact pre-v3.5.0 output for existing
162
+ # wizard call sites.
159
163
  add_server_to_env() {
160
164
  local name="$1"
161
165
  local host="$2"
@@ -164,15 +168,18 @@ add_server_to_env() {
164
168
  local auth_value="$5"
165
169
  local port="${6:-22}"
166
170
  local description="${7:-}"
167
-
171
+ local mode="${8:-}"
172
+ local allow_patterns="${9:-}"
173
+ local audit_log="${10:-}"
174
+
168
175
  local name_upper="$(echo "$name" | tr '[:lower:]' '[:upper:]')"
169
-
176
+
170
177
  # Check if server already exists
171
178
  if grep -q "^SSH_SERVER_${name_upper}_HOST=" "$SSH_MANAGER_ENV" 2>/dev/null; then
172
179
  print_error "Server '$name' already exists"
173
180
  return 1
174
181
  fi
175
-
182
+
176
183
  # Ensure parent directory and .env file exist
177
184
  mkdir -p "$(dirname "$SSH_MANAGER_ENV")"
178
185
  touch "$SSH_MANAGER_ENV"
@@ -187,18 +194,30 @@ add_server_to_env() {
187
194
  echo "SSH_SERVER_${name_upper}_HOST=$host"
188
195
  echo "SSH_SERVER_${name_upper}_USER=$user"
189
196
  echo "SSH_SERVER_${name_upper}_PORT=$port"
190
-
197
+
191
198
  if [ "$auth_type" = "password" ]; then
192
199
  echo "SSH_SERVER_${name_upper}_PASSWORD=$auth_value"
193
200
  else
194
201
  echo "SSH_SERVER_${name_upper}_KEYPATH=$auth_value"
195
202
  fi
196
-
203
+
197
204
  if [ -n "$description" ]; then
198
205
  echo "SSH_SERVER_${name_upper}_DESCRIPTION=\"$description\""
199
206
  fi
207
+
208
+ # Security mode (v3.5.0+) — only emit non-empty / non-default values to
209
+ # keep generated .env diff-free for users who skip these prompts.
210
+ if [ -n "$mode" ] && [ "$mode" != "unrestricted" ]; then
211
+ echo "SSH_SERVER_${name_upper}_MODE=$mode"
212
+ fi
213
+ if [ -n "$allow_patterns" ]; then
214
+ echo "SSH_SERVER_${name_upper}_ALLOW_PATTERNS=\"$allow_patterns\""
215
+ fi
216
+ if [ -n "$audit_log" ]; then
217
+ echo "SSH_SERVER_${name_upper}_AUDIT_LOG=$audit_log"
218
+ fi
200
219
  } >> "$SSH_MANAGER_ENV"
201
-
220
+
202
221
  print_success "Server '$name' added successfully"
203
222
  }
204
223
 
package/cli/migrate.sh CHANGED
@@ -147,7 +147,7 @@ echo " ${YELLOW}SSH_MANAGER_ENV=\"$(realpath "$ENV_FILE")\" ssh-manager${NC}
147
147
  echo
148
148
  echo " 2. Direct commands:"
149
149
  echo " ${YELLOW}SSH_MANAGER_ENV=\"$(realpath "$ENV_FILE")\" ssh-manager server list${NC}"
150
- echo " ${YELLOW}SSH_MANAGER_ENV=\"$(realpath "$ENV_FILE")\" ssh-manager ssh dmis${NC}"
150
+ echo " ${YELLOW}SSH_MANAGER_ENV=\"$(realpath "$ENV_FILE")\" ssh-manager ssh production${NC}"
151
151
  echo
152
152
  echo " 3. Or use the wrapper:"
153
153
  echo " ${YELLOW}$WRAPPER${NC}"
@@ -68,9 +68,9 @@ Each profile provides relevant aliases:
68
68
  ### Using Command Aliases in Claude Code
69
69
 
70
70
  ```
71
- "Execute bench-update on production server"
72
- "Run bench-restart on dmis"
73
- "Execute check-memory on develop"
71
+ "Execute app-update on production server"
72
+ "Run app-restart on myapp"
73
+ "Execute check-memory on staging"
74
74
  ```
75
75
 
76
76
  ### Managing Command Aliases
@@ -64,19 +64,19 @@ Create shortcuts for your servers.
64
64
 
65
65
  ## Common Deployment Workflows
66
66
 
67
- ### ERPNext/Frappe Deployment
67
+ ### Application Module Deployment
68
68
 
69
- For the scenario from your conversation, here's the optimized workflow:
69
+ A typical end-to-end deployment of a couple of module files into a running app:
70
70
 
71
71
  ```
72
72
  # Step 1: Create aliases for easier access
73
- "Create alias 'dmis' for dmis server"
73
+ "Create alias 'myapp' for production_server"
74
74
 
75
75
  # Step 2: Deploy files using the new tool
76
- "Deploy payment_proposal.py and payment_proposal.js to dmis:/home/neoffice/frappe-bench/apps/erpnextswiss/"
76
+ "Deploy handler.py and handler.js to myapp:/opt/myapp/apps/myapp/module/"
77
77
 
78
78
  # Step 3: Restart the service
79
- "Run 'bench restart' on dmis"
79
+ "Run './bin/restart' on myapp"
80
80
  ```
81
81
 
82
82
  The deployment tool automatically:
@@ -150,11 +150,11 @@ Always enabled by default:
150
150
 
151
151
  ### Server Not Found
152
152
 
153
- **Problem**: "Server 'dmis.neoffice.me' not found"
153
+ **Problem**: "Server 'host.example.com' not found"
154
154
 
155
155
  **Solution**: Use configured name or create an alias:
156
156
  ```
157
- "Create alias 'dmis.neoffice.me' for dmis"
157
+ "Create alias 'host.example.com' for myapp"
158
158
  ```
159
159
 
160
160
  ### Files Not Updating
@@ -165,7 +165,7 @@ Always enabled by default:
165
165
  ```json
166
166
  {
167
167
  "options": {
168
- "restart": "bench restart"
168
+ "restart": "systemctl restart myapp"
169
169
  }
170
170
  }
171
171
  ```
@@ -198,7 +198,7 @@ Create a `.server-aliases.json`:
198
198
  "prod": "production",
199
199
  "dev": "development",
200
200
  "stage": "staging",
201
- "dmis": "dmis_server"
201
+ "myapp": "production_server"
202
202
  }
203
203
  ```
204
204
 
@@ -209,29 +209,30 @@ Create a `.server-aliases.json`:
209
209
  3. **Default Directories**: Set default dirs to avoid repetition
210
210
  4. **Connection Reuse**: Connections are kept alive during session
211
211
 
212
- ## Example: Complete ERPNext Update
212
+ ## Example: Complete Application Update
213
213
 
214
- Based on your real scenario, here's the optimized workflow:
214
+ End-to-end deployment of a couple of customization files into a running app:
215
215
 
216
216
  ```bash
217
217
  # 1. Setup (one time)
218
- "Create alias 'dmis' for dmis server"
218
+ "Create alias 'myapp' for production_server"
219
219
 
220
220
  # 2. Deploy both files at once
221
- "Deploy these files to dmis:
222
- - payment_proposal.py to /home/neoffice/frappe-bench/apps/erpnextswiss/erpnextswiss/doctype/payment_proposal/
223
- - payment_proposal.js to same location"
221
+ "Deploy these files to myapp:
222
+ - handler.py to /opt/myapp/apps/myapp/module/handler/
223
+ - handler.js to same location"
224
224
 
225
225
  # 3. Restart service
226
- "Run 'cd /home/neoffice/frappe-bench && bench restart' on dmis"
226
+ "Run 'cd /opt/myapp && ./bin/restart' on myapp"
227
227
  ```
228
228
 
229
- This replaces your previous multi-step process:
230
- - ❌ Upload to wrong location
231
- - ❌ Permission errors
232
- - ❌ Manual sudo password entry
233
- - ❌ Copy from /tmp
234
- - ✅ Single command deployment!
229
+ The single-command flow replaces the manual process of upload-to-tmp,
230
+ chown, chmod, mv, restart — all handled by `ssh_deploy` in one shot:
231
+
232
+ - ✅ Single command deployment
233
+ - ✅ Automatic permission/ownership handling
234
+ - ✅ Automatic backup before overwriting
235
+ - ✅ No sudo password typed in the terminal
235
236
 
236
237
  ## Support
237
238
 
@@ -0,0 +1,189 @@
1
+ # Security Modes (v3.5.0+)
2
+
3
+ `mcp-ssh-manager` lets you declare a **per-server security mode** to constrain
4
+ what an AI agent can do once it's been granted access to the MCP server.
5
+ This is **opt-in** — servers without a `MODE` field behave exactly like they
6
+ did in v3.4.x.
7
+
8
+ ## Why
9
+
10
+ Before v3.5.0 the only authorization layer was Claude Code's `autoApprove`
11
+ mechanism, which is tool-level and all-or-nothing. Once `ssh_execute` is
12
+ auto-approved, anything goes — including `rm -rf /`. Security modes add a
13
+ **second filter inside the MCP server itself**, so a server you've marked
14
+ `readonly` will refuse destructive commands even if the client allowed
15
+ the tool.
16
+
17
+ This is **not** a kernel sandbox (no seccomp, no container, no namespaces).
18
+ It's a defense-in-depth filter against accidents and prompt-injection
19
+ attacks, layered between the MCP client and the SSH session.
20
+
21
+ ## The three modes
22
+
23
+ | Mode | What it does |
24
+ |---|---|
25
+ | `unrestricted` (default) | No filter. Identical to pre-v3.5.0 behavior. Zero overhead — `evaluatePolicy()` early-returns. |
26
+ | `readonly` | Blocks mutating tools at the tool level (`ssh_upload`, `ssh_deploy`, `ssh_sync`, `ssh_execute_sudo`, `ssh_backup_create/restore/schedule`, `ssh_db_import/dump`, `ssh_key_manage` write actions, `ssh_alert_setup` set, `ssh_process_manager kill`). For `ssh_execute` / `ssh_execute_sudo` / `ssh_execute_group` / `ssh_session_send`, applies a built-in denylist (rm, mv, dd, mkfs, chmod, chown, sudo, systemctl restart/stop, docker rm/stop, pipe-to-sh, redirect outside `/tmp`, etc.). |
27
+ | `restricted` | All readonly blocks plus: every command must match at least one `ALLOW_PATTERNS` regex AND no `DENY_PATTERNS` regex. **DENY wins over ALLOW**. With no `ALLOW_PATTERNS`, every command is refused (fail-closed). |
28
+
29
+ ## Configuration
30
+
31
+ ### Environment variables / `.env`
32
+
33
+ ```bash
34
+ SSH_SERVER_PROD_HOST=prod.example.com
35
+ SSH_SERVER_PROD_USER=deploy
36
+ SSH_SERVER_PROD_KEYPATH=~/.ssh/id_ed25519
37
+
38
+ # Security mode (optional — omit to keep pre-v3.5.0 behavior)
39
+ SSH_SERVER_PROD_MODE=readonly
40
+ SSH_SERVER_PROD_AUDIT_LOG=/var/log/mcp-ssh-prod.jsonl
41
+
42
+ # For restricted mode
43
+ SSH_SERVER_PROD_ALLOW_PATTERNS="^docker (ps|logs|inspect);^kubectl get ;^systemctl status "
44
+ SSH_SERVER_PROD_DENY_PATTERNS=" -f $; --force"
45
+ ```
46
+
47
+ Patterns are `;`-separated POSIX-ish JavaScript regex (compiled with `new RegExp`).
48
+ Invalid regex are logged as warnings and skipped — they do not abort startup.
49
+
50
+ ### TOML
51
+
52
+ ```toml
53
+ [ssh_servers.prod]
54
+ host = "prod.example.com"
55
+ user = "deploy"
56
+ key_path = "~/.ssh/id_ed25519"
57
+
58
+ mode = "restricted"
59
+ allow_patterns = ["^docker (ps|logs|inspect)", "^kubectl get ", "^systemctl status "]
60
+ deny_patterns = [" -f $", "--force"]
61
+ audit_log = "/var/log/mcp-ssh-prod.jsonl"
62
+ ```
63
+
64
+ TOML arrays are preferred. A `;`-separated string is also accepted for
65
+ parity with the `.env` form.
66
+
67
+ ## Audit log
68
+
69
+ When `AUDIT_LOG` (`.env`) or `audit_log` (TOML) is set to a file path, every
70
+ **gated** tool invocation appends a JSONL record:
71
+
72
+ ```json
73
+ {"ts":"2026-05-18T15:30:00.123Z","server":"prod","tool":"ssh_execute","args":{"command":"ls /tmp"},"allowed":true,"exitCode":0,"success":true}
74
+ {"ts":"2026-05-18T15:30:14.789Z","server":"prod","tool":"ssh_execute","args":{"command":"rm /tmp/x"},"allowed":false,"reason":"Command refused on server \"prod\" (mode: readonly): matches built-in destructive pattern /(^|[\\s;&|])rm(\\s|$)/."}
75
+ ```
76
+
77
+ Secrets (`password`, `passphrase`, `sudoPassword`, `token`, `secret`, `apikey`)
78
+ are redacted to `***` before being written, even if a tool somehow passed them
79
+ through args.
80
+
81
+ Log rotation is not handled by `mcp-ssh-manager` — use `logrotate`, `vector`,
82
+ or your log shipper of choice. v3.5.0 audits cover the gated tool set:
83
+ `ssh_execute`, `ssh_upload`, `ssh_execute_sudo`, plus denials on every other
84
+ mutating tool. Pure read tools (`ssh_health_check`, `ssh_db_query`, `ssh_tail`…)
85
+ are not audited in v3.5.0 — open an issue if you need full coverage.
86
+
87
+ ## Recipes
88
+
89
+ ### Third-party agent with read-only access
90
+
91
+ Goal: hand the MCP to an external agent (CI bot, sandbox, third-party LLM
92
+ service) that should only be able to **observe** your prod box.
93
+
94
+ ```bash
95
+ SSH_SERVER_PROD_HOST=prod.example.com
96
+ SSH_SERVER_PROD_USER=observer
97
+ SSH_SERVER_PROD_KEYPATH=~/.ssh/observer_ed25519
98
+ SSH_SERVER_PROD_MODE=readonly
99
+ SSH_SERVER_PROD_AUDIT_LOG=~/.ssh-manager/audit/prod.jsonl
100
+ ```
101
+
102
+ The agent can run `ls`, `cat`, `df`, `ps`, `journalctl`, `docker ps`,
103
+ `kubectl get`, etc. — but `rm`, `mv`, `sudo`, redirect-to-`/etc/`, `pipe | sh`,
104
+ `systemctl restart`, `apt install`, etc. all return a `Policy denied` error
105
+ to the MCP client.
106
+
107
+ ### CI bot with a tight allowlist
108
+
109
+ Goal: an automated bot can only deploy-status commands, nothing else.
110
+
111
+ ```bash
112
+ SSH_SERVER_CI_HOST=ci.example.com
113
+ SSH_SERVER_CI_USER=ci-bot
114
+ SSH_SERVER_CI_KEYPATH=~/.ssh/ci_bot_ed25519
115
+ SSH_SERVER_CI_MODE=restricted
116
+ SSH_SERVER_CI_ALLOW_PATTERNS="^docker compose ps;^docker compose logs ;^/opt/myapp/bin/healthcheck"
117
+ SSH_SERVER_CI_DENY_PATTERNS="--force; rm "
118
+ SSH_SERVER_CI_AUDIT_LOG=/var/log/ci-bot.jsonl
119
+ ```
120
+
121
+ ### Mixed fleet: one strict server, others unrestricted
122
+
123
+ You can mix modes freely — the policy is evaluated per server, per call.
124
+
125
+ ```bash
126
+ # Your dev box — full control, no surprises
127
+ SSH_SERVER_DEV_HOST=dev.local
128
+ SSH_SERVER_DEV_USER=you
129
+ SSH_SERVER_DEV_KEYPATH=~/.ssh/id_ed25519
130
+ # (no MODE → unrestricted, behaves like v3.4.x)
131
+
132
+ # Client's prod box you don't want to break
133
+ SSH_SERVER_CLIENT_PROD_HOST=client-prod.example.com
134
+ SSH_SERVER_CLIENT_PROD_USER=consultant
135
+ SSH_SERVER_CLIENT_PROD_KEYPATH=~/.ssh/consultant_ed25519
136
+ SSH_SERVER_CLIENT_PROD_MODE=readonly
137
+ SSH_SERVER_CLIENT_PROD_AUDIT_LOG=~/.ssh-manager/audit/client-prod.jsonl
138
+ ```
139
+
140
+ ## What gets gated, what doesn't
141
+
142
+ **Fully gated** (policy check at tool entry):
143
+ `ssh_execute`, `ssh_execute_sudo`, `ssh_execute_group`, `ssh_session_send`,
144
+ `ssh_upload`, `ssh_sync`, `ssh_deploy`, `ssh_backup_create`,
145
+ `ssh_backup_restore`, `ssh_backup_schedule`, `ssh_db_import`, `ssh_db_dump`.
146
+
147
+ **Action-gated** (only the mutating action is checked):
148
+ `ssh_key_manage` (only `accept` / `remove`), `ssh_alert_setup` (only `set`),
149
+ `ssh_process_manager` (only `kill`).
150
+
151
+ **Not gated** (pure reads or local-only state — no remote effect to block):
152
+ `ssh_list_servers`, `ssh_download`, `ssh_tail`, `ssh_monitor`, `ssh_history`,
153
+ `ssh_health_check`, `ssh_service_status`, `ssh_db_list`, `ssh_db_query`
154
+ (already SELECT-only), `ssh_backup_list`, `ssh_session_start`,
155
+ `ssh_session_list`, `ssh_session_close`, `ssh_connection_status`,
156
+ `ssh_tunnel_*`, `ssh_group_manage`, `ssh_command_alias`, `ssh_alias`,
157
+ `ssh_hooks`, `ssh_profile`.
158
+
159
+ ## Limitations
160
+
161
+ - **Not a sandbox.** Once a command is allowed, it runs with the full
162
+ permissions of the SSH user. Use a dedicated low-privilege account for
163
+ servers in `readonly` / `restricted` mode.
164
+ - **Regex-based filtering can be bypassed** with creative command crafting
165
+ (encoded payloads, indirection via shell variables, etc.). Treat `readonly`
166
+ as protection against accidents and prompt injection of the common form,
167
+ not as an unbreakable shell escape.
168
+ - **Aliases are expanded before policy evaluation** — you can't bypass a DENY
169
+ by hiding `rm` behind an alias defined via `ssh_command_alias`.
170
+ - **No transport-level / per-client policies.** All clients see the same
171
+ policy for a given server. If you need different policies per agent, run
172
+ separate MCP server instances with different config files.
173
+
174
+ ## Backward compatibility
175
+
176
+ A v3.4.x `.env` or TOML loads identically under v3.5.0:
177
+
178
+ - No `MODE` field → `mode = 'unrestricted'` → `evaluatePolicy()` early-returns
179
+ `{ allowed: true }`. Not a single regex is compiled, not a single byte is
180
+ written to disk.
181
+ - `AUDIT_LOG` is opt-in — no log file is created until you set it.
182
+ - The interactive wizard (`ssh-manager server add`) defaults all three new
183
+ prompts to "skip" (press Enter and the resulting `.env` block is identical
184
+ to v3.4.x).
185
+ - Tool auto-approval (`autoApprove` in `claude_code_config.json`) keeps
186
+ working — the policy intercepts AFTER auto-approval, BEFORE execution,
187
+ so the client never sees a new prompt.
188
+
189
+ See `CHANGELOG.md` v3.5.0 for the full diff.