@p0security/cli 0.11.4 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/__tests__/login.test.js +31 -12
- package/dist/commands/__tests__/login.test.js.map +1 -1
- package/dist/commands/__tests__/ssh.test.js +23 -15
- package/dist/commands/__tests__/ssh.test.js.map +1 -1
- package/dist/commands/login.js +6 -6
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/ls.js +26 -7
- package/dist/commands/ls.js.map +1 -1
- package/dist/commands/scp.js +5 -0
- package/dist/commands/scp.js.map +1 -1
- package/dist/commands/shared/request.d.ts +1 -0
- package/dist/commands/shared/request.js +9 -1
- package/dist/commands/shared/request.js.map +1 -1
- package/dist/commands/shared/ssh.d.ts +11 -1
- package/dist/commands/shared/ssh.js +16 -11
- package/dist/commands/shared/ssh.js.map +1 -1
- package/dist/commands/ssh.js +8 -3
- package/dist/commands/ssh.js.map +1 -1
- package/dist/common/install.d.ts +3 -0
- package/dist/common/install.js +12 -1
- package/dist/common/install.js.map +1 -1
- package/dist/drivers/auth.d.ts +1 -4
- package/dist/drivers/auth.js +4 -8
- package/dist/drivers/auth.js.map +1 -1
- package/dist/drivers/config.d.ts +2 -2
- package/dist/drivers/config.js +11 -1
- package/dist/drivers/config.js.map +1 -1
- package/dist/drivers/firestore.d.ts +4 -3
- package/dist/drivers/firestore.js +11 -6
- package/dist/drivers/firestore.js.map +1 -1
- package/dist/plugins/aws/ssh.js +5 -4
- package/dist/plugins/aws/ssh.js.map +1 -1
- package/dist/plugins/aws/types.d.ts +15 -15
- package/dist/plugins/azure/auth.d.ts +11 -0
- package/dist/plugins/azure/auth.js +56 -0
- package/dist/plugins/azure/auth.js.map +1 -0
- package/dist/plugins/azure/install.d.ts +1 -0
- package/dist/plugins/azure/install.js +33 -0
- package/dist/plugins/azure/install.js.map +1 -0
- package/dist/plugins/azure/keygen.d.ts +13 -0
- package/dist/plugins/azure/keygen.js +69 -0
- package/dist/plugins/azure/keygen.js.map +1 -0
- package/dist/plugins/azure/ssh.d.ts +13 -0
- package/dist/plugins/azure/ssh.js +124 -0
- package/dist/plugins/azure/ssh.js.map +1 -0
- package/dist/plugins/azure/tunnel.d.ts +14 -0
- package/dist/plugins/azure/tunnel.js +160 -0
- package/dist/plugins/azure/tunnel.js.map +1 -0
- package/dist/plugins/azure/types.d.ts +47 -0
- package/dist/plugins/azure/types.js +3 -0
- package/dist/plugins/azure/types.js.map +1 -0
- package/dist/plugins/google/ssh.js +5 -4
- package/dist/plugins/google/ssh.js.map +1 -1
- package/dist/plugins/google/types.d.ts +5 -6
- package/dist/plugins/ssh/index.js +44 -24
- package/dist/plugins/ssh/index.js.map +1 -1
- package/dist/types/request.d.ts +3 -1
- package/dist/types/ssh.d.ts +14 -6
- package/dist/types/ssh.js +1 -1
- package/dist/types/ssh.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssh.js","sourceRoot":"","sources":["../../../src/plugins/azure/ssh.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAWA,iCAAsE;AACtE,uCAA4C;AAC5C,qCAMkB;AAClB,qCAAyE;AAMzE,0DAA6B;AAE7B,sDAAsD;AACtD,MAAM,4BAA4B,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAEtC,QAAA,gBAAgB,GAIzB;IACF,+CAA+C;IAC/C,kBAAkB,EAAE,GAAS,EAAE;QAC7B,4CAA4C;QAC5C,OAAO,SAAS,CAAC;IACnB,CAAC,CAAA;IAED,aAAa,EAAE,GAAS,EAAE;QACxB,IAAI,CAAC,CAAC,MAAM,IAAA,yBAAe,GAAE,CAAC,EAAE;YAC9B,MAAM,uDAAuD,CAAC;SAC/D;IACH,CAAC,CAAA;IAED,YAAY,EAAE,iBAAiB;IAE/B,oBAAoB,EAAE,qDAAqD;IAE3E,wBAAwB;IACxB,oBAAoB,EAAE,SAAS;IAE/B,oBAAoB,EAAE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AAE,yBAAgB,CAAC,CAAC;QAEnE,MAAM,QAAQ,GAAG,GAAS,EAAE;YAC1B,MAAM,UAAU,EAAE,CAAC;YACnB,MAAM,iBAAiB,EAAE,CAAC;QAC5B,CAAC,CAAA,CAAC;QAEF,OAAO;YACL,UAAU,EAAE;gBACV,mBAAmB,qBAAqB,EAAE;gBAE1C,2GAA2G;gBAC3G,4GAA4G;gBAC5G,gHAAgH;gBAChH,6GAA6G;gBAC7G,+GAA+G;gBAC/G,2BAA2B;gBAC3B,0BAA0B;gBAC1B,8BAA8B;aAC/B;YACD,YAAY,EAAE,iBAAiB;YAC/B,IAAI,EAAE,eAAe;YACrB,QAAQ;SACT,CAAC;IACJ,CAAC,CAAA;IAED,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,+BACzB,IAAI,EAAE,OAAO,EACb,EAAE,EAAE,WAAW,IACZ,OAAO,CAAC,YAAY,KACvB,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,EAClD,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,cAAc,EAC1D,qBAAqB,EAAE,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,eAAe,EAClE,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,aAAa,IAC3C;IAEF,kBAAkB;IAClB,2BAA2B,EAAE,EAAE;IAE/B,YAAY,EAAE,CAAO,OAAO,EAAE,EAAE;QAC9B,uCACK,OAAO,KACV,YAAY,EAAE;gBACZ,aAAa,EAAE,OAAO,CAAC,SAAS;aACjC,IACD;IACJ,CAAC,CAAA;CACF,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AzureSshRequest } from "./types";
|
|
2
|
+
export type BastionTunnelMeta = {
|
|
3
|
+
killTunnel: () => Promise<void>;
|
|
4
|
+
tunnelLocalPort: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const azBastionTunnelCommand: (request: AzureSshRequest, port: string, options?: {
|
|
7
|
+
debug?: boolean;
|
|
8
|
+
}) => {
|
|
9
|
+
command: string;
|
|
10
|
+
args: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare const trySpawnBastionTunnel: (request: AzureSshRequest, options?: {
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
}) => Promise<BastionTunnelMeta>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.trySpawnBastionTunnel = exports.azBastionTunnelCommand = void 0;
|
|
13
|
+
/** Copyright © 2024-present P0 Security
|
|
14
|
+
|
|
15
|
+
This file is part of @p0security/cli
|
|
16
|
+
|
|
17
|
+
@p0security/cli is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.
|
|
18
|
+
|
|
19
|
+
@p0security/cli is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
20
|
+
|
|
21
|
+
You should have received a copy of the GNU General Public License along with @p0security/cli. If not, see <https://www.gnu.org/licenses/>.
|
|
22
|
+
**/
|
|
23
|
+
const retry_1 = require("../../common/retry");
|
|
24
|
+
const stdio_1 = require("../../drivers/stdio");
|
|
25
|
+
const util_1 = require("../../util");
|
|
26
|
+
const node_child_process_1 = require("node:child_process");
|
|
27
|
+
const TUNNEL_READY_STRING = "Tunnel is ready";
|
|
28
|
+
const SPAWN_TUNNEL_TRIES = 3;
|
|
29
|
+
// Ignore these debug messages from the tunnel process; they are far too noisy and spam the terminal with useless info
|
|
30
|
+
// anytime the SSH/SCP session has network activity.
|
|
31
|
+
const tunnelDebugOutputIgnorePatterns = [
|
|
32
|
+
/Waiting for (debugger|websocket) data/i,
|
|
33
|
+
/Received (debugger|websocket)/i,
|
|
34
|
+
/Sending to (debugger|websocket)/i,
|
|
35
|
+
];
|
|
36
|
+
const azBastionTunnelCommand = (request, port, options = {}) => ({
|
|
37
|
+
command: "az",
|
|
38
|
+
args: [
|
|
39
|
+
"network",
|
|
40
|
+
"bastion",
|
|
41
|
+
"tunnel",
|
|
42
|
+
"--ids",
|
|
43
|
+
request.bastionId,
|
|
44
|
+
"--target-resource-id",
|
|
45
|
+
request.instanceId,
|
|
46
|
+
"--resource-port",
|
|
47
|
+
"22",
|
|
48
|
+
"--port",
|
|
49
|
+
port,
|
|
50
|
+
...(options.debug ? ["--debug"] : []),
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
exports.azBastionTunnelCommand = azBastionTunnelCommand;
|
|
54
|
+
const selectRandomPort = () => {
|
|
55
|
+
// The IANA ephemeral port range is 49152 to 65535, inclusive. Pick a random value in that range.
|
|
56
|
+
// If the port is in use (unlikely but possible), we can just generate a new value and try again.
|
|
57
|
+
// 16384 is 65535 - 49152 + 1, the number of possible ports in the range.
|
|
58
|
+
const port = Math.floor(Math.random() * 16384) + 49152;
|
|
59
|
+
return port.toString();
|
|
60
|
+
};
|
|
61
|
+
const spawnBastionTunnelInBackground = (request, port, options = {}) => {
|
|
62
|
+
const { debug } = options;
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
let processSignalledToExit = false;
|
|
65
|
+
let processExited = false;
|
|
66
|
+
let stdout = "";
|
|
67
|
+
let stderr = "";
|
|
68
|
+
const { command, args } = (0, exports.azBastionTunnelCommand)(request, port, { debug });
|
|
69
|
+
if (debug)
|
|
70
|
+
(0, stdio_1.print2)("Spawning Azure Bastion tunnel process...");
|
|
71
|
+
// Spawn the process in detached mode so that it is in its own process group; this lets us kill it and all
|
|
72
|
+
// descendent processes together.
|
|
73
|
+
const child = (0, node_child_process_1.spawn)(command, args, { detached: true });
|
|
74
|
+
child.on("exit", (code) => {
|
|
75
|
+
processExited = true;
|
|
76
|
+
if (code === 0) {
|
|
77
|
+
if (debug)
|
|
78
|
+
(0, stdio_1.print2)("Azure Bastion tunnel process exited normally.");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (!debug) {
|
|
82
|
+
// stdout and stderr are printed in real-time when debugging is enabled, so we don't need to print them here
|
|
83
|
+
(0, stdio_1.print2)(stdout);
|
|
84
|
+
(0, stdio_1.print2)(stderr);
|
|
85
|
+
}
|
|
86
|
+
reject(`Error running Azure Network Bastion tunnel; tunnel process ended with status ${code}`);
|
|
87
|
+
});
|
|
88
|
+
child.stdout.on("data", (data) => {
|
|
89
|
+
const str = data.toString("utf-8");
|
|
90
|
+
stdout += str;
|
|
91
|
+
if (debug &&
|
|
92
|
+
!tunnelDebugOutputIgnorePatterns.some((regex) => str.match(regex))) {
|
|
93
|
+
(0, stdio_1.print2)(str);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
child.stderr.on("data", (data) => {
|
|
97
|
+
const str = data.toString("utf-8");
|
|
98
|
+
stderr += str;
|
|
99
|
+
if (debug &&
|
|
100
|
+
!tunnelDebugOutputIgnorePatterns.some((regex) => str.match(regex))) {
|
|
101
|
+
(0, stdio_1.print2)(str);
|
|
102
|
+
}
|
|
103
|
+
if (str.includes(TUNNEL_READY_STRING)) {
|
|
104
|
+
(0, stdio_1.print2)("Azure Bastion tunnel is ready.");
|
|
105
|
+
resolve({
|
|
106
|
+
killTunnel: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
|
+
if (processSignalledToExit || processExited)
|
|
108
|
+
return;
|
|
109
|
+
processSignalledToExit = true;
|
|
110
|
+
if (child.pid) {
|
|
111
|
+
// Kill the process and all its descendents via killing the process group; this is only possible
|
|
112
|
+
// because we launched the process with `detached: true` above. This is necessary because `az` is
|
|
113
|
+
// actually a bash script that spawns a Python process, and we need to kill the Python process as well.
|
|
114
|
+
// SIGINT is equivalent to pressing Ctrl-C in the terminal; allows for the tunnel process to perform any
|
|
115
|
+
// necessary cleanup of its own before exiting. The negative PID is what indicates that we want to kill
|
|
116
|
+
// the whole process group.
|
|
117
|
+
try {
|
|
118
|
+
if (debug) {
|
|
119
|
+
(0, stdio_1.print2)(`Sending SIGINT to Azure Bastion tunnel process (${child.pid})...`);
|
|
120
|
+
}
|
|
121
|
+
process.kill(-child.pid, "SIGINT");
|
|
122
|
+
// Give the tunnel a chance to quit gracefully after the SIGINT by waiting at least 250 ms and up to
|
|
123
|
+
// 5 seconds. If the process is still running after that, it's probably hung; SIGKILL it to force it to
|
|
124
|
+
// end immediately.
|
|
125
|
+
const SPIN_WAIT_MS = 250;
|
|
126
|
+
for (let spins = 0; spins < 20; spins++) {
|
|
127
|
+
yield (0, util_1.sleep)(SPIN_WAIT_MS);
|
|
128
|
+
if (processExited) {
|
|
129
|
+
if (debug) {
|
|
130
|
+
(0, stdio_1.print2)(`Azure Bastion tunnel process exited after SIGINT after ${spins * SPIN_WAIT_MS} ms.`);
|
|
131
|
+
}
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (debug) {
|
|
136
|
+
(0, stdio_1.print2)(`Azure Bastion tunnel process (${child.pid}) not responding, sending SIGKILL...`);
|
|
137
|
+
}
|
|
138
|
+
process.kill(-child.pid, "SIGKILL");
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
// Ignore the error and move on; we might as well just exit without waiting since we can't control
|
|
142
|
+
// the child process, for whatever reason
|
|
143
|
+
(0, stdio_1.print2)(`Failed to kill Azure Bastion tunnel process: ${error}`);
|
|
144
|
+
child.unref();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}),
|
|
148
|
+
tunnelLocalPort: port,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
const trySpawnBastionTunnel = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
155
|
+
// Attempt to spawn the tunnel SPAWN_TUNNEL_TRIES times, picking a new port each time. If we fail
|
|
156
|
+
// too many times, then the problem is likely not the port, but something else.
|
|
157
|
+
return yield (0, retry_1.retryWithSleep)(() => spawnBastionTunnelInBackground(request, selectRandomPort(), options), () => true, SPAWN_TUNNEL_TRIES, 1000);
|
|
158
|
+
});
|
|
159
|
+
exports.trySpawnBastionTunnel = trySpawnBastionTunnel;
|
|
160
|
+
//# sourceMappingURL=tunnel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tunnel.js","sourceRoot":"","sources":["../../../src/plugins/azure/tunnel.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;GASG;AACH,8CAAoD;AACpD,+CAA6C;AAC7C,qCAAmC;AAEnC,2DAA2C;AAE3C,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAC9C,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAE7B,sHAAsH;AACtH,oDAAoD;AACpD,MAAM,+BAA+B,GAAa;IAChD,wCAAwC;IACxC,gCAAgC;IAChC,kCAAkC;CACnC,CAAC;AAOK,MAAM,sBAAsB,GAAG,CACpC,OAAwB,EACxB,IAAY,EACZ,UAA+B,EAAE,EACjC,EAAE,CAAC,CAAC;IACJ,OAAO,EAAE,IAAI;IACb,IAAI,EAAE;QACJ,SAAS;QACT,SAAS;QACT,QAAQ;QACR,OAAO;QACP,OAAO,CAAC,SAAS;QACjB,sBAAsB;QACtB,OAAO,CAAC,UAAU;QAClB,iBAAiB;QACjB,IAAI;QAC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AAG,CACnC,OAAwB,EACxB,OAA6B,EACD,EAAE;IAC9B,iGAAiG;IACjG,+EAA+E;IAE/E,OAAO,MAAM,IAAA,sBAAc,EACzB,GAAG,EAAE,CAAC,8BAA8B,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,OAAO,CAAC,EAC1E,GAAG,EAAE,CAAC,IAAI,EACV,kBAAkB,EAClB,IAAI,CACL,CAAC;AACJ,CAAC,CAAA,CAAC;AAbW,QAAA,qBAAqB,yBAahC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Copyright © 2024-present P0 Security
|
|
2
|
+
|
|
3
|
+
This file is part of @p0security/cli
|
|
4
|
+
|
|
5
|
+
@p0security/cli is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.
|
|
6
|
+
|
|
7
|
+
@p0security/cli is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
8
|
+
|
|
9
|
+
You should have received a copy of the GNU General Public License along with @p0security/cli. If not, see <https://www.gnu.org/licenses/>.
|
|
10
|
+
**/
|
|
11
|
+
import { PermissionSpec } from "../../types/request";
|
|
12
|
+
import { CliPermissionSpec } from "../../types/ssh";
|
|
13
|
+
import { CommonSshPermissionSpec } from "../ssh/types";
|
|
14
|
+
export type AzureSshPermissionSpec = PermissionSpec<"ssh", AzureSshPermission>;
|
|
15
|
+
export type AzureSsh = CliPermissionSpec<AzureSshPermissionSpec, AzureLocalData>;
|
|
16
|
+
export type AzureSshPermission = CommonSshPermissionSpec & {
|
|
17
|
+
provider: "azure";
|
|
18
|
+
destination: string;
|
|
19
|
+
parent: string | undefined;
|
|
20
|
+
group: string | undefined;
|
|
21
|
+
bastionHostId: string;
|
|
22
|
+
principal: string;
|
|
23
|
+
resource: {
|
|
24
|
+
instanceId: string;
|
|
25
|
+
instanceName: string;
|
|
26
|
+
subscriptionName: string;
|
|
27
|
+
resourceGroupId: string;
|
|
28
|
+
subscriptionId: string;
|
|
29
|
+
region: string;
|
|
30
|
+
networkInterfaceIds: string[];
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type AzureNodeSpec = {
|
|
34
|
+
instanceId: string;
|
|
35
|
+
sudo?: boolean;
|
|
36
|
+
};
|
|
37
|
+
export type AzureBastionSpec = {
|
|
38
|
+
bastionId: string;
|
|
39
|
+
};
|
|
40
|
+
export type AzureSshRequest = AzureNodeSpec & AzureBastionSpec & AzureLocalData & {
|
|
41
|
+
type: "azure";
|
|
42
|
+
id: "localhost";
|
|
43
|
+
subscriptionId: string;
|
|
44
|
+
};
|
|
45
|
+
export type AzureLocalData = {
|
|
46
|
+
linuxUserName: string;
|
|
47
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plugins/azure/types.ts"],"names":[],"mappings":""}
|
|
@@ -65,6 +65,7 @@ exports.gcpSshProvider = {
|
|
|
65
65
|
throw "Please try again after installing the required GCP utilities";
|
|
66
66
|
}
|
|
67
67
|
}),
|
|
68
|
+
validateSshKey: (request, publicKey) => request.permission.publicKey === publicKey,
|
|
68
69
|
friendlyName: "Google Cloud",
|
|
69
70
|
loginRequiredMessage: "Please login to Google Cloud CLI with 'gcloud auth login'",
|
|
70
71
|
loginRequiredPattern: /You do not currently have an active account selected/,
|
|
@@ -97,9 +98,9 @@ exports.gcpSshProvider = {
|
|
|
97
98
|
reproCommands: () => undefined,
|
|
98
99
|
requestToSsh: (request) => {
|
|
99
100
|
return {
|
|
100
|
-
id: request.permission.
|
|
101
|
-
projectId: request.permission.
|
|
102
|
-
zone: request.permission.
|
|
101
|
+
id: request.permission.resource.instanceName,
|
|
102
|
+
projectId: request.permission.resource.projectId,
|
|
103
|
+
zone: request.permission.zone,
|
|
103
104
|
linuxUserName: request.cliLocalData.linuxUserName,
|
|
104
105
|
type: "gcloud",
|
|
105
106
|
};
|
|
@@ -107,7 +108,7 @@ exports.gcpSshProvider = {
|
|
|
107
108
|
unprovisionedAccessPatterns,
|
|
108
109
|
toCliRequest: (request, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
110
|
return (Object.assign(Object.assign({}, request), { cliLocalData: {
|
|
110
|
-
linuxUserName: yield (0, ssh_key_1.importSshKey)(request.permission.
|
|
111
|
+
linuxUserName: yield (0, ssh_key_1.importSshKey)(request.permission.publicKey, options),
|
|
111
112
|
} }));
|
|
112
113
|
}),
|
|
113
114
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssh.js","sourceRoot":"","sources":["../../../src/plugins/google/ssh.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;GASG;AACH,mDAA0D;AAE1D,uCAAgD;AAChD,uCAAyC;AAGzC,oGAAoG;AACpG,MAAM,4BAA4B,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,2BAA2B,GAAG;IAClC,EAAE,OAAO,EAAE,iCAAiC,EAAE;IAC9C;QACE,mEAAmE;QACnE,OAAO,EAAE,uCAAuC;KACjD;IACD,EAAE,OAAO,EAAE,mDAAmD,EAAE;IAChE;QACE,OAAO,EAAE,+CAA+C;QACxD,kBAAkB,EAAE,IAAI;KACzB;IACD,EAAE,OAAO,EAAE,4DAA4D,EAAE;CACjE,CAAC;AAEE,QAAA,cAAc,GAIvB;IACF,uCAAuC;IACvC,kBAAkB,EAAE,GAAS,EAAE,kDAAC,OAAA,SAAS,CAAA,GAAA;IAEzC,aAAa,EAAE,GAAS,EAAE;QACxB,IAAI,CAAC,CAAC,MAAM,IAAA,6BAAmB,GAAE,CAAC,EAAE;YAClC,MAAM,8DAA8D,CAAC;SACtE;IACH,CAAC,CAAA;IAED,YAAY,EAAE,cAAc;IAE5B,oBAAoB,EAClB,2DAA2D;IAE7D,oBAAoB,EAAE,sDAAsD;I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CAAC,SAAS;YAChD,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI;YAC7B,aAAa,EAAE,OAAO,CAAC,YAAY,CAAC,aAAa;YACjD,IAAI,EAAE,QAAQ;SACf,CAAC;IACJ,CAAC;IAED,2BAA2B;IAE3B,YAAY,EAAE,CAAO,OAAO,EAAE,OAAO,EAAE,EAAE;QAAC,OAAA,iCACrC,OAAO,KACV,YAAY,EAAE;gBACZ,aAAa,EAAE,MAAM,IAAA,sBAAY,EAAC,OAAO,CAAC,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC;aACzE,IACD,CAAA;MAAA;CACH,CAAC"}
|
|
@@ -11,25 +11,24 @@ You should have received a copy of the GNU General Public License along with @p0
|
|
|
11
11
|
import { PermissionSpec } from "../../types/request";
|
|
12
12
|
import { CliPermissionSpec } from "../../types/ssh";
|
|
13
13
|
import { CommonSshPermissionSpec } from "../ssh/types";
|
|
14
|
-
export type GcpSshPermission = {
|
|
15
|
-
|
|
14
|
+
export type GcpSshPermission = CommonSshPermissionSpec & {
|
|
15
|
+
provider: "gcloud";
|
|
16
|
+
zone: string;
|
|
17
|
+
resource: {
|
|
16
18
|
instanceName: string;
|
|
17
19
|
projectId: string;
|
|
18
|
-
zone: string;
|
|
19
|
-
type: "gcloud";
|
|
20
20
|
};
|
|
21
|
-
type: "session";
|
|
22
21
|
};
|
|
23
22
|
export type GcpSshPermissionSpec = PermissionSpec<"ssh", GcpSshPermission>;
|
|
24
23
|
export type GcpSsh = CliPermissionSpec<GcpSshPermissionSpec, {
|
|
25
24
|
linuxUserName: string;
|
|
26
25
|
}>;
|
|
27
26
|
export type GcpSshRequest = {
|
|
27
|
+
type: "gcloud";
|
|
28
28
|
linuxUserName: string;
|
|
29
29
|
projectId: string;
|
|
30
30
|
zone: string;
|
|
31
31
|
id: string;
|
|
32
|
-
type: "gcloud";
|
|
33
32
|
};
|
|
34
33
|
type PosixAccount = {
|
|
35
34
|
username: string;
|
|
@@ -143,14 +143,20 @@ function spawnSshNode(options) {
|
|
|
143
143
|
});
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
|
-
const createCommand = (data, args, proxyCommand) => {
|
|
147
|
-
|
|
146
|
+
const createCommand = (data, args, setupData, proxyCommand) => {
|
|
147
|
+
var _a;
|
|
148
|
+
addCommonArgs(args, proxyCommand, setupData);
|
|
149
|
+
const sshOptionsOverrides = (_a = setupData === null || setupData === void 0 ? void 0 : setupData.sshOptions) !== null && _a !== void 0 ? _a : [];
|
|
150
|
+
const port = setupData === null || setupData === void 0 ? void 0 : setupData.port;
|
|
151
|
+
const argsOverride = sshOptionsOverrides.flatMap((opt) => ["-o", opt]);
|
|
148
152
|
if ("source" in args) {
|
|
149
153
|
addScpArgs(args);
|
|
150
154
|
return {
|
|
151
155
|
command: "scp",
|
|
152
156
|
args: [
|
|
153
157
|
...(args.sshOptions ? args.sshOptions : []),
|
|
158
|
+
...argsOverride,
|
|
159
|
+
...(port ? ["-P", port] : []),
|
|
154
160
|
args.source,
|
|
155
161
|
args.destination,
|
|
156
162
|
],
|
|
@@ -160,6 +166,8 @@ const createCommand = (data, args, proxyCommand) => {
|
|
|
160
166
|
command: "ssh",
|
|
161
167
|
args: [
|
|
162
168
|
...(args.sshOptions ? args.sshOptions : []),
|
|
169
|
+
...argsOverride,
|
|
170
|
+
...(port ? ["-p", port] : []),
|
|
163
171
|
`${data.linuxUserName}@${data.id}`,
|
|
164
172
|
...(args.command ? [args.command] : []),
|
|
165
173
|
...args.arguments.map((argument) =>
|
|
@@ -173,7 +181,8 @@ const createCommand = (data, args, proxyCommand) => {
|
|
|
173
181
|
*
|
|
174
182
|
* These common args are only added if they have not been explicitly specified by the end user.
|
|
175
183
|
*/
|
|
176
|
-
const addCommonArgs = (args,
|
|
184
|
+
const addCommonArgs = (args, sshProviderProxyCommand, setupData) => {
|
|
185
|
+
var _a;
|
|
177
186
|
const sshOptions = args.sshOptions ? args.sshOptions : [];
|
|
178
187
|
const identityFileOptionExists = sshOptions.some((opt, idx) => {
|
|
179
188
|
var _a;
|
|
@@ -184,15 +193,15 @@ const addCommonArgs = (args, proxyCommand) => {
|
|
|
184
193
|
// Explicitly specify which private key to use to avoid "Too many authentication failures"
|
|
185
194
|
// error caused by SSH trying every available key
|
|
186
195
|
if (!identityFileOptionExists) {
|
|
187
|
-
sshOptions.push("-i", keys_1.PRIVATE_KEY_PATH);
|
|
196
|
+
sshOptions.push("-i", (_a = setupData === null || setupData === void 0 ? void 0 : setupData.identityFile) !== null && _a !== void 0 ? _a : keys_1.PRIVATE_KEY_PATH);
|
|
188
197
|
// Only use the authentication identity specified by -i above
|
|
189
198
|
if (!identitiesOnlyOptionExists) {
|
|
190
199
|
sshOptions.push("-o", "IdentitiesOnly=yes");
|
|
191
200
|
}
|
|
192
201
|
}
|
|
193
|
-
const
|
|
194
|
-
if (!
|
|
195
|
-
sshOptions.push("-o", `ProxyCommand=${
|
|
202
|
+
const userSpecifiedProxyCommand = sshOptions.some((opt, idx) => { var _a; return opt === "-o" && ((_a = sshOptions[idx + 1]) === null || _a === void 0 ? void 0 : _a.startsWith("ProxyCommand")); });
|
|
203
|
+
if (!userSpecifiedProxyCommand && sshProviderProxyCommand.length > 0) {
|
|
204
|
+
sshOptions.push("-o", `ProxyCommand=${sshProviderProxyCommand.join(" ")}`);
|
|
196
205
|
}
|
|
197
206
|
// Force verbose output from SSH so we can parse the output
|
|
198
207
|
const verboseOptionExists = sshOptions.some((opt) => opt === "-v");
|
|
@@ -234,7 +243,8 @@ const preTestAccessPropagationIfNeeded = (sshProvider, request, cmdArgs, proxyCo
|
|
|
234
243
|
// Pre-testing comes at a performance cost because we have to execute another ssh subprocess after
|
|
235
244
|
// a successful test. Only do when absolutely necessary.
|
|
236
245
|
if (testCmdArgs) {
|
|
237
|
-
const { command, args } = createCommand(request, testCmdArgs,
|
|
246
|
+
const { command, args } = createCommand(request, testCmdArgs, undefined, // No need to re-apply SSH options from setupData
|
|
247
|
+
proxyCommand);
|
|
238
248
|
// Assumes that this is a non-interactive ssh command that exits automatically
|
|
239
249
|
return spawnSshNode({
|
|
240
250
|
credential,
|
|
@@ -251,15 +261,18 @@ const preTestAccessPropagationIfNeeded = (sshProvider, request, cmdArgs, proxyCo
|
|
|
251
261
|
return null;
|
|
252
262
|
});
|
|
253
263
|
const sshOrScp = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
264
|
+
var _a;
|
|
254
265
|
const { authn, request, cmdArgs, privateKey, sshProvider } = args;
|
|
266
|
+
const { debug } = cmdArgs;
|
|
255
267
|
if (!privateKey) {
|
|
256
268
|
throw "Failed to load a private key for this request. Please contact support@p0.dev for assistance.";
|
|
257
269
|
}
|
|
258
270
|
const credential = yield sshProvider.cloudProviderLogin(authn, request);
|
|
259
271
|
const proxyCommand = sshProvider.proxyCommand(request);
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
272
|
+
const setupData = yield ((_a = sshProvider.setup) === null || _a === void 0 ? void 0 : _a.call(sshProvider, request, { debug }));
|
|
273
|
+
const { command, args: commandArgs } = createCommand(request, cmdArgs, setupData, proxyCommand);
|
|
274
|
+
if (debug) {
|
|
275
|
+
const reproCommands = sshProvider.reproCommands(request, setupData);
|
|
263
276
|
if (reproCommands) {
|
|
264
277
|
const repro = [
|
|
265
278
|
...reproCommands,
|
|
@@ -269,20 +282,27 @@ const sshOrScp = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
269
282
|
}
|
|
270
283
|
}
|
|
271
284
|
const endTime = Date.now() + sshProvider.propagationTimeoutMs;
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
285
|
+
let sshNodeExit;
|
|
286
|
+
try {
|
|
287
|
+
const exitCode = yield preTestAccessPropagationIfNeeded(sshProvider, request, cmdArgs, proxyCommand, credential, endTime);
|
|
288
|
+
if (exitCode && exitCode !== 0) {
|
|
289
|
+
return exitCode; // Only exit if there was an error when pre-testing
|
|
290
|
+
}
|
|
291
|
+
sshNodeExit = yield spawnSshNode({
|
|
292
|
+
credential,
|
|
293
|
+
abortController: new AbortController(),
|
|
294
|
+
command,
|
|
295
|
+
args: commandArgs,
|
|
296
|
+
stdio: ["inherit", "inherit", "pipe"],
|
|
297
|
+
debug,
|
|
298
|
+
provider: request.type,
|
|
299
|
+
endTime: endTime,
|
|
300
|
+
});
|
|
275
301
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
args: commandArgs,
|
|
281
|
-
stdio: ["inherit", "inherit", "pipe"],
|
|
282
|
-
debug: cmdArgs.debug,
|
|
283
|
-
provider: request.type,
|
|
284
|
-
endTime: endTime,
|
|
285
|
-
});
|
|
302
|
+
finally {
|
|
303
|
+
yield (setupData === null || setupData === void 0 ? void 0 : setupData.teardown());
|
|
304
|
+
}
|
|
305
|
+
return sshNodeExit;
|
|
286
306
|
});
|
|
287
307
|
exports.sshOrScp = sshOrScp;
|
|
288
308
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/ssh/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;GASG;AACH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/ssh/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;GASG;AACH,mDAImC;AACnC,4CAAqD;AACrD,+CAA6C;AAG7C,qCAAmC;AAEnC,2DAK4B;AAG5B;;GAEG;AACH,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAEzC,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,sBAAsB,GAAG,CAC7B,QAAqB,EACrB,KAAgD,EAChD,OAA4B,EAC5B,EAAE;IACF,IAAI,gCAAgC,GAAG,KAAK,CAAC;IAC7C,IAAI,gBAAgB,GAAG,KAAK,CAAC;IAE7B,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,M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AG,CAAC,EAAE;aACzD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACb,IAAA,cAAM,EACJ,gGAAgG,KAAK,2BAA2B,CACjI,CAAC;SACH;KACF;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,oBAAoB,CAAC;IAE9D,IAAI,WAAW,CAAC;IAEhB,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,gCAAgC,CACrD,WAAW,EACX,OAAO,EACP,OAAO,EACP,YAAY,EACZ,UAAU,EACV,OAAO,CACR,CAAC;QACF,IAAI,QAAQ,IAAI,QAAQ,KAAK,CAAC,EAAE;YAC9B,OAAO,QAAQ,CAAC,CAAC,mDAAmD;SACrE;QAED,WAAW,GAAG,MAAM,YAAY,CAAC;YAC/B,UAAU;YACV,eAAe,EAAE,IAAI,eAAe,EAAE;YACtC,OAAO;YACP,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC;YACrC,KAAK;YACL,QAAQ,EAAE,OAAO,CAAC,IAAI;YACtB,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;KACJ;YAAS;QACR,MAAM,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ,EAAE,CAAA,CAAC;KAC7B;IAED,OAAO,WAAW,CAAC;AACrB,CAAC,CAAA,CAAC;AAzEW,QAAA,QAAQ,YAyEnB"}
|
package/dist/types/request.d.ts
CHANGED
|
@@ -9,11 +9,13 @@ This file is part of @p0security/cli
|
|
|
9
9
|
You should have received a copy of the GNU General Public License along with @p0security/cli. If not, see <https://www.gnu.org/licenses/>.
|
|
10
10
|
**/
|
|
11
11
|
import { K8sPermissionSpec } from "../plugins/kubeconfig/types";
|
|
12
|
-
import { PluginSshRequest } from "./ssh";
|
|
12
|
+
import { PluginSshRequest, SupportedSshProvider } from "./ssh";
|
|
13
13
|
export declare const DONE_STATUSES: readonly ["DONE", "DONE_NOTIFIED"];
|
|
14
14
|
export declare const DENIED_STATUSES: readonly ["DENIED", "DENIED_NOTIFIED"];
|
|
15
15
|
export declare const ERROR_STATUSES: readonly ["ERRORED", "ERRORED", "ERRORED_NOTIFIED"];
|
|
16
16
|
export type PermissionSpec<K extends string, P extends {
|
|
17
|
+
provider: SupportedSshProvider;
|
|
18
|
+
} | {
|
|
17
19
|
type: string;
|
|
18
20
|
}, G extends object | undefined = undefined> = {
|
|
19
21
|
type: K;
|
package/dist/types/ssh.d.ts
CHANGED
|
@@ -8,23 +8,26 @@ This file is part of @p0security/cli
|
|
|
8
8
|
|
|
9
9
|
You should have received a copy of the GNU General Public License along with @p0security/cli. If not, see <https://www.gnu.org/licenses/>.
|
|
10
10
|
**/
|
|
11
|
-
import { CommandArgs } from "../commands/shared/ssh";
|
|
11
|
+
import { CommandArgs, SshAdditionalSetup } from "../commands/shared/ssh";
|
|
12
12
|
import { AwsSsh, AwsSshPermissionSpec, AwsSshRequest } from "../plugins/aws/types";
|
|
13
|
+
import { AzureSsh, AzureSshPermissionSpec, AzureSshRequest } from "../plugins/azure/types";
|
|
13
14
|
import { GcpSsh, GcpSshPermissionSpec, GcpSshRequest } from "../plugins/google/types";
|
|
14
15
|
import { Authn } from "./identity";
|
|
15
16
|
import { Request } from "./request";
|
|
16
|
-
export type CliSshRequest = AwsSsh | GcpSsh;
|
|
17
|
-
export type PluginSshRequest = AwsSshPermissionSpec | GcpSshPermissionSpec;
|
|
17
|
+
export type CliSshRequest = AwsSsh | AzureSsh | GcpSsh;
|
|
18
|
+
export type PluginSshRequest = AwsSshPermissionSpec | AzureSshPermissionSpec | GcpSshPermissionSpec;
|
|
18
19
|
export type CliPermissionSpec<P extends PluginSshRequest, C extends object | undefined> = P & {
|
|
19
20
|
cliLocalData: C;
|
|
20
21
|
};
|
|
21
|
-
export declare const SupportedSshProviders: readonly ["aws", "gcloud"];
|
|
22
|
+
export declare const SupportedSshProviders: readonly ["aws", "azure", "gcloud"];
|
|
22
23
|
export type SupportedSshProvider = (typeof SupportedSshProviders)[number];
|
|
23
24
|
export type SshProvider<PR extends PluginSshRequest = PluginSshRequest, O extends object | undefined = undefined, SR extends SshRequest = SshRequest, C extends object | undefined = undefined> = {
|
|
24
25
|
/** Logs in the user to the cloud provider */
|
|
25
26
|
cloudProviderLogin: (authn: Authn, request: SR) => Promise<C>;
|
|
26
27
|
/** Callback to ensure that this provider's CLI utils are installed */
|
|
27
28
|
ensureInstall: () => Promise<void>;
|
|
29
|
+
/** Validate the SSH key if necessary; throw an exception if the key is invalid */
|
|
30
|
+
validateSshKey?: (request: Request<PR>, publicKey: string) => boolean;
|
|
28
31
|
/** A human-readable name for this CSP */
|
|
29
32
|
friendlyName: string;
|
|
30
33
|
/** Friendly message to ask the user to log in to the CSP */
|
|
@@ -41,11 +44,16 @@ export type SshProvider<PR extends PluginSshRequest = PluginSshRequest, O extend
|
|
|
41
44
|
* the actual ssh/scp command.
|
|
42
45
|
*/
|
|
43
46
|
preTestAccessPropagationArgs: (cmdArgs: CommandArgs) => CommandArgs | undefined;
|
|
47
|
+
/** Perform any setup required before running the SSH command. Returns a list of additional arguments to pass to the
|
|
48
|
+
* SSH command. */
|
|
49
|
+
setup?: (request: SR, options?: {
|
|
50
|
+
debug?: boolean;
|
|
51
|
+
}) => Promise<SshAdditionalSetup>;
|
|
44
52
|
/** Returns the command and its arguments that are going to be injected as the ssh ProxyCommand option */
|
|
45
53
|
proxyCommand: (request: SR) => string[];
|
|
46
54
|
/** Each element in the returned array is a command that can be run to reproduce the
|
|
47
55
|
* steps of logging in the user to the ssh session. */
|
|
48
|
-
reproCommands: (request: SR) => string[] | undefined;
|
|
56
|
+
reproCommands: (request: SR, additionalData?: SshAdditionalSetup) => string[] | undefined;
|
|
49
57
|
/** Unwraps this provider's types */
|
|
50
58
|
requestToSsh: (request: CliPermissionSpec<PR, O>) => SR;
|
|
51
59
|
/** Regex matches for error strings indicating that the provider has not yet fully provisioned node acces */
|
|
@@ -60,4 +68,4 @@ export type SshProvider<PR extends PluginSshRequest = PluginSshRequest, O extend
|
|
|
60
68
|
debug?: boolean;
|
|
61
69
|
}) => Promise<Request<CliSshRequest>>;
|
|
62
70
|
};
|
|
63
|
-
export type SshRequest = AwsSshRequest | GcpSshRequest;
|
|
71
|
+
export type SshRequest = AwsSshRequest | AzureSshRequest | GcpSshRequest;
|
package/dist/types/ssh.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SupportedSshProviders = void 0;
|
|
4
4
|
// The prefix of installed SSH accounts in P0 is the provider name
|
|
5
|
-
exports.SupportedSshProviders = ["aws", "gcloud"];
|
|
5
|
+
exports.SupportedSshProviders = ["aws", "azure", "gcloud"];
|
|
6
6
|
//# sourceMappingURL=ssh.js.map
|
package/dist/types/ssh.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssh.js","sourceRoot":"","sources":["../../src/types/ssh.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"ssh.js","sourceRoot":"","sources":["../../src/types/ssh.ts"],"names":[],"mappings":";;;AA0CA,kEAAkE;AACrD,QAAA,qBAAqB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC"}
|