mcp-ssh-manager 3.8.5 → 3.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +80 -0
- package/README.md +12 -11
- package/cli/lib/menu.sh +2 -2
- package/docs/ALIASES_AND_HOOKS.md +54 -25
- package/docs/SECURITY_MODES.md +33 -3
- package/package.json +5 -3
- package/profiles/default.json +6 -4
- package/server.json +2 -2
- package/src/backup-manager.js +24 -1
- package/src/command-aliases.js +9 -6
- package/src/config-paths.js +12 -0
- package/src/database-manager.js +200 -21
- package/src/deploy-helper.js +15 -7
- package/src/hooks-system.js +298 -57
- package/src/index.js +39 -22
- package/src/logger.js +43 -17
- package/src/policy.js +46 -25
- package/src/profile-loader.js +18 -12
- package/src/server-aliases.js +9 -6
- package/src/shell-quote.js +8 -0
- package/src/shell-segments.js +189 -0
- package/src/ssh-key-manager.js +123 -76
- package/src/ssh-manager.js +17 -41
- package/src/user-state.js +60 -0
- package/.hooks-config.json +0 -131
package/src/ssh-key-manager.js
CHANGED
|
@@ -1,29 +1,101 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFileSync, spawn } from 'child_process';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import os from 'os';
|
|
5
5
|
import crypto from 'crypto';
|
|
6
6
|
import { logger } from './logger.js';
|
|
7
7
|
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
// The standard OpenSSH file remains the default. The override also lets tests
|
|
9
|
+
// and headless deployments isolate trust without touching a user's key files.
|
|
10
|
+
function knownHostsPath() {
|
|
11
|
+
return process.env.SSH_MANAGER_KNOWN_HOSTS || path.join(os.homedir(), '.ssh', 'known_hosts');
|
|
12
|
+
}
|
|
11
13
|
|
|
12
|
-
/**
|
|
13
|
-
* Parse a known_hosts entry
|
|
14
|
-
*/
|
|
14
|
+
/** Parse ordinary, hashed and marker-prefixed OpenSSH known_hosts entries. */
|
|
15
15
|
function parseKnownHostEntry(line) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
16
|
+
const parts = line.trim().split(/\s+/);
|
|
17
|
+
if (!parts[0] || parts[0].startsWith('#')) return null;
|
|
18
|
+
const marker = parts[0].startsWith('@') ? parts.shift() : null;
|
|
19
19
|
if (parts.length < 3) return null;
|
|
20
|
+
return { host: parts[0], keyType: parts[1], key: parts[2], marker,
|
|
21
|
+
comment: parts.slice(3).join(' ') || '' };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function hostEntryName(host, port) {
|
|
25
|
+
return Number(port) === 22 ? host.toLowerCase() : `[${host.toLowerCase()}]:${port}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function matchesHostPattern(pattern, host) {
|
|
29
|
+
if (pattern.startsWith('|1|')) {
|
|
30
|
+
const [, version, salt, expected] = pattern.split('|');
|
|
31
|
+
if (version !== '1' || !salt || !expected) return false;
|
|
32
|
+
const actual = crypto.createHmac('sha1', Buffer.from(salt, 'base64')).update(host).digest();
|
|
33
|
+
const hash = Buffer.from(expected, 'base64');
|
|
34
|
+
return actual.length === hash.length && crypto.timingSafeEqual(actual, hash);
|
|
35
|
+
}
|
|
36
|
+
const expression = pattern.toLowerCase().split('').map(char =>
|
|
37
|
+
char === '*' ? '.*' : char === '?' ? '.' : char.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('');
|
|
38
|
+
return new RegExp(`^${expression}$`).test(host);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function matchesHost(entry, host) {
|
|
42
|
+
let matched = false;
|
|
43
|
+
for (const pattern of entry.host.split(',')) {
|
|
44
|
+
if (pattern.startsWith('!')) {
|
|
45
|
+
if (matchesHostPattern(pattern.slice(1), host)) return false;
|
|
46
|
+
} else if (matchesHostPattern(pattern, host)) matched = true;
|
|
47
|
+
}
|
|
48
|
+
return matched;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function matchingEntries(host, port) {
|
|
52
|
+
let content;
|
|
53
|
+
try { content = fs.readFileSync(knownHostsPath(), 'utf8'); }
|
|
54
|
+
catch (error) { if (error.code === 'ENOENT') return []; throw error; }
|
|
55
|
+
const name = hostEntryName(host, port);
|
|
56
|
+
return content.split('\n').map(parseKnownHostEntry).filter(entry => entry && matchesHost(entry, name));
|
|
57
|
+
}
|
|
20
58
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
59
|
+
/** Prefer a stored key's algorithm so a multi-key server presents a trusted key. */
|
|
60
|
+
export function trustedHostKeyAlgorithms(host, port = 22) {
|
|
61
|
+
return [...new Set(matchingEntries(host, port)
|
|
62
|
+
.filter(entry => !entry.marker)
|
|
63
|
+
.flatMap(entry => entry.keyType === 'ssh-rsa'
|
|
64
|
+
? ['rsa-sha2-512', 'rsa-sha2-256', 'ssh-rsa'] : [entry.keyType]))];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Verify the actual handshake key. An unknown host is trusted on first use and
|
|
69
|
+
* that exact key is pinned synchronously before authentication can proceed.
|
|
70
|
+
* Existing entries, including hashed hostnames and revocations, fail closed.
|
|
71
|
+
*/
|
|
72
|
+
export function verifyHostKey(host, port, key) {
|
|
73
|
+
if (!Buffer.isBuffer(key) || key.length < 4) throw new Error('Invalid SSH host key');
|
|
74
|
+
const size = key.readUInt32BE(0);
|
|
75
|
+
if (size < 1 || size > key.length - 4) throw new Error('Invalid SSH host key');
|
|
76
|
+
const keyType = key.subarray(4, 4 + size).toString('ascii');
|
|
77
|
+
if (!/^[a-zA-Z0-9@._+-]+$/.test(keyType)) throw new Error('Invalid SSH host key type');
|
|
78
|
+
const encoded = key.toString('base64');
|
|
79
|
+
const entries = matchingEntries(host, port);
|
|
80
|
+
if (entries.some(entry => entry.marker === '@revoked' && entry.key === encoded)) {
|
|
81
|
+
throw new Error(`SSH host key is revoked for ${host}:${port}`);
|
|
82
|
+
}
|
|
83
|
+
if (entries.some(entry => !entry.marker && entry.key === encoded)) return true;
|
|
84
|
+
if (entries.length) {
|
|
85
|
+
throw new Error(`SSH host key changed or is not trusted for ${host}:${port}; verify the server identity before updating known_hosts`);
|
|
86
|
+
}
|
|
87
|
+
const name = hostEntryName(host, port);
|
|
88
|
+
if (/[\s,|!]/.test(name)) throw new Error('Invalid SSH hostname');
|
|
89
|
+
const file = knownHostsPath();
|
|
90
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
91
|
+
let prefix = '';
|
|
92
|
+
try {
|
|
93
|
+
const existing = fs.readFileSync(file, 'utf8');
|
|
94
|
+
if (existing && !existing.endsWith('\n')) prefix = '\n';
|
|
95
|
+
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
96
|
+
fs.appendFileSync(file, `${prefix}${name} ${keyType} ${encoded}\n`, { mode: 0o600 });
|
|
97
|
+
logger.info('SSH host key trusted on first use', { host, port });
|
|
98
|
+
return true;
|
|
27
99
|
}
|
|
28
100
|
|
|
29
101
|
/**
|
|
@@ -77,76 +149,51 @@ export async function getHostKeyFingerprint(host, port = 22) {
|
|
|
77
149
|
* Check if a host key exists in known_hosts
|
|
78
150
|
*/
|
|
79
151
|
export function isHostKnown(host, port = 22) {
|
|
80
|
-
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const content = fs.readFileSync(KNOWN_HOSTS_PATH, 'utf8');
|
|
85
|
-
const lines = content.split('\n');
|
|
86
|
-
|
|
87
|
-
// Format host entry as SSH does
|
|
88
|
-
const hostEntry = port === 22 ? host : `[${host}]:${port}`;
|
|
89
|
-
|
|
90
|
-
for (const line of lines) {
|
|
91
|
-
if (line.includes(hostEntry)) {
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return false;
|
|
152
|
+
return matchingEntries(host, port).length > 0;
|
|
97
153
|
}
|
|
98
154
|
|
|
99
|
-
/**
|
|
100
|
-
* Get current host key from known_hosts
|
|
101
|
-
*/
|
|
155
|
+
/** Get matching trusted fingerprints without contacting the server. */
|
|
102
156
|
export function getCurrentHostKey(host, port = 22) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// Format host entry as SSH does
|
|
111
|
-
const hostEntry = port === 22 ? host : `[${host}]:${port}`;
|
|
112
|
-
const keys = [];
|
|
113
|
-
|
|
114
|
-
for (const line of lines) {
|
|
115
|
-
if (line.includes(hostEntry)) {
|
|
116
|
-
const entry = parseKnownHostEntry(line);
|
|
117
|
-
if (entry) {
|
|
118
|
-
const keyData = Buffer.from(entry.key, 'base64');
|
|
119
|
-
const hash = crypto.createHash('sha256').update(keyData).digest('base64');
|
|
120
|
-
|
|
121
|
-
keys.push({
|
|
122
|
-
host: entry.host,
|
|
123
|
-
type: entry.keyType,
|
|
124
|
-
fingerprint: `SHA256:${hash}`,
|
|
125
|
-
fullKey: line
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return keys.length > 0 ? keys : null;
|
|
157
|
+
const keys = matchingEntries(host, port).map(entry => ({
|
|
158
|
+
host: entry.host, type: entry.keyType,
|
|
159
|
+
fingerprint: `SHA256:${crypto.createHash('sha256').update(Buffer.from(entry.key, 'base64')).digest('base64')}`,
|
|
160
|
+
fullKey: `${entry.marker ? `${entry.marker} ` : ''}${entry.host} ${entry.keyType} ${entry.key}`,
|
|
161
|
+
}));
|
|
162
|
+
return keys.length ? keys : null;
|
|
132
163
|
}
|
|
133
164
|
|
|
134
165
|
/**
|
|
135
166
|
* Remove a host from known_hosts
|
|
136
167
|
*/
|
|
137
168
|
export function removeHostKey(host, port = 22) {
|
|
138
|
-
|
|
139
|
-
const hostEntry = port === 22 ? host : `[${host}]:${port}`;
|
|
169
|
+
const hostEntry = port === 22 ? host : `[${host}]:${port}`;
|
|
140
170
|
|
|
141
|
-
|
|
142
|
-
|
|
171
|
+
// Was it there to begin with? ssh-keygen -R succeeds either way, so without
|
|
172
|
+
// this the function would report success for a host it never touched — and a
|
|
173
|
+
// control plane would tell an operator it forgot a key that is still there.
|
|
174
|
+
// Return before touching ssh-keygen when there is nothing to remove: the
|
|
175
|
+
// command fails outright where no known_hosts file exists at all (a fresh CI
|
|
176
|
+
// runner, a container), and reporting that as an error would be wrong — there
|
|
177
|
+
// was simply no key.
|
|
178
|
+
if (!isHostKnown(host, port)) {
|
|
179
|
+
logger.info('No host key to remove', { host, port });
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
143
182
|
|
|
144
|
-
|
|
145
|
-
|
|
183
|
+
try {
|
|
184
|
+
// execFileSync, not execSync: arguments are passed to the process directly
|
|
185
|
+
// instead of through a shell. `host` comes from a server config, which an
|
|
186
|
+
// operator (or the control plane's own form) can set to anything, so a
|
|
187
|
+
// value containing a quote or $(...) used to be a command injection here —
|
|
188
|
+
// the same class of bug fixed across the database and backup builders.
|
|
189
|
+
execFileSync('ssh-keygen', ['-R', hostEntry, '-f', knownHostsPath()], { stdio: 'ignore' });
|
|
146
190
|
} catch (error) {
|
|
147
191
|
logger.error('Failed to remove host key', { host, port, error: error.message });
|
|
148
192
|
throw new Error(`Failed to remove host key: ${error.message}`);
|
|
149
193
|
}
|
|
194
|
+
|
|
195
|
+
logger.info('Host key removed', { host, port });
|
|
196
|
+
return true;
|
|
150
197
|
}
|
|
151
198
|
|
|
152
199
|
/**
|
|
@@ -159,7 +206,7 @@ export async function addHostKey(host, port = 22, keyData = null) {
|
|
|
159
206
|
// file can be replaced, and the check adds a race without preventing the
|
|
160
207
|
// failure it appears to guard against.
|
|
161
208
|
try {
|
|
162
|
-
fs.copyFileSync(
|
|
209
|
+
fs.copyFileSync(knownHostsPath(), `${knownHostsPath()}.mcp-backup`);
|
|
163
210
|
} catch (error) {
|
|
164
211
|
if (error.code !== 'ENOENT') throw error;
|
|
165
212
|
}
|
|
@@ -176,11 +223,11 @@ export async function addHostKey(host, port = 22, keyData = null) {
|
|
|
176
223
|
// Ensure .ssh directory exists. No existsSync guard: mkdirSync with
|
|
177
224
|
// recursive:true is already a no-op on an existing directory, and checking
|
|
178
225
|
// first only opens a window where the directory can change underneath us.
|
|
179
|
-
const sshDir = path.dirname(
|
|
226
|
+
const sshDir = path.dirname(knownHostsPath());
|
|
180
227
|
fs.mkdirSync(sshDir, { mode: 0o700, recursive: true });
|
|
181
228
|
|
|
182
229
|
// Append to known_hosts
|
|
183
|
-
fs.appendFileSync(
|
|
230
|
+
fs.appendFileSync(knownHostsPath(), keyData + '\n', { mode: 0o600 });
|
|
184
231
|
|
|
185
232
|
logger.info('Host key added', { host, port });
|
|
186
233
|
return true;
|
|
@@ -251,11 +298,11 @@ export async function hasHostKeyChanged(host, port = 22) {
|
|
|
251
298
|
* List all known hosts
|
|
252
299
|
*/
|
|
253
300
|
export function listKnownHosts() {
|
|
254
|
-
if (!fs.existsSync(
|
|
301
|
+
if (!fs.existsSync(knownHostsPath())) {
|
|
255
302
|
return [];
|
|
256
303
|
}
|
|
257
304
|
|
|
258
|
-
const content = fs.readFileSync(
|
|
305
|
+
const content = fs.readFileSync(knownHostsPath(), 'utf8');
|
|
259
306
|
const lines = content.split('\n');
|
|
260
307
|
const hosts = new Map();
|
|
261
308
|
|
package/src/ssh-manager.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Client } from 'ssh2';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import os from 'os';
|
|
4
|
-
import {
|
|
4
|
+
import { trustedHostKeyAlgorithms, verifyHostKey } from './ssh-key-manager.js';
|
|
5
5
|
import { logger } from './logger.js';
|
|
6
|
+
import { shellPath } from './shell-quote.js';
|
|
6
7
|
|
|
7
8
|
// Validate liveness-probe output across shells (bash, cmd.exe, PowerShell).
|
|
8
9
|
// Normalize CRLF, stray quotes/backslashes and case before matching so quoted
|
|
@@ -107,46 +108,20 @@ class SSHManager {
|
|
|
107
108
|
}
|
|
108
109
|
};
|
|
109
110
|
|
|
110
|
-
//
|
|
111
|
+
// Verify the key ssh2 received on this connection, never a second
|
|
112
|
+
// ssh-keyscan connection. First contact remains noninteractive TOFU;
|
|
113
|
+
// a changed known key is refused before credentials are sent.
|
|
114
|
+
// Up to 3.8.5 this callback accepted every key (GHSA-cwg3-pfmm-w8rm).
|
|
111
115
|
if (this.hostKeyVerification) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
logger.info('Host key verified', { host, port });
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Host is not known
|
|
125
|
-
logger.info('New host detected', { host, port });
|
|
126
|
-
|
|
127
|
-
// If autoAcceptHostKey is enabled, accept and add the key
|
|
128
|
-
if (this.autoAcceptHostKey) {
|
|
129
|
-
logger.info('Auto-accept host key', { host, port });
|
|
130
|
-
// Schedule key addition after connection
|
|
131
|
-
setImmediate(async () => {
|
|
132
|
-
try {
|
|
133
|
-
await addHostKey(host, port);
|
|
134
|
-
logger.info('Host key added', { host, port });
|
|
135
|
-
} catch (err) {
|
|
136
|
-
logger.warn('Failed to add host key', {
|
|
137
|
-
host,
|
|
138
|
-
port,
|
|
139
|
-
error: err.message
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
return true;
|
|
116
|
+
const trusted = trustedHostKeyAlgorithms(this.config.host, this.config.port || 22);
|
|
117
|
+
if (trusted.length) connConfig.algorithms.serverHostKey = trusted;
|
|
118
|
+
connConfig.hostVerifier = key => {
|
|
119
|
+
try {
|
|
120
|
+
return verifyHostKey(this.config.host, this.config.port || 22, key);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
reject(error);
|
|
123
|
+
return false;
|
|
144
124
|
}
|
|
145
|
-
|
|
146
|
-
// For backward compatibility, accept new hosts by default
|
|
147
|
-
// In production, you might want to prompt the user or check a whitelist
|
|
148
|
-
logger.warn('Auto-accepting new host', { host, port });
|
|
149
|
-
return true;
|
|
150
125
|
};
|
|
151
126
|
}
|
|
152
127
|
|
|
@@ -189,7 +164,8 @@ class SSHManager {
|
|
|
189
164
|
}
|
|
190
165
|
|
|
191
166
|
const { timeout = 30000, cwd, rawCommand = false, stdin = null } = options;
|
|
192
|
-
|
|
167
|
+
// Quoted: a working directory is data, never shell code (GHSA-37fv-fcpc-j236).
|
|
168
|
+
const fullCommand = (cwd && !rawCommand) ? `cd -- ${shellPath(cwd)} && ${command}` : command;
|
|
193
169
|
|
|
194
170
|
return new Promise((resolve, reject) => {
|
|
195
171
|
let stdout = '';
|
|
@@ -297,7 +273,7 @@ class SSHManager {
|
|
|
297
273
|
}
|
|
298
274
|
|
|
299
275
|
const { cwd, onStdout, onStderr } = options;
|
|
300
|
-
const fullCommand = cwd ? `cd ${cwd} && ${command}` : command;
|
|
276
|
+
const fullCommand = cwd ? `cd -- ${shellPath(cwd)} && ${command}` : command;
|
|
301
277
|
|
|
302
278
|
return new Promise((resolve, reject) => {
|
|
303
279
|
this.client.exec(fullCommand, (err, stream) => {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings a user changes while the server runs: hooks, command and server
|
|
3
|
+
* aliases, the active profile.
|
|
4
|
+
*
|
|
5
|
+
* Up to 3.8.5 they were written inside the installed package. Every upgrade
|
|
6
|
+
* replaced that directory, so a change made through a tool vanished on the
|
|
7
|
+
* next `npm install -g`, and the server needed write access to its own
|
|
8
|
+
* install directory (issue #87). They now live beside the .env, in
|
|
9
|
+
* SSH_MANAGER_HOME (~/.ssh-manager by default), readable by their owner only.
|
|
10
|
+
*
|
|
11
|
+
* The old file is still read while the new one does not exist, so a source
|
|
12
|
+
* checkout keeps what it had until its next change writes the new file.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import fs from 'fs';
|
|
16
|
+
import path from 'path';
|
|
17
|
+
import { managerHome } from './config-paths.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} name - File name inside the manager home
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
function userStatePath(name) {
|
|
24
|
+
return path.join(managerHome(), name);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Read a state file, falling back to its pre-4.0 location inside the package.
|
|
29
|
+
* @param {string} name - File name inside the manager home
|
|
30
|
+
* @param {string} [legacyFile] - Absolute path of the old file, if any
|
|
31
|
+
* @returns {{file: string, text: string}|null} null when neither exists
|
|
32
|
+
*/
|
|
33
|
+
export function readUserState(name, legacyFile) {
|
|
34
|
+
for (const file of [userStatePath(name), legacyFile]) {
|
|
35
|
+
if (!file) continue;
|
|
36
|
+
try {
|
|
37
|
+
return { file, text: fs.readFileSync(file, 'utf8') };
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (error.code !== 'ENOENT') throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Replace a state file atomically, creating the manager home if needed. The
|
|
47
|
+
* directory is created 0700 and the file 0600: these files name servers and
|
|
48
|
+
* commands, which are nobody else's business on a shared machine.
|
|
49
|
+
* @param {string} name - File name inside the manager home
|
|
50
|
+
* @param {string} text - Complete new contents
|
|
51
|
+
* @returns {string} The path written
|
|
52
|
+
*/
|
|
53
|
+
export function writeUserState(name, text) {
|
|
54
|
+
const file = userStatePath(name);
|
|
55
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
56
|
+
const temp = `${file}.${process.pid}.tmp`;
|
|
57
|
+
fs.writeFileSync(temp, text, { mode: 0o600 });
|
|
58
|
+
fs.renameSync(temp, file);
|
|
59
|
+
return file;
|
|
60
|
+
}
|
package/.hooks-config.json
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"pre-deploy": {
|
|
3
|
-
"enabled": true,
|
|
4
|
-
"description": "Run before any deployment",
|
|
5
|
-
"actions": [
|
|
6
|
-
{
|
|
7
|
-
"type": "validation",
|
|
8
|
-
"name": "check-git-status",
|
|
9
|
-
"command": "git status --porcelain",
|
|
10
|
-
"expectEmpty": true,
|
|
11
|
-
"errorMessage": "Uncommitted changes detected. Please commit or stash changes before deployment."
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"type": "validation",
|
|
15
|
-
"name": "run-tests",
|
|
16
|
-
"command": "npm test 2>/dev/null || echo \"No tests configured\"",
|
|
17
|
-
"optional": true
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
},
|
|
21
|
-
"post-deploy": {
|
|
22
|
-
"enabled": true,
|
|
23
|
-
"description": "Run after successful deployment",
|
|
24
|
-
"actions": [
|
|
25
|
-
{
|
|
26
|
-
"type": "notification",
|
|
27
|
-
"name": "log-deployment",
|
|
28
|
-
"command": "echo \"[$(date)] Deployment completed to {server}\" >> deployments.log"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"type": "notification",
|
|
32
|
-
"name": "notify-slack",
|
|
33
|
-
"command": "curl -X POST -H \"Content-Type: application/json\" -d \"{{\\\"text\\\":\\\"Deployment to {server} completed\\\"}}\" $SLACK_WEBHOOK_URL 2>/dev/null || true",
|
|
34
|
-
"optional": true,
|
|
35
|
-
"requiresEnv": [
|
|
36
|
-
"SLACK_WEBHOOK_URL"
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
},
|
|
41
|
-
"on-error": {
|
|
42
|
-
"enabled": true,
|
|
43
|
-
"description": "Run when an error occurs",
|
|
44
|
-
"actions": [
|
|
45
|
-
{
|
|
46
|
-
"type": "notification",
|
|
47
|
-
"name": "log-error",
|
|
48
|
-
"command": "echo \"[$(date)] Error on {server}: {error}\" >> errors.log"
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"type": "recovery",
|
|
52
|
-
"name": "attempt-recovery",
|
|
53
|
-
"remoteCommand": "bench restart && bench clear-cache",
|
|
54
|
-
"server": "{server}",
|
|
55
|
-
"optional": true
|
|
56
|
-
}
|
|
57
|
-
]
|
|
58
|
-
},
|
|
59
|
-
"pre-bench-update": {
|
|
60
|
-
"enabled": true,
|
|
61
|
-
"description": "Run before bench update",
|
|
62
|
-
"actions": [
|
|
63
|
-
{
|
|
64
|
-
"type": "backup",
|
|
65
|
-
"name": "backup-database",
|
|
66
|
-
"remoteCommand": "bench --site all backup --with-files",
|
|
67
|
-
"server": "{server}"
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
"type": "validation",
|
|
71
|
-
"name": "check-disk-space",
|
|
72
|
-
"remoteCommand": "df -h | grep -E \"/$|/home\" | awk '{print $5}' | sed 's/%//' | awk '{if($1 > 80) exit 1}'",
|
|
73
|
-
"server": "{server}",
|
|
74
|
-
"errorMessage": "Insufficient disk space (>80% used)"
|
|
75
|
-
}
|
|
76
|
-
]
|
|
77
|
-
},
|
|
78
|
-
"post-bench-update": {
|
|
79
|
-
"enabled": true,
|
|
80
|
-
"description": "Run after bench update",
|
|
81
|
-
"actions": [
|
|
82
|
-
{
|
|
83
|
-
"type": "verification",
|
|
84
|
-
"name": "check-services",
|
|
85
|
-
"remoteCommand": "supervisorctl status | grep -E \"RUNNING|STOPPED\"",
|
|
86
|
-
"server": "{server}"
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
"type": "verification",
|
|
90
|
-
"name": "check-site-status",
|
|
91
|
-
"remoteCommand": "bench --site all doctor",
|
|
92
|
-
"server": "{server}"
|
|
93
|
-
}
|
|
94
|
-
]
|
|
95
|
-
},
|
|
96
|
-
"pre-connect": {
|
|
97
|
-
"enabled": false,
|
|
98
|
-
"description": "Run before connecting to a server",
|
|
99
|
-
"actions": [
|
|
100
|
-
{
|
|
101
|
-
"type": "validation",
|
|
102
|
-
"name": "check-vpn",
|
|
103
|
-
"command": "ping -c 1 -W 2 10.0.0.1 > /dev/null 2>&1",
|
|
104
|
-
"errorMessage": "VPN not connected",
|
|
105
|
-
"optional": true
|
|
106
|
-
}
|
|
107
|
-
]
|
|
108
|
-
},
|
|
109
|
-
"post-connect": {
|
|
110
|
-
"enabled": false,
|
|
111
|
-
"description": "Run after successful connection",
|
|
112
|
-
"actions": [
|
|
113
|
-
{
|
|
114
|
-
"type": "notification",
|
|
115
|
-
"name": "log-connection",
|
|
116
|
-
"command": "echo \"[$(date)] Connected to {server}\" >> connections.log"
|
|
117
|
-
}
|
|
118
|
-
]
|
|
119
|
-
},
|
|
120
|
-
"context-test": {
|
|
121
|
-
"enabled": true,
|
|
122
|
-
"description": "Context replacement test",
|
|
123
|
-
"actions": [
|
|
124
|
-
{
|
|
125
|
-
"type": "notification",
|
|
126
|
-
"name": "use-context",
|
|
127
|
-
"command": "echo \"Server: {server}, Error: {error}\" > /tmp/mcp-ssh-manager-context-test.txt"
|
|
128
|
-
}
|
|
129
|
-
]
|
|
130
|
-
}
|
|
131
|
-
}
|