mcp-ssh-manager 3.8.7 → 4.0.1
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/.eslintignore +5 -0
- package/.gitattributes +5 -0
- package/CHANGELOG.md +371 -6
- package/CLAUDE.md +6 -0
- package/CODE_OF_CONDUCT.md +18 -0
- package/CONTRIBUTING.md +30 -0
- package/Formula/ssh-manager.rb +60 -0
- package/README.md +484 -964
- package/ROADMAP-V4.md +451 -0
- package/brand/README.md +43 -0
- package/brand/icon.svg +32 -0
- package/brand/mark.svg +18 -0
- package/brand/wordmark.svg +30 -0
- package/cli/app.js +230 -0
- package/cli/control.js +116 -0
- package/cli/lib/colors.sh +15 -0
- package/cli/lib/menu.sh +145 -96
- package/cli/portability.js +186 -0
- package/cli/ssh-manager +197 -91
- package/cli/ssh-manager.js +14 -0
- package/cli/style.js +17 -0
- package/cli/vault.js +411 -0
- package/desktop/ControlPlaneApp.swift +219 -0
- package/desktop/build.sh +58 -0
- package/desktop/electron/after-pack.cjs +39 -0
- package/desktop/electron/electron-builder.yml +148 -0
- package/desktop/electron/finalize-artifacts.mjs +83 -0
- package/desktop/electron/main.js +815 -0
- package/desktop/electron/package-lock.json +3656 -0
- package/desktop/electron/package.json +30 -0
- package/desktop/electron/prepare-engine.mjs +84 -0
- package/desktop/electron/resources/entitlements.mac.plist +22 -0
- package/desktop/electron/resources/icon.png +0 -0
- package/desktop/electron/resources/trayTemplate.png +0 -0
- package/desktop/electron/resources/trayTemplate@2x.png +0 -0
- package/desktop/electron/smoke-test.mjs +184 -0
- package/dist/ui/app.css +1 -0
- package/dist/ui/app.js +501 -0
- package/dist/ui/assets/Forum-Regular.woff2 +0 -0
- package/dist/ui/assets/JetBrainsMono-Bold.woff2 +0 -0
- package/dist/ui/assets/JetBrainsMono-Regular.woff2 +0 -0
- package/dist/ui/assets/Karla-Variable.woff2 +0 -0
- package/dist/ui/index.html +16 -0
- package/docs/DISTRIBUTION.md +136 -0
- package/docs/FINAL-TEST-V4.md +209 -0
- package/docs/MIGRATION.md +334 -0
- package/docs/TESTING-V4.md +119 -0
- package/docs/superpowers/specs/2026-10-08-desktop-from-npm-and-cli-design.md +187 -0
- package/docs/videos/control-plane.mp4 +0 -0
- package/package.json +61 -30
- package/scripts/build-interface.mjs +73 -0
- package/scripts/capture-screenshots.mjs +191 -0
- package/scripts/demo-env.mjs +461 -0
- package/scripts/frame-screenshots.py +176 -0
- package/scripts/macbook-mockup.py +296 -0
- package/scripts/make-tray-icon.py +61 -0
- package/scripts/preview-candidate.mjs +291 -0
- package/scripts/publish-desktop.mjs +46 -0
- package/scripts/record-demo.mjs +229 -0
- package/scripts/release-version.mjs +32 -0
- package/scripts/render-cli-menu.py +157 -0
- package/scripts/requirements-dev.in +12 -0
- package/scripts/requirements-dev.txt +424 -0
- package/scripts/run-ui-regression.mjs +48 -0
- package/scripts/setup-hooks.sh +7 -13
- package/scripts/smoke-desktop.mjs +80 -0
- package/scripts/test-drag-and-drop.mjs +114 -0
- package/scripts/test-first-run.mjs +5 -0
- package/scripts/test-import-ui.mjs +5 -0
- package/scripts/test-preferences-persist.mjs +5 -0
- package/scripts/test-upgrade-from-published.mjs +226 -0
- package/scripts/verify-mac-build.sh +153 -0
- package/scripts/verify-windows-build.ps1 +15 -0
- package/server.json +3 -3
- package/skills/README.md +42 -0
- package/skills/ssh-incident/SKILL.md +55 -0
- package/skills/ssh-operations/SKILL.md +62 -0
- package/skills/ssh-restricted/SKILL.md +57 -0
- package/src/agent-clients.js +482 -0
- package/src/approval.js +291 -0
- package/src/audit.js +11 -1
- package/src/command-log.js +162 -0
- package/src/config-loader.js +119 -4
- package/src/config-paths.js +101 -0
- package/src/control-plane.js +2730 -0
- package/src/desktop-install.js +747 -0
- package/src/index.js +179 -213
- package/src/live-stream.js +261 -0
- package/src/saved-commands.js +150 -0
- package/src/secret-store.js +573 -0
- package/src/server-aliases.js +8 -7
- package/src/server-config-manager.js +33 -7
- package/src/server-export.js +106 -0
- package/src/server-groups.js +82 -21
- package/src/server-import.js +477 -0
- package/src/shell-quote.js +9 -2
- package/src/ssh-connection.js +155 -0
- package/src/ssh-manager.js +186 -13
- package/src/tunnel-manager.js +79 -0
- package/src/vault-recovery.js +206 -0
- package/src/xlsx.js +322 -0
- package/docs/images/social-preview.png +0 -0
- package/docs/images/social-preview@2x.png +0 -0
- package/docs/images/ssh-manager-cli-menu.png +0 -0
package/cli/vault.js
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `ssh-manager vault` — manage the encrypted credential store.
|
|
3
|
+
//
|
|
4
|
+
// This is the headless half of what a GUI will later do with buttons. Both
|
|
5
|
+
// drive the same SecretStore, so anything possible in the interface is possible
|
|
6
|
+
// here, and a server added by either is visible to the other immediately.
|
|
7
|
+
//
|
|
8
|
+
// Commands:
|
|
9
|
+
// list Show what the vault holds (never prints secrets)
|
|
10
|
+
// add <name> Add or replace a server (prompts for the password)
|
|
11
|
+
// remove <name> Delete a server
|
|
12
|
+
// import [--from <path>] Copy servers from a .env into the vault
|
|
13
|
+
// status Where the vault and its key live
|
|
14
|
+
|
|
15
|
+
import fs from 'fs';
|
|
16
|
+
import path from 'path';
|
|
17
|
+
import readline from 'readline';
|
|
18
|
+
import { writeRecoveryFile, readRecoveryFile, describeRecoveryFile } from '../src/vault-recovery.js';
|
|
19
|
+
import { SecretStore, defaultVaultPath, SECRET_FIELDS } from '../src/secret-store.js';
|
|
20
|
+
import { defaultSocketPath, isControlPlaneListening, VALID_APPROVAL_MODES } from '../src/approval.js';
|
|
21
|
+
import { ConfigLoader } from '../src/config-loader.js';
|
|
22
|
+
import { resolveEnvFilePath } from '../src/config-paths.js';
|
|
23
|
+
import { GREEN, YELLOW, RED, DIM, RESET } from './style.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Ask a question on the terminal.
|
|
27
|
+
* @param {string} question - Prompt text
|
|
28
|
+
* @param {boolean} [hidden] - Mask the input (for secrets)
|
|
29
|
+
* @returns {Promise<string>} The answer, trimmed
|
|
30
|
+
*/
|
|
31
|
+
let sharedReadline = null;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The one readline interface for the whole command.
|
|
35
|
+
*
|
|
36
|
+
* Created per question originally, which works at a keyboard and fails
|
|
37
|
+
* everywhere else: an interface opened on a pipe reads whatever is buffered and
|
|
38
|
+
* discards the rest when it closes, so the second question of a pair never sees
|
|
39
|
+
* its answer. One interface, closed at the end, behaves the same either way.
|
|
40
|
+
*/
|
|
41
|
+
function getReadline() {
|
|
42
|
+
if (!sharedReadline) {
|
|
43
|
+
sharedReadline = readline.createInterface({
|
|
44
|
+
input: process.stdin,
|
|
45
|
+
output: process.stdout,
|
|
46
|
+
terminal: process.stdin.isTTY === true,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return sharedReadline;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Release stdin so the process can exit. */
|
|
53
|
+
function closeReadline() {
|
|
54
|
+
sharedReadline?.close();
|
|
55
|
+
sharedReadline = null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function ask(question, hidden = false) {
|
|
59
|
+
const rl = getReadline();
|
|
60
|
+
return new Promise(resolve => {
|
|
61
|
+
if (hidden) {
|
|
62
|
+
// Suppress echo: a password typed into a terminal should not stay
|
|
63
|
+
// visible in the scrollback of a shared screen or a recorded session.
|
|
64
|
+
const onData = () => { rl.output.write('\x1B[2K\x1B[200D' + question); };
|
|
65
|
+
rl.input.on('data', onData);
|
|
66
|
+
rl.question(question, answer => {
|
|
67
|
+
rl.input.removeListener('data', onData);
|
|
68
|
+
rl.output.write('\n');
|
|
69
|
+
resolve(answer.trim());
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
rl.question(question, answer => resolve(answer.trim()));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function usage() {
|
|
78
|
+
console.log(`
|
|
79
|
+
${GREEN}ssh-manager vault${RESET} — encrypted credential store
|
|
80
|
+
|
|
81
|
+
${GREEN}list${RESET} Servers held in the vault
|
|
82
|
+
${GREEN}add${RESET} <name> Add or replace a server
|
|
83
|
+
${GREEN}remove${RESET} <name> Delete a server
|
|
84
|
+
${GREEN}import${RESET} [--from <path>] Copy servers from .env / TOML into the vault
|
|
85
|
+
${GREEN}backup${RESET} <file> Write a recovery file, encrypted with a passphrase
|
|
86
|
+
${GREEN}restore${RESET} <file> Read one back into the vault
|
|
87
|
+
${GREEN}status${RESET} Where the vault and its key live
|
|
88
|
+
|
|
89
|
+
${DIM}Secrets are encrypted with AES-256-GCM. The key lives in your OS keychain
|
|
90
|
+
when there is one, otherwise in a 0600 file next to the vault.
|
|
91
|
+
Set SSH_MANAGER_KEY_SOURCE=file to skip the keychain (CI, containers).
|
|
92
|
+
|
|
93
|
+
That key belongs to this machine. Before you delete secrets from a .env,
|
|
94
|
+
take a recovery file — it is the copy that survives a new laptop.${RESET}
|
|
95
|
+
`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Write a recovery file. Asked for twice, because a passphrase typed once and
|
|
100
|
+
* mistyped is a file nobody can open, discovered at the worst moment.
|
|
101
|
+
*
|
|
102
|
+
* @param {import('../src/secret-store.js').SecretStore} store - The vault
|
|
103
|
+
* @param {string} target - Where to write
|
|
104
|
+
*/
|
|
105
|
+
async function cmdBackup(store, target) {
|
|
106
|
+
if (!target) {
|
|
107
|
+
console.error(`${YELLOW}Where should it go?${RESET} ssh-manager vault backup ~/ssh-manager-recovery.json`);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
const servers = store.getAllDecrypted();
|
|
111
|
+
const count = Object.keys(servers).length;
|
|
112
|
+
if (count === 0) {
|
|
113
|
+
console.error(`${YELLOW}The vault is empty — nothing to back up.${RESET}`);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log(`
|
|
118
|
+
${GREEN}${count} server(s) will be written to ${target}${RESET}
|
|
119
|
+
|
|
120
|
+
${DIM}The file is encrypted with a passphrase you choose here — not with this
|
|
121
|
+
machine's key. That is the point: it is what still opens on a new laptop.
|
|
122
|
+
Keep it where you keep passwords, not next to the vault.${RESET}
|
|
123
|
+
`);
|
|
124
|
+
|
|
125
|
+
const passphrase = await ask('Passphrase (at least 8 characters): ', true);
|
|
126
|
+
if (passphrase.length < 8) {
|
|
127
|
+
console.error(`${YELLOW}Too short. Nothing written.${RESET}`);
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
const again = await ask('Again: ', true);
|
|
131
|
+
if (again !== passphrase) {
|
|
132
|
+
console.error(`${YELLOW}They do not match. Nothing written.${RESET}`);
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const result = writeRecoveryFile(servers, passphrase, target);
|
|
137
|
+
console.log(`
|
|
138
|
+
${GREEN}✓${RESET} ${result.servers} server(s), ${result.secrets} secret(s) → ${result.path}
|
|
139
|
+
${DIM}Read it back with: ssh-manager vault restore ${target}
|
|
140
|
+
There is no way to recover the passphrase. If you lose it, this file is noise.${RESET}
|
|
141
|
+
`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Read a recovery file back into the vault.
|
|
146
|
+
*
|
|
147
|
+
* @param {import('../src/secret-store.js').SecretStore} store - The vault
|
|
148
|
+
* @param {string} source - The file
|
|
149
|
+
*/
|
|
150
|
+
async function cmdRestore(store, source) {
|
|
151
|
+
if (!source) {
|
|
152
|
+
console.error(`${YELLOW}Which file?${RESET} ssh-manager vault restore ~/ssh-manager-recovery.json`);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let described;
|
|
157
|
+
try {
|
|
158
|
+
described = describeRecoveryFile(source);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error(`${YELLOW}${error.message}${RESET}`);
|
|
161
|
+
process.exit(1);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
console.log(`
|
|
165
|
+
${GREEN}${source}${RESET}
|
|
166
|
+
${DIM}written ${new Date(described.createdAt).toLocaleString()} · ${described.servers} server(s), ${described.secrets} secret(s)${RESET}
|
|
167
|
+
`);
|
|
168
|
+
|
|
169
|
+
const passphrase = await ask('Passphrase: ', true);
|
|
170
|
+
let servers;
|
|
171
|
+
try {
|
|
172
|
+
servers = readRecoveryFile(source, passphrase);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error(`${YELLOW}${error.message}${RESET}`);
|
|
175
|
+
process.exit(1);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const readability = store.checkKey();
|
|
179
|
+
let existing = [];
|
|
180
|
+
try { existing = store.exists() ? store.listServers() : []; } catch { /* unreadable vault */ }
|
|
181
|
+
const clashes = Object.keys(servers).filter(name => existing.includes(name));
|
|
182
|
+
if (!readability.ok) {
|
|
183
|
+
console.log(`${YELLOW}The existing vault cannot be read. Recovery will replace it completely.${RESET}`);
|
|
184
|
+
const absent = existing.filter(name => !(name in servers));
|
|
185
|
+
if (absent.length) console.log(`${YELLOW}Not in this recovery file and not retained:${RESET} ${absent.join(', ')}`);
|
|
186
|
+
const answer = await ask('Replace the unreadable vault with this recovery file? [y/N] ');
|
|
187
|
+
if (answer.toLowerCase() !== 'y') { console.log('Cancelled.'); return; }
|
|
188
|
+
} else if (clashes.length > 0) {
|
|
189
|
+
console.log(`${YELLOW}Already in the vault and about to be replaced:${RESET} ${clashes.join(', ')}`);
|
|
190
|
+
const answer = await ask('Continue? [y/N] ');
|
|
191
|
+
if (answer.toLowerCase() !== 'y') {
|
|
192
|
+
console.log('Cancelled.');
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
store.restoreServers(servers, { replaceUnreadable: !readability.ok });
|
|
198
|
+
console.log(`\n${GREEN}✓${RESET} ${Object.keys(servers).length} server(s) restored into ${store.vaultPath}\n`);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Warn when the vault cannot actually be opened. Printed before the listing
|
|
203
|
+
* rather than after: an operator who reads "3 servers" and stops reading has
|
|
204
|
+
* been told the opposite of the truth.
|
|
205
|
+
*
|
|
206
|
+
* @param {import('../src/secret-store.js').SecretStore} store - The vault
|
|
207
|
+
* @returns {boolean} True when everything decrypts
|
|
208
|
+
*/
|
|
209
|
+
function warnIfUnreadable(store) {
|
|
210
|
+
const check = store.checkKey();
|
|
211
|
+
if (check.ok) return true;
|
|
212
|
+
console.error(`
|
|
213
|
+
${RED}This vault cannot be read on this machine.${RESET}
|
|
214
|
+
|
|
215
|
+
${check.reason}
|
|
216
|
+
`);
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function cmdList(store) {
|
|
221
|
+
const names = store.listServers();
|
|
222
|
+
if (names.length === 0) {
|
|
223
|
+
console.log(`${YELLOW}The vault is empty.${RESET} Add a server with: ssh-manager vault add <name>`);
|
|
224
|
+
console.log(`${DIM}Or copy what you already have: ssh-manager vault import${RESET}`);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const readable = warnIfUnreadable(store);
|
|
228
|
+
const raw = store.read();
|
|
229
|
+
console.log(`\n${readable ? GREEN : YELLOW}${names.length} server(s) in the vault${RESET} ${DIM}${store.vaultPath}${RESET}\n`);
|
|
230
|
+
for (const name of names) {
|
|
231
|
+
const s = raw.servers[name];
|
|
232
|
+
const secrets = SECRET_FIELDS.filter(f => s[f]).map(f => f.replace('Password', ' password'));
|
|
233
|
+
const auth = s.keyPath ? `key ${s.keyPath}` : (secrets.length ? 'password' : `${YELLOW}no credential${RESET}`);
|
|
234
|
+
const mode = s.mode && s.mode !== 'unrestricted' ? ` ${YELLOW}[${s.mode}]${RESET}` : '';
|
|
235
|
+
console.log(` ${name.padEnd(16)} ${String(s.user || '?')}@${String(s.host || '?')}:${s.port || 22} ${DIM}${auth}${RESET}${mode}`);
|
|
236
|
+
if (secrets.length) console.log(` ${' '.repeat(16)} ${DIM}encrypted: ${secrets.join(', ')}${RESET}`);
|
|
237
|
+
}
|
|
238
|
+
console.log();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async function cmdAdd(store, name) {
|
|
242
|
+
if (!name) { console.error(`${RED}Usage: ssh-manager vault add <name>${RESET}`); process.exit(1); }
|
|
243
|
+
|
|
244
|
+
const existing = store.read().servers[name.toLowerCase()];
|
|
245
|
+
if (existing) console.log(`${YELLOW}"${name}" already exists — this will replace it.${RESET}\n`);
|
|
246
|
+
|
|
247
|
+
const host = await ask(`Host${existing?.host ? ` [${existing.host}]` : ''}: `) || existing?.host;
|
|
248
|
+
if (!host) { console.error(`${RED}A host is required.${RESET}`); process.exit(1); }
|
|
249
|
+
const user = await ask(`User${existing?.user ? ` [${existing.user}]` : ''}: `) || existing?.user;
|
|
250
|
+
const port = await ask('Port [22]: ') || '22';
|
|
251
|
+
const keyPath = await ask('SSH key path (blank to use a password): ');
|
|
252
|
+
|
|
253
|
+
/** @type {Record<string, any>} */
|
|
254
|
+
const config = { host, user, port: Number(port) };
|
|
255
|
+
if (keyPath) {
|
|
256
|
+
config.keyPath = keyPath;
|
|
257
|
+
const passphrase = await ask('Key passphrase (blank if none): ', true);
|
|
258
|
+
if (passphrase) config.passphrase = passphrase;
|
|
259
|
+
} else {
|
|
260
|
+
const password = await ask('Password: ', true);
|
|
261
|
+
if (password) config.password = password;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const sudo = await ask('Sudo password (blank if none): ', true);
|
|
265
|
+
if (sudo) config.sudoPassword = sudo;
|
|
266
|
+
|
|
267
|
+
const mode = await ask('Security mode — unrestricted / readonly / restricted [unrestricted]: ');
|
|
268
|
+
if (mode && mode !== 'unrestricted') config.mode = mode;
|
|
269
|
+
|
|
270
|
+
store.setServer(name, config);
|
|
271
|
+
console.log(`\n${GREEN}✓${RESET} "${name.toLowerCase()}" saved, secrets encrypted.`);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async function cmdRemove(store, name) {
|
|
275
|
+
if (!name) { console.error(`${RED}Usage: ssh-manager vault remove <name>${RESET}`); process.exit(1); }
|
|
276
|
+
if (store.removeServer(name)) {
|
|
277
|
+
console.log(`${GREEN}✓${RESET} "${name.toLowerCase()}" removed from the vault.`);
|
|
278
|
+
} else {
|
|
279
|
+
console.log(`${YELLOW}"${name}" is not in the vault.${RESET}`);
|
|
280
|
+
process.exit(1);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async function cmdImport(store, fromPath) {
|
|
285
|
+
const envPath = fromPath || resolveEnvFilePath();
|
|
286
|
+
if (fromPath && !fs.existsSync(fromPath)) {
|
|
287
|
+
console.error(`${RED}No configuration found at ${fromPath}${RESET}`);
|
|
288
|
+
process.exit(1);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Load through the real ConfigLoader rather than parsing here, so an imported
|
|
292
|
+
// server is byte-for-byte what the MCP server would have used.
|
|
293
|
+
const loader = new ConfigLoader();
|
|
294
|
+
const fromToml = fromPath && path.extname(fromPath).toLowerCase() === '.toml';
|
|
295
|
+
const servers = await loader.load(fromToml
|
|
296
|
+
? { tomlPath: fromPath, preferToml: true, vaultPath: null }
|
|
297
|
+
: { envPath, vaultPath: null });
|
|
298
|
+
|
|
299
|
+
if (servers.size === 0) {
|
|
300
|
+
console.log(`${YELLOW}No servers found in the configuration.${RESET}`);
|
|
301
|
+
console.log(`${DIM}Point at a file with: ssh-manager vault import --from /path/to/.env (or .toml)${RESET}`);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const source = fromToml ? fromPath : loader.envPath || 'TOML / environment';
|
|
306
|
+
console.log(`\n${GREEN}${servers.size} server(s) found in ${source}${RESET}\n`);
|
|
307
|
+
for (const [name, config] of servers) {
|
|
308
|
+
const secrets = SECRET_FIELDS.filter(f => config[f]);
|
|
309
|
+
console.log(` ${name.padEnd(16)} ${config.user || '?'}@${config.host} ${DIM}${secrets.length ? `${secrets.length} secret(s) to encrypt` : 'no secret'}${RESET}`);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const answer = await ask('\nImport these into the vault? The .env is left untouched. [y/N] ');
|
|
313
|
+
if (answer.toLowerCase() !== 'y') { console.log('Cancelled.'); return; }
|
|
314
|
+
|
|
315
|
+
for (const [name, config] of servers) {
|
|
316
|
+
// `name` is injected by the loader for its own bookkeeping; it is the key.
|
|
317
|
+
const { name: _ignored, ...rest } = config;
|
|
318
|
+
store.setServer(name, rest);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
console.log(`\n${GREEN}✓${RESET} ${servers.size} server(s) imported and encrypted.`);
|
|
322
|
+
console.log(`${DIM}The vault now takes precedence over ${envPath}, which is untouched.${RESET}`);
|
|
323
|
+
|
|
324
|
+
// Ordered deliberately. Suggesting the .env can be cleaned up is only safe
|
|
325
|
+
// advice once a copy exists that does not depend on this machine's keychain —
|
|
326
|
+
// otherwise the two sentences together are "delete your only copy".
|
|
327
|
+
console.log(`
|
|
328
|
+
${YELLOW}Before you remove anything from ${envPath}:${RESET}
|
|
329
|
+
|
|
330
|
+
1. ${GREEN}ssh-manager vault backup ~/ssh-manager-recovery.json${RESET}
|
|
331
|
+
${DIM}A copy encrypted with a passphrase you choose. The vault's own key
|
|
332
|
+
lives in this machine's keychain and does not travel — a new laptop, a
|
|
333
|
+
reinstalled OS, or a wiped keyring leaves the vault unreadable.${RESET}
|
|
334
|
+
|
|
335
|
+
2. ${GREEN}ssh-manager vault status${RESET}
|
|
336
|
+
${DIM}Confirms this machine can actually decrypt what it just wrote.${RESET}
|
|
337
|
+
|
|
338
|
+
3. Run something real against a server.
|
|
339
|
+
|
|
340
|
+
${DIM}The .env keeps working either way — the vault sits above it, it does not
|
|
341
|
+
replace it. Nothing obliges you to delete anything.${RESET}
|
|
342
|
+
`);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* One line saying whether this machine can open the vault.
|
|
347
|
+
* @param {{ok: boolean, reason?: string, checked: number}} check - From checkKey()
|
|
348
|
+
* @returns {string}
|
|
349
|
+
*/
|
|
350
|
+
function describeReadability(check) {
|
|
351
|
+
if (!check.ok) return `${RED}NO — ${check.reason?.split('\n')[0]}${RESET}`;
|
|
352
|
+
if (check.checked === 0) return `${DIM}nothing encrypted yet${RESET}`;
|
|
353
|
+
return `${GREEN}yes${RESET} ${DIM}(${check.checked} secret(s) decrypt with this machine's key)${RESET}`;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function cmdStatus(store) {
|
|
357
|
+
const exists = store.exists();
|
|
358
|
+
// Asked here because "status" is exactly the question this answers, and
|
|
359
|
+
// because the answer used to be reassuring regardless of the truth.
|
|
360
|
+
const check = store.checkKey();
|
|
361
|
+
const source = store.keySource;
|
|
362
|
+
const socketPath = defaultSocketPath();
|
|
363
|
+
const listening = isControlPlaneListening(socketPath);
|
|
364
|
+
console.log(`
|
|
365
|
+
${GREEN}Vault${RESET} ${store.vaultPath} ${exists ? `${DIM}(${store.listServers().length} server(s))${RESET}` : `${YELLOW}— not created yet${RESET}`}
|
|
366
|
+
${GREEN}Key${RESET} ${source === 'keychain' ? `OS keychain ${DIM}(service: mcp-ssh-manager)${RESET}` : source === 'file' ? `${YELLOW}file${RESET} ${DIM}${path.join(path.dirname(defaultVaultPath()), 'vault.key')}${RESET}` : `${DIM}not unlocked${RESET}`}
|
|
367
|
+
${GREEN}Cipher${RESET} AES-256-GCM ${DIM}(authenticated: tampering is detected, not silently accepted)${RESET}
|
|
368
|
+
${GREEN}Encrypted${RESET} ${SECRET_FIELDS.join(', ')}
|
|
369
|
+
${GREEN}Readable${RESET} ${describeReadability(check)}
|
|
370
|
+
${GREEN}Recovery${RESET} ${DIM}ssh-manager vault backup <file> — the copy that survives a new machine${RESET}
|
|
371
|
+
|
|
372
|
+
${GREEN}Approval${RESET} ${listening ? `${GREEN}a control plane is listening${RESET}` : `${DIM}control plane unavailable${RESET}`}
|
|
373
|
+
${GREEN}Socket${RESET} ${socketPath}
|
|
374
|
+
${GREEN}Modes${RESET} ${[...VALID_APPROVAL_MODES].join(' / ')} ${DIM}(set per server in the control plane, default never)${RESET}
|
|
375
|
+
`);
|
|
376
|
+
if (source === 'file') {
|
|
377
|
+
console.log(`${YELLOW}Note:${RESET} no OS keychain was reachable, so the key sits next to the vault.`);
|
|
378
|
+
console.log(`${DIM}Still better than a clear-text .env, but the keychain is preferable on a desktop.${RESET}\n`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async function main() {
|
|
383
|
+
const [command, ...args] = process.argv.slice(2);
|
|
384
|
+
const store = new SecretStore(defaultVaultPath());
|
|
385
|
+
|
|
386
|
+
switch (command) {
|
|
387
|
+
case 'list': await cmdList(store); break;
|
|
388
|
+
case 'add': await cmdAdd(store, args[0]); break;
|
|
389
|
+
case 'remove': case 'rm': await cmdRemove(store, args[0]); break;
|
|
390
|
+
case 'import': {
|
|
391
|
+
const i = args.indexOf('--from');
|
|
392
|
+
await cmdImport(store, i >= 0 ? args[i + 1] : null);
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
case 'backup': await cmdBackup(store, args[0]); break;
|
|
396
|
+
case 'restore': await cmdRestore(store, args[0]); break;
|
|
397
|
+
case 'status': cmdStatus(store); break;
|
|
398
|
+
default: usage(); process.exit(command ? 1 : 0);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
main()
|
|
403
|
+
.then(closeReadline)
|
|
404
|
+
.catch(error => {
|
|
405
|
+
closeReadline();
|
|
406
|
+
// A vault whose key is gone throws a multi-line explanation of what to do
|
|
407
|
+
// about it; printing only `error.message` would still show all of it, but
|
|
408
|
+
// the exit code is what a script reads.
|
|
409
|
+
console.error(`${RED}${error.message}${RESET}`);
|
|
410
|
+
process.exit(1);
|
|
411
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// SSH Manager — the desktop shell.
|
|
2
|
+
//
|
|
3
|
+
// A window around the control plane the engine already serves. It starts
|
|
4
|
+
// `ssh-manager control` as a child process, reads the tokenised URL from its
|
|
5
|
+
// output, and shows that page in a WKWebView.
|
|
6
|
+
//
|
|
7
|
+
// Why not Electron: the thing to display is one HTML page that the engine
|
|
8
|
+
// already serves over localhost. Electron's runtime alone is 19 MB before any
|
|
9
|
+
// application code, and a packaged app is well past a hundred; this binary is a
|
|
10
|
+
// few hundred kilobytes and ships no browser of its own. The trade-off is that
|
|
11
|
+
// it is macOS-only — elsewhere `ssh-manager control` opens in the browser,
|
|
12
|
+
// which is the same interface.
|
|
13
|
+
//
|
|
14
|
+
// The child process is the interesting part. It holds the approval socket, so
|
|
15
|
+
// leaving it running after the window closes would keep agents blocked on a UI
|
|
16
|
+
// nobody can see; every exit path therefore terminates it.
|
|
17
|
+
|
|
18
|
+
import AppKit
|
|
19
|
+
import WebKit
|
|
20
|
+
|
|
21
|
+
// A GUI app launched from Finder inherits a minimal PATH — not the shell's —
|
|
22
|
+
// so `node` and `ssh-manager` are invisible unless we look for them. These are
|
|
23
|
+
// the standard install locations, plus whatever the user's login shell knows.
|
|
24
|
+
let candidatePaths = [
|
|
25
|
+
"/opt/homebrew/bin",
|
|
26
|
+
"/usr/local/bin",
|
|
27
|
+
"/usr/bin",
|
|
28
|
+
"\(NSHomeDirectory())/bin",
|
|
29
|
+
"\(NSHomeDirectory())/.local/bin",
|
|
30
|
+
"\(NSHomeDirectory())/.nvm/versions/node",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
/// Locate an executable by name, searching the usual install locations and, as
|
|
34
|
+
/// a last resort, asking the user's login shell where it is.
|
|
35
|
+
func findExecutable(_ name: String) -> String? {
|
|
36
|
+
for directory in candidatePaths {
|
|
37
|
+
let path = "\(directory)/\(name)"
|
|
38
|
+
if FileManager.default.isExecutableFile(atPath: path) { return path }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Ask a login shell: it sources the profile, so it knows about nvm, asdf,
|
|
42
|
+
// volta and anything else the user set up.
|
|
43
|
+
let shell = ProcessInfo.processInfo.environment["SHELL"] ?? "/bin/zsh"
|
|
44
|
+
let process = Process()
|
|
45
|
+
process.executableURL = URL(fileURLWithPath: shell)
|
|
46
|
+
process.arguments = ["-lc", "command -v \(name)"]
|
|
47
|
+
let pipe = Pipe()
|
|
48
|
+
process.standardOutput = pipe
|
|
49
|
+
process.standardError = FileHandle.nullDevice
|
|
50
|
+
do {
|
|
51
|
+
try process.run()
|
|
52
|
+
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
|
53
|
+
process.waitUntilExit()
|
|
54
|
+
let found = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
55
|
+
if let found, !found.isEmpty, FileManager.default.isExecutableFile(atPath: found) {
|
|
56
|
+
return found
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
return nil
|
|
60
|
+
}
|
|
61
|
+
return nil
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
final class AppDelegate: NSObject, NSApplicationDelegate, WKNavigationDelegate {
|
|
65
|
+
var window: NSWindow!
|
|
66
|
+
var webView: WKWebView!
|
|
67
|
+
var controlPlane: Process?
|
|
68
|
+
var statusLabel: NSTextField!
|
|
69
|
+
var signalSources: [DispatchSourceSignal] = []
|
|
70
|
+
|
|
71
|
+
func applicationDidFinishLaunching(_ notification: Notification) {
|
|
72
|
+
window = NSWindow(
|
|
73
|
+
contentRect: NSRect(x: 0, y: 0, width: 1100, height: 780),
|
|
74
|
+
styleMask: [.titled, .closable, .miniaturizable, .resizable],
|
|
75
|
+
backing: .buffered,
|
|
76
|
+
defer: false
|
|
77
|
+
)
|
|
78
|
+
window.title = "SSH Manager"
|
|
79
|
+
window.center()
|
|
80
|
+
window.setFrameAutosaveName("ControlPlaneWindow")
|
|
81
|
+
|
|
82
|
+
let configuration = WKWebViewConfiguration()
|
|
83
|
+
webView = WKWebView(frame: window.contentView!.bounds, configuration: configuration)
|
|
84
|
+
webView.autoresizingMask = [.width, .height]
|
|
85
|
+
webView.navigationDelegate = self
|
|
86
|
+
window.contentView?.addSubview(webView)
|
|
87
|
+
|
|
88
|
+
// Shown while the control plane starts, and left in place if it fails —
|
|
89
|
+
// a blank window would be indistinguishable from a hung one.
|
|
90
|
+
statusLabel = NSTextField(labelWithString: "Starting the control plane…")
|
|
91
|
+
statusLabel.frame = NSRect(x: 40, y: window.contentView!.bounds.height / 2, width: 1020, height: 60)
|
|
92
|
+
statusLabel.alignment = .center
|
|
93
|
+
statusLabel.font = NSFont.systemFont(ofSize: 14)
|
|
94
|
+
statusLabel.textColor = .secondaryLabelColor
|
|
95
|
+
statusLabel.autoresizingMask = [.width, .minYMargin, .maxYMargin]
|
|
96
|
+
window.contentView?.addSubview(statusLabel)
|
|
97
|
+
|
|
98
|
+
window.makeKeyAndOrderFront(nil)
|
|
99
|
+
NSApp.activate(ignoringOtherApps: true)
|
|
100
|
+
|
|
101
|
+
startControlPlane()
|
|
102
|
+
installSignalHandlers()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/// Terminate the child on signals AppKit does not turn into a clean quit.
|
|
106
|
+
/// Without this, `kill` on the app leaves the control plane running and
|
|
107
|
+
/// holding the approval socket.
|
|
108
|
+
func installSignalHandlers() {
|
|
109
|
+
for sig in [SIGTERM, SIGINT, SIGHUP] {
|
|
110
|
+
signal(sig, SIG_IGN)
|
|
111
|
+
let source = DispatchSource.makeSignalSource(signal: sig, queue: .main)
|
|
112
|
+
source.setEventHandler { NSApp.terminate(nil) }
|
|
113
|
+
source.resume()
|
|
114
|
+
signalSources.append(source)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// Launch `ssh-manager control` and wait for it to print its URL.
|
|
119
|
+
func startControlPlane() {
|
|
120
|
+
// SSH_MANAGER_CLI points at a specific CLI. Needed while developing —
|
|
121
|
+
// a machine can carry an older global install that predates `control` —
|
|
122
|
+
// and for any layout the search below does not know about.
|
|
123
|
+
let override = ProcessInfo.processInfo.environment["SSH_MANAGER_CLI"]
|
|
124
|
+
let located = override.flatMap { FileManager.default.isExecutableFile(atPath: $0) ? $0 : nil }
|
|
125
|
+
?? findExecutable("ssh-manager")
|
|
126
|
+
|
|
127
|
+
guard let sshManager = located else {
|
|
128
|
+
fail("""
|
|
129
|
+
Could not find ssh-manager.
|
|
130
|
+
|
|
131
|
+
Install it first:
|
|
132
|
+
npm install -g mcp-ssh-manager
|
|
133
|
+
or brew install ssh-manager
|
|
134
|
+
|
|
135
|
+
Already installed elsewhere? Point at it with SSH_MANAGER_CLI.
|
|
136
|
+
""")
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let process = Process()
|
|
141
|
+
process.executableURL = URL(fileURLWithPath: sshManager)
|
|
142
|
+
process.arguments = ["control"]
|
|
143
|
+
|
|
144
|
+
// Pass a PATH that includes the usual locations, so the CLI can find
|
|
145
|
+
// node even though this app was launched from Finder.
|
|
146
|
+
var environment = ProcessInfo.processInfo.environment
|
|
147
|
+
let existingPath = environment["PATH"] ?? ""
|
|
148
|
+
environment["PATH"] = (candidatePaths + [existingPath]).joined(separator: ":")
|
|
149
|
+
// Ask the control plane to stop when this app does, however it dies.
|
|
150
|
+
// Opt-in on purpose: inferring it killed control planes started with
|
|
151
|
+
// `ssh-manager control > log &`, where the launching shell exits at once.
|
|
152
|
+
environment["SSH_MANAGER_PARENT_WATCH"] = "1"
|
|
153
|
+
process.environment = environment
|
|
154
|
+
|
|
155
|
+
let pipe = Pipe()
|
|
156
|
+
process.standardOutput = pipe
|
|
157
|
+
process.standardError = pipe
|
|
158
|
+
|
|
159
|
+
var buffer = Data()
|
|
160
|
+
var opened = false
|
|
161
|
+
pipe.fileHandleForReading.readabilityHandler = { [weak self] handle in
|
|
162
|
+
let chunk = handle.availableData
|
|
163
|
+
guard !chunk.isEmpty else { return }
|
|
164
|
+
buffer.append(chunk)
|
|
165
|
+
guard !opened, let text = String(data: buffer, encoding: .utf8) else { return }
|
|
166
|
+
|
|
167
|
+
// The CLI prints the URL with its one-time token; that line is the
|
|
168
|
+
// signal that the socket and HTTP server are both up.
|
|
169
|
+
guard let range = text.range(of: #"http://127\.0\.0\.1:\d+/\?token=[a-f0-9]+"#, options: .regularExpression) else { return }
|
|
170
|
+
opened = true
|
|
171
|
+
let url = String(text[range])
|
|
172
|
+
DispatchQueue.main.async { self?.load(url) }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
process.terminationHandler = { [weak self] finished in
|
|
176
|
+
DispatchQueue.main.async {
|
|
177
|
+
guard !opened else { return }
|
|
178
|
+
self?.fail("The control plane stopped unexpectedly (exit \(finished.terminationStatus)).")
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
do {
|
|
183
|
+
try process.run()
|
|
184
|
+
controlPlane = process
|
|
185
|
+
} catch {
|
|
186
|
+
fail("Could not start the control plane: \(error.localizedDescription)")
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
func load(_ url: String) {
|
|
191
|
+
statusLabel.isHidden = true
|
|
192
|
+
webView.load(URLRequest(url: URL(string: url)!))
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
func fail(_ message: String) {
|
|
196
|
+
statusLabel.stringValue = message
|
|
197
|
+
statusLabel.isHidden = false
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// The child holds the approval socket. Leaving it alive after the window
|
|
201
|
+
// closes would keep agents waiting on a UI nobody can see.
|
|
202
|
+
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true }
|
|
203
|
+
|
|
204
|
+
func applicationWillTerminate(_ notification: Notification) {
|
|
205
|
+
controlPlane?.terminate()
|
|
206
|
+
// Give it a moment to refuse anything pending and release the socket.
|
|
207
|
+
let deadline = Date().addingTimeInterval(2)
|
|
208
|
+
while controlPlane?.isRunning == true && Date() < deadline {
|
|
209
|
+
usleep(50_000)
|
|
210
|
+
}
|
|
211
|
+
if controlPlane?.isRunning == true { kill(controlPlane!.processIdentifier, SIGKILL) }
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
let app = NSApplication.shared
|
|
216
|
+
let delegate = AppDelegate()
|
|
217
|
+
app.delegate = delegate
|
|
218
|
+
app.setActivationPolicy(.regular)
|
|
219
|
+
app.run()
|
package/desktop/build.sh
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Build SSH Manager.app — the desktop shell around the control plane.
|
|
3
|
+
#
|
|
4
|
+
# No Xcode project, no package manager: one Swift file, swiftc, and a bundle
|
|
5
|
+
# assembled by hand. Keeping it this small is the point — the window is a
|
|
6
|
+
# wrapper around a page the engine already serves.
|
|
7
|
+
set -euo pipefail
|
|
8
|
+
|
|
9
|
+
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
10
|
+
APP="${1:-$HERE/build/SSH Manager.app}"
|
|
11
|
+
VERSION="$(node -p "require('$HERE/../package.json').version")"
|
|
12
|
+
|
|
13
|
+
# Homebrew's Xcode may be older than the toolchain needed; prefer a beta when
|
|
14
|
+
# one is installed, as the released Xcode on this machine lags behind.
|
|
15
|
+
if [ -z "${DEVELOPER_DIR:-}" ] && [ -d /Applications/Xcode-beta.app ]; then
|
|
16
|
+
export DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer
|
|
17
|
+
fi
|
|
18
|
+
|
|
19
|
+
echo "Building SSH Manager.app ($VERSION)"
|
|
20
|
+
rm -rf "$APP"
|
|
21
|
+
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources"
|
|
22
|
+
|
|
23
|
+
cat > "$APP/Contents/Info.plist" <<PLIST
|
|
24
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
25
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
26
|
+
<plist version="1.0">
|
|
27
|
+
<dict>
|
|
28
|
+
<key>CFBundleName</key><string>SSH Manager</string>
|
|
29
|
+
<key>CFBundleDisplayName</key><string>SSH Manager</string>
|
|
30
|
+
<key>CFBundleIdentifier</key><string>com.bvisible.ssh-manager</string>
|
|
31
|
+
<key>CFBundleVersion</key><string>$VERSION</string>
|
|
32
|
+
<key>CFBundleShortVersionString</key><string>$VERSION</string>
|
|
33
|
+
<key>CFBundlePackageType</key><string>APPL</string>
|
|
34
|
+
<key>CFBundleExecutable</key><string>SSHManager</string>
|
|
35
|
+
<key>LSMinimumSystemVersion</key><string>13.0</string>
|
|
36
|
+
<key>NSHighResolutionCapable</key><true/>
|
|
37
|
+
<!-- The page is served from 127.0.0.1 over plain HTTP: it never leaves the
|
|
38
|
+
machine, and TLS on a loopback socket would only add a certificate to
|
|
39
|
+
manage. Scoped to localhost so nothing else is exempted. -->
|
|
40
|
+
<key>NSAppTransportSecurity</key>
|
|
41
|
+
<dict><key>NSAllowsLocalNetworking</key><true/></dict>
|
|
42
|
+
</dict>
|
|
43
|
+
</plist>
|
|
44
|
+
PLIST
|
|
45
|
+
|
|
46
|
+
xcrun swiftc \
|
|
47
|
+
-O \
|
|
48
|
+
-target arm64-apple-macosx13.0 \
|
|
49
|
+
-framework AppKit -framework WebKit \
|
|
50
|
+
-o "$APP/Contents/MacOS/SSHManager" \
|
|
51
|
+
"$HERE/ControlPlaneApp.swift"
|
|
52
|
+
|
|
53
|
+
# Ad-hoc signature: enough for the app to run on the machine that built it.
|
|
54
|
+
# A distributed build needs a Developer ID and notarisation.
|
|
55
|
+
codesign --force --sign - "$APP" 2>/dev/null || echo " (unsigned — fine for local use)"
|
|
56
|
+
|
|
57
|
+
echo "Built: $APP"
|
|
58
|
+
du -sh "$APP" | awk '{print " size: " $1}'
|