@zincapp/znvault-cli 2.29.1 → 2.29.2
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/dist/commands/agent/direct/update-all.d.ts.map +1 -1
- package/dist/commands/agent/direct/update-all.js +13 -8
- package/dist/commands/agent/direct/update-all.js.map +1 -1
- package/dist/commands/agent/helpers.d.ts +3 -6
- package/dist/commands/agent/helpers.d.ts.map +1 -1
- package/dist/commands/agent/helpers.js +13 -21
- package/dist/commands/agent/helpers.js.map +1 -1
- package/dist/commands/apikey/helpers.d.ts +1 -2
- package/dist/commands/apikey/helpers.d.ts.map +1 -1
- package/dist/commands/apikey/helpers.js +2 -12
- package/dist/commands/apikey/helpers.js.map +1 -1
- package/dist/commands/backup/helpers.d.ts +1 -3
- package/dist/commands/backup/helpers.d.ts.map +1 -1
- package/dist/commands/backup/helpers.js +2 -23
- package/dist/commands/backup/helpers.js.map +1 -1
- package/dist/commands/device.d.ts.map +1 -1
- package/dist/commands/device.js +10 -6
- package/dist/commands/device.js.map +1 -1
- package/dist/commands/dynamic-secrets/helpers.d.ts +3 -2
- package/dist/commands/dynamic-secrets/helpers.d.ts.map +1 -1
- package/dist/commands/dynamic-secrets/helpers.js +6 -15
- package/dist/commands/dynamic-secrets/helpers.js.map +1 -1
- package/dist/commands/kms/crud.d.ts +6 -0
- package/dist/commands/kms/crud.d.ts.map +1 -0
- package/dist/commands/kms/crud.js +226 -0
- package/dist/commands/kms/crud.js.map +1 -0
- package/dist/commands/kms/crypto.d.ts +6 -0
- package/dist/commands/kms/crypto.d.ts.map +1 -0
- package/dist/commands/kms/crypto.js +190 -0
- package/dist/commands/kms/crypto.js.map +1 -0
- package/dist/commands/kms/helpers.d.ts +10 -0
- package/dist/commands/kms/helpers.d.ts.map +1 -0
- package/dist/commands/kms/helpers.js +44 -0
- package/dist/commands/kms/helpers.js.map +1 -0
- package/dist/commands/kms/index.d.ts +13 -0
- package/dist/commands/kms/index.d.ts.map +1 -0
- package/dist/commands/kms/index.js +18 -0
- package/dist/commands/kms/index.js.map +1 -0
- package/dist/commands/kms/lifecycle.d.ts +6 -0
- package/dist/commands/kms/lifecycle.d.ts.map +1 -0
- package/dist/commands/kms/lifecycle.js +124 -0
- package/dist/commands/kms/lifecycle.js.map +1 -0
- package/dist/commands/kms/types.d.ts +102 -0
- package/dist/commands/kms/types.d.ts.map +1 -0
- package/dist/commands/kms/types.js +3 -0
- package/dist/commands/kms/types.js.map +1 -0
- package/dist/commands/plugin/enable-disable.d.ts +6 -0
- package/dist/commands/plugin/enable-disable.d.ts.map +1 -0
- package/dist/commands/plugin/enable-disable.js +64 -0
- package/dist/commands/plugin/enable-disable.js.map +1 -0
- package/dist/commands/plugin/helpers.d.ts +63 -0
- package/dist/commands/plugin/helpers.d.ts.map +1 -0
- package/dist/commands/plugin/helpers.js +204 -0
- package/dist/commands/plugin/helpers.js.map +1 -0
- package/dist/commands/plugin/index.d.ts +10 -0
- package/dist/commands/plugin/index.d.ts.map +1 -0
- package/dist/commands/plugin/index.js +24 -0
- package/dist/commands/plugin/index.js.map +1 -0
- package/dist/commands/plugin/info.d.ts +6 -0
- package/dist/commands/plugin/info.d.ts.map +1 -0
- package/dist/commands/plugin/info.js +108 -0
- package/dist/commands/plugin/info.js.map +1 -0
- package/dist/commands/plugin/install.d.ts +6 -0
- package/dist/commands/plugin/install.d.ts.map +1 -0
- package/dist/commands/plugin/install.js +96 -0
- package/dist/commands/plugin/install.js.map +1 -0
- package/dist/commands/plugin/list.d.ts +6 -0
- package/dist/commands/plugin/list.d.ts.map +1 -0
- package/dist/commands/plugin/list.js +60 -0
- package/dist/commands/plugin/list.js.map +1 -0
- package/dist/commands/plugin/types.d.ts +37 -0
- package/dist/commands/plugin/types.d.ts.map +1 -0
- package/dist/commands/plugin/types.js +7 -0
- package/dist/commands/plugin/types.js.map +1 -0
- package/dist/commands/plugin/uninstall.d.ts +6 -0
- package/dist/commands/plugin/uninstall.d.ts.map +1 -0
- package/dist/commands/plugin/uninstall.js +50 -0
- package/dist/commands/plugin/uninstall.js.map +1 -0
- package/dist/commands/plugin/update.d.ts +6 -0
- package/dist/commands/plugin/update.d.ts.map +1 -0
- package/dist/commands/plugin/update.js +84 -0
- package/dist/commands/plugin/update.js.map +1 -0
- package/dist/commands/policy/attachments.d.ts.map +1 -1
- package/dist/commands/policy/attachments.js +14 -20
- package/dist/commands/policy/attachments.js.map +1 -1
- package/dist/commands/policy/crud.d.ts.map +1 -1
- package/dist/commands/policy/crud.js +13 -23
- package/dist/commands/policy/crud.js.map +1 -1
- package/dist/commands/policy/io.d.ts.map +1 -1
- package/dist/commands/policy/io.js +4 -5
- package/dist/commands/policy/io.js.map +1 -1
- package/dist/commands/policy/list.d.ts.map +1 -1
- package/dist/commands/policy/list.js +7 -8
- package/dist/commands/policy/list.js.map +1 -1
- package/dist/commands/quarantine.d.ts.map +1 -1
- package/dist/commands/quarantine.js +1 -9
- package/dist/commands/quarantine.js.map +1 -1
- package/dist/commands/role.d.ts.map +1 -1
- package/dist/commands/role.js +4 -10
- package/dist/commands/role.js.map +1 -1
- package/dist/commands/secret/helpers.d.ts +1 -2
- package/dist/commands/secret/helpers.d.ts.map +1 -1
- package/dist/commands/secret/helpers.js +2 -14
- package/dist/commands/secret/helpers.js.map +1 -1
- package/dist/commands/secret/list.d.ts.map +1 -1
- package/dist/commands/secret/list.js +3 -4
- package/dist/commands/secret/list.js.map +1 -1
- package/dist/commands/ssh/bookmark.d.ts +11 -0
- package/dist/commands/ssh/bookmark.d.ts.map +1 -0
- package/dist/commands/ssh/bookmark.js +210 -0
- package/dist/commands/ssh/bookmark.js.map +1 -0
- package/dist/commands/ssh/ca.d.ts +6 -0
- package/dist/commands/ssh/ca.d.ts.map +1 -0
- package/dist/commands/ssh/ca.js +162 -0
- package/dist/commands/ssh/ca.js.map +1 -0
- package/dist/commands/ssh/cert.d.ts +6 -0
- package/dist/commands/ssh/cert.d.ts.map +1 -0
- package/dist/commands/ssh/cert.js +303 -0
- package/dist/commands/ssh/cert.js.map +1 -0
- package/dist/commands/ssh/config.d.ts +6 -0
- package/dist/commands/ssh/config.d.ts.map +1 -0
- package/dist/commands/ssh/config.js +95 -0
- package/dist/commands/ssh/config.js.map +1 -0
- package/dist/commands/ssh/connect.d.ts +6 -0
- package/dist/commands/ssh/connect.d.ts.map +1 -0
- package/dist/commands/ssh/connect.js +219 -0
- package/dist/commands/ssh/connect.js.map +1 -0
- package/dist/commands/ssh/exec.d.ts +6 -0
- package/dist/commands/ssh/exec.d.ts.map +1 -0
- package/dist/commands/ssh/exec.js +218 -0
- package/dist/commands/ssh/exec.js.map +1 -0
- package/dist/commands/ssh/helpers.d.ts +46 -0
- package/dist/commands/ssh/helpers.d.ts.map +1 -0
- package/dist/commands/ssh/helpers.js +175 -0
- package/dist/commands/ssh/helpers.js.map +1 -0
- package/dist/commands/ssh/hosts.d.ts +6 -0
- package/dist/commands/ssh/hosts.d.ts.map +1 -0
- package/dist/commands/ssh/hosts.js +101 -0
- package/dist/commands/ssh/hosts.js.map +1 -0
- package/dist/commands/ssh/index.d.ts +20 -0
- package/dist/commands/ssh/index.d.ts.map +1 -0
- package/dist/commands/ssh/index.js +34 -0
- package/dist/commands/ssh/index.js.map +1 -0
- package/dist/commands/ssh/mapping.d.ts +6 -0
- package/dist/commands/ssh/mapping.d.ts.map +1 -0
- package/dist/commands/ssh/mapping.js +130 -0
- package/dist/commands/ssh/mapping.js.map +1 -0
- package/dist/commands/ssh/scp.d.ts +6 -0
- package/dist/commands/ssh/scp.d.ts.map +1 -0
- package/dist/commands/ssh/scp.js +219 -0
- package/dist/commands/ssh/scp.js.map +1 -0
- package/dist/commands/ssh/server-group.d.ts +6 -0
- package/dist/commands/ssh/server-group.d.ts.map +1 -0
- package/dist/commands/ssh/server-group.js +249 -0
- package/dist/commands/ssh/server-group.js.map +1 -0
- package/dist/commands/ssh/types.d.ts +150 -0
- package/dist/commands/ssh/types.d.ts.map +1 -0
- package/dist/commands/ssh/types.js +3 -0
- package/dist/commands/ssh/types.js.map +1 -0
- package/dist/commands/ssh-ca/helpers.d.ts +1 -8
- package/dist/commands/ssh-ca/helpers.d.ts.map +1 -1
- package/dist/commands/ssh-ca/helpers.js +2 -23
- package/dist/commands/ssh-ca/helpers.js.map +1 -1
- package/dist/commands/sso/crud.d.ts +6 -0
- package/dist/commands/sso/crud.d.ts.map +1 -0
- package/dist/commands/sso/crud.js +360 -0
- package/dist/commands/sso/crud.js.map +1 -0
- package/dist/commands/sso/helpers.d.ts +9 -0
- package/dist/commands/sso/helpers.d.ts.map +1 -0
- package/dist/commands/sso/helpers.js +13 -0
- package/dist/commands/sso/helpers.js.map +1 -0
- package/dist/commands/sso/index.d.ts +13 -0
- package/dist/commands/sso/index.d.ts.map +1 -0
- package/dist/commands/sso/index.js +16 -0
- package/dist/commands/sso/index.js.map +1 -0
- package/dist/commands/sso/types.d.ts +119 -0
- package/dist/commands/sso/types.d.ts.map +1 -0
- package/dist/commands/sso/types.js +3 -0
- package/dist/commands/sso/types.js.map +1 -0
- package/dist/commands/sso/users.d.ts +6 -0
- package/dist/commands/sso/users.d.ts.map +1 -0
- package/dist/commands/sso/users.js +128 -0
- package/dist/commands/sso/users.js.map +1 -0
- package/dist/commands/unseal.d.ts.map +1 -1
- package/dist/commands/unseal.js +10 -20
- package/dist/commands/unseal.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/cli-update.d.ts.map +1 -1
- package/dist/lib/cli-update.js +18 -14
- package/dist/lib/cli-update.js.map +1 -1
- package/dist/lib/client/http.d.ts +3 -1
- package/dist/lib/client/http.d.ts.map +1 -1
- package/dist/lib/client/http.js +41 -8
- package/dist/lib/client/http.js.map +1 -1
- package/dist/lib/config/autounseal.d.ts +4 -0
- package/dist/lib/config/autounseal.d.ts.map +1 -1
- package/dist/lib/config/autounseal.js +102 -6
- package/dist/lib/config/autounseal.js.map +1 -1
- package/dist/lib/config/credentials.d.ts.map +1 -1
- package/dist/lib/config/credentials.js +3 -2
- package/dist/lib/config/credentials.js.map +1 -1
- package/dist/lib/config/index.d.ts +2 -1
- package/dist/lib/config/index.d.ts.map +1 -1
- package/dist/lib/config/index.js +3 -1
- package/dist/lib/config/index.js.map +1 -1
- package/dist/lib/config/keychain.d.ts +27 -0
- package/dist/lib/config/keychain.d.ts.map +1 -0
- package/dist/lib/config/keychain.js +194 -0
- package/dist/lib/config/keychain.js.map +1 -0
- package/dist/lib/config/types.d.ts +12 -0
- package/dist/lib/config/types.d.ts.map +1 -1
- package/dist/lib/config/types.js +3 -2
- package/dist/lib/config/types.js.map +1 -1
- package/dist/lib/constants.d.ts +24 -0
- package/dist/lib/constants.d.ts.map +1 -1
- package/dist/lib/constants.js +34 -1
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/db/health.d.ts.map +1 -1
- package/dist/lib/db/health.js +14 -7
- package/dist/lib/db/health.js.map +1 -1
- package/dist/lib/debug.d.ts +17 -0
- package/dist/lib/debug.d.ts.map +1 -0
- package/dist/lib/debug.js +50 -0
- package/dist/lib/debug.js.map +1 -0
- package/dist/lib/format-helpers.d.ts +43 -0
- package/dist/lib/format-helpers.d.ts.map +1 -1
- package/dist/lib/format-helpers.js +85 -0
- package/dist/lib/format-helpers.js.map +1 -1
- package/dist/lib/local.d.ts.map +1 -1
- package/dist/lib/local.js +12 -8
- package/dist/lib/local.js.map +1 -1
- package/dist/lib/mode.d.ts.map +1 -1
- package/dist/lib/mode.js +2 -1
- package/dist/lib/mode.js.map +1 -1
- package/dist/lib/output.d.ts +10 -0
- package/dist/lib/output.d.ts.map +1 -1
- package/dist/lib/output.js +21 -0
- package/dist/lib/output.js.map +1 -1
- package/dist/services/auto-update-daemon.d.ts.map +1 -1
- package/dist/services/auto-update-daemon.js +10 -6
- package/dist/services/auto-update-daemon.js.map +1 -1
- package/dist/services/update-checker.d.ts.map +1 -1
- package/dist/services/update-checker.js +2 -1
- package/dist/services/update-checker.js.map +1 -1
- package/dist/services/update-installer.d.ts +8 -0
- package/dist/services/update-installer.d.ts.map +1 -1
- package/dist/services/update-installer.js +47 -18
- package/dist/services/update-installer.js.map +1 -1
- package/package.json +4 -4
- package/dist/commands/kms.d.ts +0 -3
- package/dist/commands/kms.d.ts.map +0 -1
- package/dist/commands/kms.js +0 -555
- package/dist/commands/kms.js.map +0 -1
- package/dist/commands/plugin.d.ts +0 -8
- package/dist/commands/plugin.d.ts.map +0 -1
- package/dist/commands/plugin.js +0 -637
- package/dist/commands/plugin.js.map +0 -1
- package/dist/commands/ssh.d.ts +0 -3
- package/dist/commands/ssh.d.ts.map +0 -1
- package/dist/commands/ssh.js +0 -814
- package/dist/commands/ssh.js.map +0 -1
- package/dist/commands/sso.d.ts +0 -3
- package/dist/commands/sso.d.ts.map +0 -1
- package/dist/commands/sso.js +0 -486
- package/dist/commands/sso.js.map +0 -1
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// Path: src/commands/ssh/connect.ts
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import * as output from '../../lib/output.js';
|
|
4
|
+
import { getCurrentProfile } from '../../lib/config.js';
|
|
5
|
+
import { getDefaultKeyPath, getCertificatePath, isCertificateValid, signCertificate, } from './helpers.js';
|
|
6
|
+
import { resolveBookmark } from './bookmark.js';
|
|
7
|
+
export function registerConnectCommand(parent) {
|
|
8
|
+
parent
|
|
9
|
+
.command('connect <destination> [command...]')
|
|
10
|
+
.description('SSH to a host using certificate authentication (auto-signs if needed)')
|
|
11
|
+
.option('-i, --identity <file>', 'Path to SSH private key (default: ~/.ssh/id_ed25519)')
|
|
12
|
+
.option('-p, --port <port>', 'SSH port', '22')
|
|
13
|
+
.option('--principals <principals>', 'Principals for signing (admin override, comma-separated)')
|
|
14
|
+
.option('--ttl <ttl>', 'Certificate TTL (e.g., 8h, 1d)')
|
|
15
|
+
.option('--tenant <id>', 'Tenant ID (superadmin only)')
|
|
16
|
+
.option('--force-sign', 'Force re-signing even if certificate is valid')
|
|
17
|
+
.option('--dry-run', 'Show what would be done without executing SSH')
|
|
18
|
+
.option('-v, --verbose', 'Show verbose output')
|
|
19
|
+
.option('-t', 'Force pseudo-terminal allocation (for interactive commands)')
|
|
20
|
+
.option('-T', 'Disable pseudo-terminal allocation')
|
|
21
|
+
.action(async (destination, remoteCommand, options) => {
|
|
22
|
+
const fs = await import('fs');
|
|
23
|
+
const path = await import('path');
|
|
24
|
+
const { spawn } = await import('child_process');
|
|
25
|
+
// Get profile config for defaults
|
|
26
|
+
const profile = getCurrentProfile();
|
|
27
|
+
// Resolve destination: could be a bookmark, user@host, or just host
|
|
28
|
+
let user;
|
|
29
|
+
let host;
|
|
30
|
+
let port = options.port ?? '22';
|
|
31
|
+
let identityOverride = options.identity;
|
|
32
|
+
let principalsOverride = options.principals;
|
|
33
|
+
// Check if destination is a bookmark
|
|
34
|
+
const bookmark = resolveBookmark(destination);
|
|
35
|
+
if (bookmark) {
|
|
36
|
+
host = bookmark.host;
|
|
37
|
+
user = bookmark.user;
|
|
38
|
+
if (bookmark.port) {
|
|
39
|
+
port = bookmark.port.toString();
|
|
40
|
+
}
|
|
41
|
+
if (bookmark.identity) {
|
|
42
|
+
identityOverride = bookmark.identity;
|
|
43
|
+
}
|
|
44
|
+
if (bookmark.principals && !options.principals) {
|
|
45
|
+
principalsOverride = bookmark.principals.join(',');
|
|
46
|
+
}
|
|
47
|
+
if (options.verbose) {
|
|
48
|
+
output.info(`Using bookmark '${destination}' → ${bookmark.host}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (destination.includes('@')) {
|
|
52
|
+
const parts = destination.split('@');
|
|
53
|
+
user = parts[0];
|
|
54
|
+
host = parts.slice(1).join('@'); // Handle IPv6 or multiple @
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
host = destination;
|
|
58
|
+
// Use default user from config if available
|
|
59
|
+
if (profile.sshUser) {
|
|
60
|
+
user = profile.sshUser;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Command line options override bookmark settings
|
|
64
|
+
if (options.port && options.port !== '22') {
|
|
65
|
+
port = options.port;
|
|
66
|
+
}
|
|
67
|
+
const verbose = (msg) => {
|
|
68
|
+
if (options.verbose) {
|
|
69
|
+
output.info(msg);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
try {
|
|
73
|
+
// Step 1: Find SSH key
|
|
74
|
+
let keyPath;
|
|
75
|
+
if (identityOverride) {
|
|
76
|
+
keyPath = path.resolve(identityOverride.replace(/^~/, process.env.HOME ?? ''));
|
|
77
|
+
if (!fs.existsSync(keyPath)) {
|
|
78
|
+
output.error(`SSH key not found: ${keyPath}`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
verbose(`Using specified key: ${keyPath}`);
|
|
82
|
+
}
|
|
83
|
+
else if (profile.sshIdentity && fs.existsSync(profile.sshIdentity)) {
|
|
84
|
+
// Use configured identity from profile
|
|
85
|
+
keyPath = profile.sshIdentity;
|
|
86
|
+
verbose(`Using configured key: ${keyPath}`);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const defaultKey = await getDefaultKeyPath();
|
|
90
|
+
if (!defaultKey) {
|
|
91
|
+
output.error('No SSH key found in ~/.ssh/');
|
|
92
|
+
output.info('Generate one with: ssh-keygen -t ed25519');
|
|
93
|
+
output.info('Or specify a key with: znvault ssh connect -i /path/to/key user@host');
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
keyPath = defaultKey;
|
|
97
|
+
verbose(`Using default key: ${keyPath}`);
|
|
98
|
+
}
|
|
99
|
+
const pubKeyPath = `${keyPath}.pub`;
|
|
100
|
+
if (!fs.existsSync(pubKeyPath)) {
|
|
101
|
+
output.error(`Public key not found: ${pubKeyPath}`);
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
// Step 2: Check certificate validity
|
|
105
|
+
const certPath = await getCertificatePath(keyPath);
|
|
106
|
+
verbose(`Certificate path: ${certPath}`);
|
|
107
|
+
const certStatus = await isCertificateValid(certPath);
|
|
108
|
+
const needsSign = options.forceSign || !certStatus.valid;
|
|
109
|
+
if (options.verbose && !certStatus.valid) {
|
|
110
|
+
output.warn(`Certificate needs signing: ${certStatus.reason}`);
|
|
111
|
+
}
|
|
112
|
+
else if (options.verbose && certStatus.valid) {
|
|
113
|
+
output.success('Certificate is valid');
|
|
114
|
+
}
|
|
115
|
+
// Step 3: Sign if needed
|
|
116
|
+
if (needsSign) {
|
|
117
|
+
const spinner = ora('Signing certificate...').start();
|
|
118
|
+
try {
|
|
119
|
+
await signCertificate(pubKeyPath, certPath, principalsOverride, options.ttl, options.tenant);
|
|
120
|
+
spinner.succeed('Certificate signed');
|
|
121
|
+
// Show certificate info
|
|
122
|
+
if (options.verbose) {
|
|
123
|
+
const { execSync } = await import('child_process');
|
|
124
|
+
try {
|
|
125
|
+
const certInfo = execSync(`ssh-keygen -L -f "${certPath}"`, { encoding: 'utf8' });
|
|
126
|
+
const principalsMatch = certInfo.match(/Principals:\s*([\s\S]*?)(?=\s+Critical Options:)/);
|
|
127
|
+
const validMatch = certInfo.match(/Valid:\s+from\s+(\S+)\s+to\s+(\S+)/);
|
|
128
|
+
if (principalsMatch) {
|
|
129
|
+
const principals = principalsMatch[1].trim().split('\n').map(p => p.trim()).filter(Boolean);
|
|
130
|
+
output.info(`Principals: ${principals.join(', ')}`);
|
|
131
|
+
}
|
|
132
|
+
if (validMatch) {
|
|
133
|
+
output.info(`Valid until: ${validMatch[2]}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// Ignore cert inspection errors
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
spinner.fail('Failed to sign certificate');
|
|
143
|
+
output.error(err instanceof Error ? err.message : String(err));
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (!options.verbose) {
|
|
148
|
+
// In non-verbose mode, just mention we're using existing cert
|
|
149
|
+
output.info('Using existing valid certificate');
|
|
150
|
+
}
|
|
151
|
+
// Step 4: Build SSH command
|
|
152
|
+
const sshArgs = [];
|
|
153
|
+
// Add identity file (this tells SSH to use our key + cert)
|
|
154
|
+
sshArgs.push('-i', keyPath);
|
|
155
|
+
// Add port if not default
|
|
156
|
+
if (port && port !== '22') {
|
|
157
|
+
sshArgs.push('-p', port);
|
|
158
|
+
}
|
|
159
|
+
// Add TTY allocation flags
|
|
160
|
+
if (options.t) {
|
|
161
|
+
sshArgs.push('-t');
|
|
162
|
+
}
|
|
163
|
+
else if (options.T) {
|
|
164
|
+
sshArgs.push('-T');
|
|
165
|
+
}
|
|
166
|
+
// Explicitly tell SSH to use the certificate
|
|
167
|
+
sshArgs.push('-o', `CertificateFile=${certPath}`);
|
|
168
|
+
// Add destination
|
|
169
|
+
if (user) {
|
|
170
|
+
sshArgs.push(`${user}@${host}`);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
sshArgs.push(host);
|
|
174
|
+
}
|
|
175
|
+
// Add remote command if specified
|
|
176
|
+
if (remoteCommand && remoteCommand.length > 0) {
|
|
177
|
+
sshArgs.push(...remoteCommand);
|
|
178
|
+
}
|
|
179
|
+
// Step 5: Execute SSH
|
|
180
|
+
if (options.dryRun) {
|
|
181
|
+
output.section('Dry Run');
|
|
182
|
+
output.keyValue({
|
|
183
|
+
'Key': keyPath,
|
|
184
|
+
'Certificate': certPath,
|
|
185
|
+
'Host': host,
|
|
186
|
+
'User': user ?? '(default)',
|
|
187
|
+
'Port': port,
|
|
188
|
+
'Principals': principalsOverride ?? '(from mapping)',
|
|
189
|
+
'Command': remoteCommand.length > 0 ? remoteCommand.join(' ') : '(interactive shell)',
|
|
190
|
+
});
|
|
191
|
+
console.log();
|
|
192
|
+
output.info(`Would execute: ssh ${sshArgs.join(' ')}`);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
verbose(`Executing: ssh ${sshArgs.join(' ')}`);
|
|
196
|
+
// Only print empty line for interactive sessions
|
|
197
|
+
if (remoteCommand.length === 0) {
|
|
198
|
+
console.log();
|
|
199
|
+
}
|
|
200
|
+
// Spawn SSH with stdio inherited (interactive session)
|
|
201
|
+
const sshProcess = spawn('ssh', sshArgs, {
|
|
202
|
+
stdio: 'inherit',
|
|
203
|
+
env: process.env,
|
|
204
|
+
});
|
|
205
|
+
sshProcess.on('close', (code) => {
|
|
206
|
+
process.exit(code ?? 0);
|
|
207
|
+
});
|
|
208
|
+
sshProcess.on('error', (err) => {
|
|
209
|
+
output.error(`Failed to start SSH: ${err.message}`);
|
|
210
|
+
process.exit(1);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
output.error(err instanceof Error ? err.message : String(err));
|
|
215
|
+
process.exit(1);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=connect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../../../src/commands/ssh/connect.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAOpC,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,UAAU,sBAAsB,CAAC,MAAe;IACpD,MAAM;SACH,OAAO,CAAC,oCAAoC,CAAC;SAC7C,WAAW,CAAC,uEAAuE,CAAC;SACpF,MAAM,CAAC,uBAAuB,EAAE,sDAAsD,CAAC;SACvF,MAAM,CAAC,mBAAmB,EAAE,UAAU,EAAE,IAAI,CAAC;SAC7C,MAAM,CAAC,2BAA2B,EAAE,0D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ec.d.ts","sourceRoot":"","sources":["../../../src/commands/ssh/exec.ts"],"names":[],"mappings":"AAEA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAiIzC,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAsJzD"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// Path: src/commands/ssh/exec.ts
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import * as output from '../../lib/output.js';
|
|
4
|
+
import { getCurrentProfile } from '../../lib/config.js';
|
|
5
|
+
import { getDefaultKeyPath, getCertificatePath, isCertificateValid, signCertificate, } from './helpers.js';
|
|
6
|
+
import { resolveBookmark } from './bookmark.js';
|
|
7
|
+
/**
|
|
8
|
+
* Resolve a destination to host connection info
|
|
9
|
+
*/
|
|
10
|
+
function resolveDestination(destination, profile) {
|
|
11
|
+
// Check if it's a bookmark
|
|
12
|
+
const bookmark = resolveBookmark(destination);
|
|
13
|
+
if (bookmark) {
|
|
14
|
+
return {
|
|
15
|
+
host: bookmark.host,
|
|
16
|
+
user: bookmark.user ?? profile.sshUser,
|
|
17
|
+
port: bookmark.port?.toString() ?? '22',
|
|
18
|
+
displayName: destination,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
// Parse user@host format
|
|
22
|
+
if (destination.includes('@')) {
|
|
23
|
+
const parts = destination.split('@');
|
|
24
|
+
const user = parts[0];
|
|
25
|
+
const host = parts.slice(1).join('@');
|
|
26
|
+
return { host, user, port: '22', displayName: destination };
|
|
27
|
+
}
|
|
28
|
+
// Just a host
|
|
29
|
+
return {
|
|
30
|
+
host: destination,
|
|
31
|
+
user: profile.sshUser,
|
|
32
|
+
port: '22',
|
|
33
|
+
displayName: destination,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Execute command on a single host
|
|
38
|
+
*/
|
|
39
|
+
async function executeOnHost(command, hostInfo, keyPath, certPath, options) {
|
|
40
|
+
const { execSync } = await import('child_process');
|
|
41
|
+
const sshArgs = [
|
|
42
|
+
'-i', keyPath,
|
|
43
|
+
'-o', 'CertificateFile=' + certPath,
|
|
44
|
+
'-o', 'BatchMode=yes',
|
|
45
|
+
'-o', 'StrictHostKeyChecking=accept-new',
|
|
46
|
+
'-o', 'ConnectTimeout=' + (options.timeout ?? '10'),
|
|
47
|
+
];
|
|
48
|
+
if (hostInfo.port !== '22') {
|
|
49
|
+
sshArgs.push('-p', hostInfo.port);
|
|
50
|
+
}
|
|
51
|
+
const destination = hostInfo.user
|
|
52
|
+
? hostInfo.user + '@' + hostInfo.host
|
|
53
|
+
: hostInfo.host;
|
|
54
|
+
sshArgs.push(destination, command);
|
|
55
|
+
try {
|
|
56
|
+
const stdout = execSync('ssh ' + sshArgs.map(a => a.includes(' ') ? '"' + a + '"' : a).join(' '), {
|
|
57
|
+
encoding: 'utf8',
|
|
58
|
+
timeout: parseInt(options.timeout ?? '30') * 1000,
|
|
59
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
host: hostInfo.host,
|
|
63
|
+
displayName: hostInfo.displayName,
|
|
64
|
+
success: true,
|
|
65
|
+
exitCode: 0,
|
|
66
|
+
stdout: stdout.trim(),
|
|
67
|
+
stderr: '',
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
const error = err;
|
|
72
|
+
return {
|
|
73
|
+
host: hostInfo.host,
|
|
74
|
+
displayName: hostInfo.displayName,
|
|
75
|
+
success: false,
|
|
76
|
+
exitCode: error.status ?? 1,
|
|
77
|
+
stdout: (error.stdout ?? '').toString().trim(),
|
|
78
|
+
stderr: (error.stderr ?? '').toString().trim(),
|
|
79
|
+
error: error.message,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function registerExecCommand(parent) {
|
|
84
|
+
parent
|
|
85
|
+
.command('exec <command> <hosts...>')
|
|
86
|
+
.description('Execute command on multiple hosts')
|
|
87
|
+
.option('-i, --identity <file>', 'Path to SSH private key')
|
|
88
|
+
.option('-p, --port <port>', 'SSH port (can be overridden per-host via bookmarks)')
|
|
89
|
+
.option('--principals <principals>', 'Principals for signing (admin override)')
|
|
90
|
+
.option('--ttl <ttl>', 'Certificate TTL (e.g., 8h, 1d)')
|
|
91
|
+
.option('--tenant <id>', 'Tenant ID (superadmin only)')
|
|
92
|
+
.option('--force-sign', 'Force re-signing certificate')
|
|
93
|
+
.option('--parallel', 'Run on all hosts in parallel (default: sequential)')
|
|
94
|
+
.option('--fail-fast', 'Stop on first failure (sequential mode only)')
|
|
95
|
+
.option('--timeout <seconds>', 'Connection timeout per host', '30')
|
|
96
|
+
.option('-q, --quiet', 'Only show output, no status messages')
|
|
97
|
+
.action(async (command, hosts, options) => {
|
|
98
|
+
const fs = await import('fs');
|
|
99
|
+
const pathModule = await import('path');
|
|
100
|
+
const profile = getCurrentProfile();
|
|
101
|
+
// Resolve all hosts first
|
|
102
|
+
const resolvedHosts = hosts.map(h => resolveDestination(h, profile));
|
|
103
|
+
if (!options.quiet) {
|
|
104
|
+
output.section('Multi-Host Execution');
|
|
105
|
+
output.info('Command: ' + command);
|
|
106
|
+
output.info('Hosts: ' + resolvedHosts.map(h => h.displayName).join(', '));
|
|
107
|
+
output.info('Mode: ' + (options.parallel ? 'parallel' : 'sequential'));
|
|
108
|
+
console.log();
|
|
109
|
+
}
|
|
110
|
+
// Find SSH key
|
|
111
|
+
let keyPath;
|
|
112
|
+
if (options.identity) {
|
|
113
|
+
keyPath = pathModule.resolve(options.identity.replace(/^~/, process.env.HOME ?? ''));
|
|
114
|
+
if (!fs.existsSync(keyPath)) {
|
|
115
|
+
output.error('SSH key not found: ' + keyPath);
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (profile.sshIdentity && fs.existsSync(profile.sshIdentity)) {
|
|
120
|
+
keyPath = profile.sshIdentity;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const defaultKey = await getDefaultKeyPath();
|
|
124
|
+
if (!defaultKey) {
|
|
125
|
+
output.error('No SSH key found');
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
keyPath = defaultKey;
|
|
129
|
+
}
|
|
130
|
+
const pubKeyPath = keyPath + '.pub';
|
|
131
|
+
if (!fs.existsSync(pubKeyPath)) {
|
|
132
|
+
output.error('Public key not found: ' + pubKeyPath);
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
// Check/sign certificate
|
|
136
|
+
const certPath = await getCertificatePath(keyPath);
|
|
137
|
+
const certStatus = await isCertificateValid(certPath);
|
|
138
|
+
if (options.forceSign || !certStatus.valid) {
|
|
139
|
+
const spinner = ora('Signing certificate...').start();
|
|
140
|
+
try {
|
|
141
|
+
await signCertificate(pubKeyPath, certPath, options.principals, options.ttl, options.tenant);
|
|
142
|
+
spinner.succeed('Certificate signed');
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
spinner.fail('Failed to sign certificate');
|
|
146
|
+
output.error(err instanceof Error ? err.message : String(err));
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Execute on hosts
|
|
151
|
+
const results = [];
|
|
152
|
+
let hasFailure = false;
|
|
153
|
+
if (options.parallel) {
|
|
154
|
+
// Parallel execution
|
|
155
|
+
const spinner = ora('Executing on ' + resolvedHosts.length + ' hosts...').start();
|
|
156
|
+
const promises = resolvedHosts.map(hostInfo => executeOnHost(command, hostInfo, keyPath, certPath, options));
|
|
157
|
+
const parallelResults = await Promise.all(promises);
|
|
158
|
+
results.push(...parallelResults);
|
|
159
|
+
const successCount = results.filter(r => r.success).length;
|
|
160
|
+
spinner.stop();
|
|
161
|
+
if (!options.quiet) {
|
|
162
|
+
output.info('Completed: ' + successCount + '/' + results.length + ' succeeded');
|
|
163
|
+
console.log();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
// Sequential execution
|
|
168
|
+
for (const hostInfo of resolvedHosts) {
|
|
169
|
+
if (!options.quiet) {
|
|
170
|
+
process.stdout.write('● ' + hostInfo.displayName + '... ');
|
|
171
|
+
}
|
|
172
|
+
const result = await executeOnHost(command, hostInfo, keyPath, certPath, options);
|
|
173
|
+
results.push(result);
|
|
174
|
+
if (!options.quiet) {
|
|
175
|
+
if (result.success) {
|
|
176
|
+
console.log('\x1b[32m✓\x1b[0m');
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
console.log('\x1b[31m✗\x1b[0m (exit ' + result.exitCode + ')');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (!result.success) {
|
|
183
|
+
hasFailure = true;
|
|
184
|
+
if (options.failFast) {
|
|
185
|
+
output.warn('Stopping due to --fail-fast');
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
console.log();
|
|
191
|
+
}
|
|
192
|
+
// Display results
|
|
193
|
+
for (const result of results) {
|
|
194
|
+
output.section(result.displayName + (result.success ? '' : ' (FAILED)'));
|
|
195
|
+
if (result.stdout) {
|
|
196
|
+
console.log(result.stdout);
|
|
197
|
+
}
|
|
198
|
+
if (result.stderr) {
|
|
199
|
+
console.log('\x1b[33m' + result.stderr + '\x1b[0m');
|
|
200
|
+
}
|
|
201
|
+
if (!result.stdout && !result.stderr && result.error) {
|
|
202
|
+
output.error(result.error);
|
|
203
|
+
}
|
|
204
|
+
console.log();
|
|
205
|
+
}
|
|
206
|
+
// Summary
|
|
207
|
+
const successCount = results.filter(r => r.success).length;
|
|
208
|
+
const failCount = results.filter(r => !r.success).length;
|
|
209
|
+
if (failCount > 0) {
|
|
210
|
+
output.warn('Summary: ' + successCount + ' succeeded, ' + failCount + ' failed');
|
|
211
|
+
process.exit(1);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
output.success('All ' + successCount + ' hosts completed successfully');
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=exec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../../src/commands/ssh/exec.ts"],"names":[],"mappings":"AAAA,iCAAiC;AAOjC,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAyBhD;;GAEG;AACH,SAAS,kBAAkB,CACzB,WAAmB,EACnB,OAA6B;IAE7B,2BAA2B;IAC3B,MAAM,QAAQ,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;IAC9C,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO;YACL,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,IAAI,EAAE,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,OAAO;YACtC,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,IAAI;YACvC,WAAW,EAAE,WAAW;SACzB,CAAC;IACJ,CAAC;IAED,yBAAyB;IACzB,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACtC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAA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
|
+
import { formatTtl, parseTtl } from '../../lib/format-helpers.js';
|
|
2
|
+
export { formatTtl, parseTtl };
|
|
3
|
+
/**
|
|
4
|
+
* Get path to the default SSH key
|
|
5
|
+
*/
|
|
6
|
+
export declare function getDefaultKeyPath(): Promise<string | null>;
|
|
7
|
+
/**
|
|
8
|
+
* Get the certificate path for a given key path
|
|
9
|
+
*/
|
|
10
|
+
export declare function getCertificatePath(keyPath: string): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Check if a certificate is valid (exists and not expired)
|
|
13
|
+
*/
|
|
14
|
+
export declare function isCertificateValid(certPath: string): Promise<{
|
|
15
|
+
valid: boolean;
|
|
16
|
+
reason?: string;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Sign a certificate using the vault API
|
|
20
|
+
*/
|
|
21
|
+
export declare function signCertificate(publicKeyPath: string, certPath: string, principals?: string, ttl?: string, tenant?: string): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a certificate is expired
|
|
24
|
+
*/
|
|
25
|
+
export declare function isExpired(validBefore: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Build tenant query string parameter
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildTenantQuery(tenant?: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Parse local certificate details using ssh-keygen
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseCertificateInfo(certPath: string): Promise<{
|
|
34
|
+
valid: boolean;
|
|
35
|
+
principals: string[];
|
|
36
|
+
validAfter: Date | null;
|
|
37
|
+
validBefore: Date | null;
|
|
38
|
+
fingerprint: string | null;
|
|
39
|
+
keyId: string | null;
|
|
40
|
+
serial: string | null;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Format remaining time as human-readable string
|
|
44
|
+
*/
|
|
45
|
+
export declare function formatRemainingTime(validBefore: Date): string;
|
|
46
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1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