mcp-ssh-manager 3.4.1 → 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.
- package/.hooks-config.json +1 -1
- package/CHANGELOG.md +21 -0
- package/README.md +22 -0
- package/cli/commands/server.sh +34 -3
- package/cli/lib/config.sh +25 -6
- package/cli/migrate.sh +1 -1
- package/docs/ALIASES_AND_HOOKS.md +3 -3
- package/docs/DEPLOYMENT_GUIDE.md +23 -22
- package/docs/SECURITY_MODES.md +189 -0
- package/examples/deploy-workflow.py +48 -48
- package/package.json +3 -2
- package/src/audit.js +97 -0
- package/src/config-loader.js +82 -0
- package/src/index.js +135 -3
- package/src/policy.js +247 -0
package/.hooks-config.json
CHANGED
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
{
|
|
125
125
|
"type": "notification",
|
|
126
126
|
"name": "use-context",
|
|
127
|
-
"command": "echo \"Server: {server}, Error: {error}\" > /
|
|
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,27 @@ 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
|
+
|
|
8
29
|
## [3.4.1] - 2026-05-16
|
|
9
30
|
|
|
10
31
|
### Fixed
|
package/README.md
CHANGED
|
@@ -307,6 +307,28 @@ Edit `~/.config/claude-code/claude_code_config.json`:
|
|
|
307
307
|
|
|
308
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).
|
|
309
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
|
+
|
|
310
332
|
### 4. Start Using!
|
|
311
333
|
|
|
312
334
|
In Claude Code, you can now:
|
package/cli/commands/server.sh
CHANGED
|
@@ -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
|
|
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
|
|
72
|
-
"Run
|
|
73
|
-
"Execute check-memory on
|
|
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
|
package/docs/DEPLOYMENT_GUIDE.md
CHANGED
|
@@ -64,19 +64,19 @@ Create shortcuts for your servers.
|
|
|
64
64
|
|
|
65
65
|
## Common Deployment Workflows
|
|
66
66
|
|
|
67
|
-
###
|
|
67
|
+
### Application Module Deployment
|
|
68
68
|
|
|
69
|
-
|
|
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 '
|
|
73
|
+
"Create alias 'myapp' for production_server"
|
|
74
74
|
|
|
75
75
|
# Step 2: Deploy files using the new tool
|
|
76
|
-
"Deploy
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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": "
|
|
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
|
-
"
|
|
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
|
|
212
|
+
## Example: Complete Application Update
|
|
213
213
|
|
|
214
|
-
|
|
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 '
|
|
218
|
+
"Create alias 'myapp' for production_server"
|
|
219
219
|
|
|
220
220
|
# 2. Deploy both files at once
|
|
221
|
-
"Deploy these files to
|
|
222
|
-
-
|
|
223
|
-
-
|
|
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 /
|
|
226
|
+
"Run 'cd /opt/myapp && ./bin/restart' on myapp"
|
|
227
227
|
```
|
|
228
228
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
-
|
|
233
|
-
-
|
|
234
|
-
- ✅
|
|
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.
|