@p0security/cli 0.6.1 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/__tests__/ssh.test.js +18 -4
- package/dist/commands/allow.d.ts +10 -0
- package/dist/commands/allow.js +57 -0
- package/dist/commands/index.js +2 -0
- package/dist/commands/scp.js +3 -13
- package/dist/commands/shared.d.ts +6 -0
- package/dist/commands/shared.js +12 -1
- package/dist/commands/ssh.js +15 -14
- package/dist/index.d.ts +1 -0
- package/dist/index.js +12 -1
- package/dist/plugins/aws/ssm/index.d.ts +1 -3
- package/dist/plugins/aws/ssm/index.js +83 -240
- package/dist/plugins/login.js +2 -0
- package/dist/plugins/oidc/login.d.ts +5 -0
- package/dist/plugins/oidc/login.js +133 -0
- package/dist/plugins/okta/login.js +4 -88
- package/dist/plugins/ping/login.d.ts +13 -0
- package/dist/plugins/ping/login.js +16 -0
- package/dist/plugins/ssh-agent/index.d.ts +10 -0
- package/dist/plugins/ssh-agent/index.js +142 -0
- package/dist/plugins/ssh-agent/types.d.ts +17 -0
- package/dist/plugins/ssh-agent/types.js +2 -0
- package/dist/types/allow.d.ts +14 -0
- package/dist/types/allow.js +2 -0
- package/dist/types/org.d.ts +12 -4
- package/dist/types/org.js +10 -0
- package/dist/util.d.ts +3 -0
- package/dist/util.js +11 -1
- package/package.json +1 -3
|
@@ -0,0 +1,13 @@
|
|
|
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 { OrgData } from "../../types/org";
|
|
12
|
+
/** Logs in to PingOne via OIDC */
|
|
13
|
+
export declare const pingLogin: (org: OrgData) => Promise<import("../../types/oidc").TokenResponse>;
|
|
@@ -0,0 +1,16 @@
|
|
|
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.pingLogin = void 0;
|
|
13
|
+
const login_1 = require("../oidc/login");
|
|
14
|
+
/** Logs in to PingOne via OIDC */
|
|
15
|
+
const pingLogin = (org) => __awaiter(void 0, void 0, void 0, function* () { return (0, login_1.oidcLogin)(org, "openid email profile"); });
|
|
16
|
+
exports.pingLogin = pingLogin;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AgentArgs, SshAgentEnv } from "./types";
|
|
2
|
+
/** Spawns a subprocess with the ssh-agent command.
|
|
3
|
+
* Detects the auth socket and agent PID from stdout.
|
|
4
|
+
* Stdout and stderr of the subprocess is printed to stderr in debug mode.
|
|
5
|
+
* The returned promise resolves with an object that contains the auth socket and agent PID,
|
|
6
|
+
* or rejects with the contents of stderr. */
|
|
7
|
+
export declare const sshAgent: (cmdArgs: AgentArgs) => Promise<SshAgentEnv>;
|
|
8
|
+
export declare const sshAdd: (args: AgentArgs, sshAgentEnv: SshAgentEnv, privateKey: string) => Promise<number>;
|
|
9
|
+
export declare const sshAddList: (args: AgentArgs, sshAgentEnv: SshAgentEnv) => Promise<number>;
|
|
10
|
+
export declare const withSshAgent: <T>(args: AgentArgs, fn: (sshAgentEnv: SshAgentEnv) => Promise<T>) => Promise<T>;
|
|
@@ -0,0 +1,142 @@
|
|
|
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.withSshAgent = exports.sshAddList = exports.sshAdd = exports.sshAgent = 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 __1 = require("../..");
|
|
24
|
+
const stdio_1 = require("../../drivers/stdio");
|
|
25
|
+
const node_child_process_1 = require("node:child_process");
|
|
26
|
+
const AUTH_SOCK_MESSAGE = /SSH_AUTH_SOCK=(.+?);/;
|
|
27
|
+
const AGENT_PID_MESSAGE = /SSH_AGENT_PID=(\d+?);/;
|
|
28
|
+
/** Spawns a subprocess with given command, args, and options.
|
|
29
|
+
* May write content to its standard input.
|
|
30
|
+
* Stdout and stderr of the subprocess is printed to stderr in debug mode.
|
|
31
|
+
* The returned promise resolves or rejects with the exit code. */
|
|
32
|
+
const asyncSpawn = ({ debug }, command, args, options, writeStdin) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var _a;
|
|
35
|
+
const child = (0, node_child_process_1.spawn)(command, args, options);
|
|
36
|
+
if (writeStdin) {
|
|
37
|
+
if (!child.stdin)
|
|
38
|
+
return reject("Child process has no stdin");
|
|
39
|
+
child.stdin.write(writeStdin);
|
|
40
|
+
}
|
|
41
|
+
child.stdout.on("data", (data) => {
|
|
42
|
+
if (debug) {
|
|
43
|
+
(0, stdio_1.print2)(data.toString("utf-8"));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
child.stderr.on("data", (data) => {
|
|
47
|
+
if (debug) {
|
|
48
|
+
(0, stdio_1.print2)(data.toString("utf-8"));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
child.on("exit", (code) => {
|
|
52
|
+
if (code !== 0) {
|
|
53
|
+
return reject(code);
|
|
54
|
+
}
|
|
55
|
+
resolve(code);
|
|
56
|
+
});
|
|
57
|
+
if (writeStdin) {
|
|
58
|
+
(_a = child.stdin) === null || _a === void 0 ? void 0 : _a.end();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
/** Spawns a subprocess with the ssh-agent command.
|
|
63
|
+
* Detects the auth socket and agent PID from stdout.
|
|
64
|
+
* Stdout and stderr of the subprocess is printed to stderr in debug mode.
|
|
65
|
+
* The returned promise resolves with an object that contains the auth socket and agent PID,
|
|
66
|
+
* or rejects with the contents of stderr. */
|
|
67
|
+
const sshAgent = (cmdArgs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
let stderr = "";
|
|
70
|
+
let stdout = "";
|
|
71
|
+
// There is a debug flag in ssh-agent but it causes the ssh-agent process to NOT fork
|
|
72
|
+
const child = (0, node_child_process_1.spawn)("ssh-agent");
|
|
73
|
+
child.stdout.on("data", (data) => {
|
|
74
|
+
const str = data.toString("utf-8");
|
|
75
|
+
if (cmdArgs.debug) {
|
|
76
|
+
(0, stdio_1.print2)(str);
|
|
77
|
+
}
|
|
78
|
+
stdout += str;
|
|
79
|
+
});
|
|
80
|
+
child.stderr.on("data", (data) => {
|
|
81
|
+
const str = data.toString("utf-8");
|
|
82
|
+
if (cmdArgs.debug) {
|
|
83
|
+
(0, stdio_1.print2)(str);
|
|
84
|
+
}
|
|
85
|
+
stderr += str;
|
|
86
|
+
});
|
|
87
|
+
const exitListener = child.on("exit", (code) => {
|
|
88
|
+
exitListener.unref();
|
|
89
|
+
if (code !== 0) {
|
|
90
|
+
return reject(stderr);
|
|
91
|
+
}
|
|
92
|
+
const authSockMatch = stdout.match(AUTH_SOCK_MESSAGE);
|
|
93
|
+
const agentPidMatch = stdout.match(AGENT_PID_MESSAGE);
|
|
94
|
+
if (!(authSockMatch === null || authSockMatch === void 0 ? void 0 : authSockMatch[1]) || !(agentPidMatch === null || agentPidMatch === void 0 ? void 0 : agentPidMatch[1])) {
|
|
95
|
+
return reject("Failed to parse ssh-agent stdout:\n" + stdout);
|
|
96
|
+
}
|
|
97
|
+
resolve({
|
|
98
|
+
SSH_AUTH_SOCK: authSockMatch[1],
|
|
99
|
+
SSH_AGENT_PID: agentPidMatch[1],
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
exports.sshAgent = sshAgent;
|
|
105
|
+
const sshAgentKill = (args, sshAgentEnv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
+
return asyncSpawn(args, "ssh-agent", ["-k"], {
|
|
107
|
+
env: Object.assign(Object.assign({}, process.env), sshAgentEnv),
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
const sshAdd = (args, sshAgentEnv, privateKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
+
return asyncSpawn(args, "ssh-add",
|
|
112
|
+
// In debug mode do not use the quiet flag. There is no debug flag in ssh-add.
|
|
113
|
+
// Instead increase to maximum verbosity of 3 with -v flag.
|
|
114
|
+
args.debug ? ["-v", "-v", "-v", "-"] : ["-q", "-"], { env: Object.assign(Object.assign({}, process.env), sshAgentEnv) }, privateKey);
|
|
115
|
+
});
|
|
116
|
+
exports.sshAdd = sshAdd;
|
|
117
|
+
const sshAddList = (args, sshAgentEnv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
return asyncSpawn(args, "ssh-add", ["-l"], {
|
|
119
|
+
env: Object.assign(Object.assign({}, process.env), sshAgentEnv),
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
exports.sshAddList = sshAddList;
|
|
123
|
+
const withSshAgent = (args, fn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
+
const sshAgentEnv = yield (0, exports.sshAgent)(args);
|
|
125
|
+
// The ssh-agent runs in a process that is not automatically terminated.
|
|
126
|
+
// 1. Kill it when catching the main process termination signal.
|
|
127
|
+
// 2. Also kill it if the encapsulated function throws an error.
|
|
128
|
+
const abortListener = (_code) => {
|
|
129
|
+
__1.TERMINATION_CONTROLLER.signal.removeEventListener("abort", abortListener);
|
|
130
|
+
void sshAgentKill(args, sshAgentEnv);
|
|
131
|
+
};
|
|
132
|
+
__1.TERMINATION_CONTROLLER.signal.addEventListener("abort", abortListener);
|
|
133
|
+
try {
|
|
134
|
+
return yield fn(sshAgentEnv);
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
// keep the ssh-agent alive in debug mode
|
|
138
|
+
if (!args.debug)
|
|
139
|
+
yield sshAgentKill(args, sshAgentEnv);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
exports.withSshAgent = withSshAgent;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
export declare type AgentArgs = {
|
|
12
|
+
debug?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare type SshAgentEnv = {
|
|
15
|
+
SSH_AUTH_SOCK: string;
|
|
16
|
+
SSH_AGENT_PID: string;
|
|
17
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
export declare type AllowResponse = {
|
|
12
|
+
ok: true;
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
package/dist/types/org.d.ts
CHANGED
|
@@ -8,13 +8,21 @@ 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
|
-
|
|
12
|
-
export declare type OrgData = {
|
|
11
|
+
declare type BaseOrgData = {
|
|
13
12
|
clientId: string;
|
|
14
13
|
providerId: string;
|
|
15
14
|
providerDomain?: string;
|
|
16
|
-
providerType?: "okta";
|
|
17
15
|
ssoProvider: "azure-oidc" | "google-oidc" | "google" | "microsoft" | "oidc-pkce" | "okta";
|
|
18
|
-
slug: string;
|
|
19
16
|
tenantId: string;
|
|
20
17
|
};
|
|
18
|
+
/** Publicly readable organization data */
|
|
19
|
+
export declare type RawOrgData = BaseOrgData & ({
|
|
20
|
+
providerType?: "okta";
|
|
21
|
+
} | {
|
|
22
|
+
providerType?: "ping";
|
|
23
|
+
environmentId: string;
|
|
24
|
+
});
|
|
25
|
+
export declare type OrgData = RawOrgData & {
|
|
26
|
+
slug: string;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
package/dist/types/org.js
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/** Copyright © 2024-present P0 Security
|
|
3
|
+
|
|
4
|
+
This file is part of @p0security/cli
|
|
5
|
+
|
|
6
|
+
@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.
|
|
7
|
+
|
|
8
|
+
@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.
|
|
9
|
+
|
|
10
|
+
You should have received a copy of the GNU General Public License along with @p0security/cli. If not, see <https://www.gnu.org/licenses/>.
|
|
11
|
+
**/
|
|
2
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/util.d.ts
CHANGED
|
@@ -40,3 +40,6 @@ export declare const exec: (command: string, args: string[], options?: child_pro
|
|
|
40
40
|
stdout: string;
|
|
41
41
|
stderr: string;
|
|
42
42
|
}>;
|
|
43
|
+
export declare const throwAssertNever: (value: never) => never;
|
|
44
|
+
export declare const assertNever: (value: never) => Error;
|
|
45
|
+
export declare const unexpectedValueError: (value: any) => Error;
|
package/dist/util.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.exec = exports.timeout = exports.sleep = exports.P0_PATH = void 0;
|
|
15
|
+
exports.unexpectedValueError = exports.assertNever = exports.throwAssertNever = exports.exec = exports.timeout = exports.sleep = exports.P0_PATH = void 0;
|
|
16
16
|
/** Copyright © 2024-present P0 Security
|
|
17
17
|
|
|
18
18
|
This file is part of @p0security/cli
|
|
@@ -85,3 +85,13 @@ const exec = (command, args, options) => __awaiter(void 0, void 0, void 0, funct
|
|
|
85
85
|
});
|
|
86
86
|
});
|
|
87
87
|
exports.exec = exec;
|
|
88
|
+
const throwAssertNever = (value) => {
|
|
89
|
+
throw (0, exports.assertNever)(value);
|
|
90
|
+
};
|
|
91
|
+
exports.throwAssertNever = throwAssertNever;
|
|
92
|
+
const assertNever = (value) => {
|
|
93
|
+
return (0, exports.unexpectedValueError)(value);
|
|
94
|
+
};
|
|
95
|
+
exports.assertNever = assertNever;
|
|
96
|
+
const unexpectedValueError = (value) => new Error(`Unexpected code state: value ${value} had unexpected type`);
|
|
97
|
+
exports.unexpectedValueError = unexpectedValueError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@p0security/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Execute infra CLI commands with P0 grants",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"repository": {
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
"open": "^8.4.0",
|
|
32
32
|
"pkce-challenge": "^4.1.0",
|
|
33
33
|
"pluralize": "^8.0.0",
|
|
34
|
-
"ps-tree": "^1.2.0",
|
|
35
34
|
"semver": "^7.6.0",
|
|
36
35
|
"typescript": "^4.8.4",
|
|
37
36
|
"which": "^4.0.0",
|
|
@@ -47,7 +46,6 @@
|
|
|
47
46
|
"@types/node": "^18.11.7",
|
|
48
47
|
"@types/node-forge": "^1.3.11",
|
|
49
48
|
"@types/pluralize": "^0.0.33",
|
|
50
|
-
"@types/ps-tree": "^1.1.6",
|
|
51
49
|
"@types/which": "^3.0.3",
|
|
52
50
|
"@types/yargs": "^17.0.13",
|
|
53
51
|
"@typescript-eslint/eslint-plugin": "^6.4.0",
|