@p0security/cli 0.10.0 → 0.11.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.
Files changed (176) hide show
  1. package/README.md +8 -1
  2. package/dist/commands/__tests__/grant.test.js +1 -0
  3. package/dist/commands/__tests__/grant.test.js.map +1 -0
  4. package/dist/commands/__tests__/login.test.js +1 -0
  5. package/dist/commands/__tests__/login.test.js.map +1 -0
  6. package/dist/commands/__tests__/ls.test.js +1 -0
  7. package/dist/commands/__tests__/ls.test.js.map +1 -0
  8. package/dist/commands/__tests__/request.test.js +1 -0
  9. package/dist/commands/__tests__/request.test.js.map +1 -0
  10. package/dist/commands/__tests__/ssh.test.js +1 -0
  11. package/dist/commands/__tests__/ssh.test.js.map +1 -0
  12. package/dist/commands/allow.js +1 -0
  13. package/dist/commands/allow.js.map +1 -0
  14. package/dist/commands/aws/__tests__/__input__/saml-response.js +1 -0
  15. package/dist/commands/aws/__tests__/__input__/saml-response.js.map +1 -0
  16. package/dist/commands/aws/__tests__/__input__/sts-response.js +1 -0
  17. package/dist/commands/aws/__tests__/__input__/sts-response.js.map +1 -0
  18. package/dist/commands/aws/__tests__/role.test.js +1 -0
  19. package/dist/commands/aws/__tests__/role.test.js.map +1 -0
  20. package/dist/commands/aws/files.js +1 -0
  21. package/dist/commands/aws/files.js.map +1 -0
  22. package/dist/commands/aws/index.js +1 -0
  23. package/dist/commands/aws/index.js.map +1 -0
  24. package/dist/commands/aws/role.js +1 -0
  25. package/dist/commands/aws/role.js.map +1 -0
  26. package/dist/commands/grant.js +1 -0
  27. package/dist/commands/grant.js.map +1 -0
  28. package/dist/commands/index.js +3 -1
  29. package/dist/commands/index.js.map +1 -0
  30. package/dist/commands/kubeconfig.d.ts +1 -1
  31. package/dist/commands/kubeconfig.js +1 -0
  32. package/dist/commands/kubeconfig.js.map +1 -0
  33. package/dist/commands/login.js +1 -0
  34. package/dist/commands/login.js.map +1 -0
  35. package/dist/commands/ls.js +2 -0
  36. package/dist/commands/ls.js.map +1 -0
  37. package/dist/commands/request.js +1 -0
  38. package/dist/commands/request.js.map +1 -0
  39. package/dist/commands/scp.js +14 -2
  40. package/dist/commands/scp.js.map +1 -0
  41. package/dist/commands/shared/index.js +1 -0
  42. package/dist/commands/shared/index.js.map +1 -0
  43. package/dist/commands/shared/request.js +1 -0
  44. package/dist/commands/shared/request.js.map +1 -0
  45. package/dist/commands/shared/ssh.d.ts +5 -9
  46. package/dist/commands/shared/ssh.js +1 -0
  47. package/dist/commands/shared/ssh.js.map +1 -0
  48. package/dist/commands/ssh.js +16 -24
  49. package/dist/commands/ssh.js.map +1 -0
  50. package/dist/common/__mocks__/keys.js +1 -0
  51. package/dist/common/__mocks__/keys.js.map +1 -0
  52. package/dist/common/auth/oidc.js +1 -0
  53. package/dist/common/auth/oidc.js.map +1 -0
  54. package/dist/common/auth/server.js +1 -0
  55. package/dist/common/auth/server.js.map +1 -0
  56. package/dist/common/fetch.js +1 -0
  57. package/dist/common/fetch.js.map +1 -0
  58. package/dist/common/install.d.ts +3 -3
  59. package/dist/common/install.js +1 -0
  60. package/dist/common/install.js.map +1 -0
  61. package/dist/common/keys.js +1 -0
  62. package/dist/common/keys.js.map +1 -0
  63. package/dist/common/mime.js +1 -0
  64. package/dist/common/mime.js.map +1 -0
  65. package/dist/common/retry.js +1 -0
  66. package/dist/common/retry.js.map +1 -0
  67. package/dist/common/subprocess.d.ts +4 -2
  68. package/dist/common/subprocess.js +10 -3
  69. package/dist/common/subprocess.js.map +1 -0
  70. package/dist/common/xml.js +1 -0
  71. package/dist/common/xml.js.map +1 -0
  72. package/dist/drivers/__mocks__/auth.js +1 -0
  73. package/dist/drivers/__mocks__/auth.js.map +1 -0
  74. package/dist/drivers/api.js +24 -13
  75. package/dist/drivers/api.js.map +1 -0
  76. package/dist/drivers/auth.js +1 -0
  77. package/dist/drivers/auth.js.map +1 -0
  78. package/dist/drivers/env.d.ts +1 -0
  79. package/dist/drivers/env.js +3 -1
  80. package/dist/drivers/env.js.map +1 -0
  81. package/dist/drivers/firestore.js +1 -0
  82. package/dist/drivers/firestore.js.map +1 -0
  83. package/dist/drivers/stdio.js +1 -0
  84. package/dist/drivers/stdio.js.map +1 -0
  85. package/dist/index.js +2 -1
  86. package/dist/index.js.map +1 -0
  87. package/dist/middlewares/version.js +1 -0
  88. package/dist/middlewares/version.js.map +1 -0
  89. package/dist/plugins/__mocks__/login.js +1 -0
  90. package/dist/plugins/__mocks__/login.js.map +1 -0
  91. package/dist/plugins/aws/__mocks__/assumeRole.js +1 -0
  92. package/dist/plugins/aws/__mocks__/assumeRole.js.map +1 -0
  93. package/dist/plugins/aws/api.js +1 -0
  94. package/dist/plugins/aws/api.js.map +1 -0
  95. package/dist/plugins/aws/assumeRole.js +1 -0
  96. package/dist/plugins/aws/assumeRole.js.map +1 -0
  97. package/dist/plugins/aws/config.js +1 -0
  98. package/dist/plugins/aws/config.js.map +1 -0
  99. package/dist/plugins/aws/idc/index.js +1 -0
  100. package/dist/plugins/aws/idc/index.js.map +1 -0
  101. package/dist/plugins/aws/ssh.js +1 -0
  102. package/dist/plugins/aws/ssh.js.map +1 -0
  103. package/dist/plugins/aws/ssm/install.js +1 -0
  104. package/dist/plugins/aws/ssm/install.js.map +1 -0
  105. package/dist/plugins/aws/types.d.ts +16 -16
  106. package/dist/plugins/aws/types.js +1 -0
  107. package/dist/plugins/aws/types.js.map +1 -0
  108. package/dist/plugins/google/install.js +1 -0
  109. package/dist/plugins/google/install.js.map +1 -0
  110. package/dist/plugins/google/login.js +1 -0
  111. package/dist/plugins/google/login.js.map +1 -0
  112. package/dist/plugins/google/ssh-key.js +4 -0
  113. package/dist/plugins/google/ssh-key.js.map +1 -0
  114. package/dist/plugins/google/ssh.js +1 -0
  115. package/dist/plugins/google/ssh.js.map +1 -0
  116. package/dist/plugins/google/types.d.ts +8 -8
  117. package/dist/plugins/google/types.js +1 -0
  118. package/dist/plugins/google/types.js.map +1 -0
  119. package/dist/plugins/kubeconfig/index.js +1 -0
  120. package/dist/plugins/kubeconfig/index.js.map +1 -0
  121. package/dist/plugins/kubeconfig/install.js +1 -0
  122. package/dist/plugins/kubeconfig/install.js.map +1 -0
  123. package/dist/plugins/kubeconfig/types.d.ts +5 -5
  124. package/dist/plugins/kubeconfig/types.js +1 -0
  125. package/dist/plugins/kubeconfig/types.js.map +1 -0
  126. package/dist/plugins/login.d.ts +1 -1
  127. package/dist/plugins/login.js +1 -0
  128. package/dist/plugins/login.js.map +1 -0
  129. package/dist/plugins/oidc/login.js +1 -0
  130. package/dist/plugins/oidc/login.js.map +1 -0
  131. package/dist/plugins/okta/aws.js +1 -0
  132. package/dist/plugins/okta/aws.js.map +1 -0
  133. package/dist/plugins/okta/login.js +1 -0
  134. package/dist/plugins/okta/login.js.map +1 -0
  135. package/dist/plugins/ping/login.js +1 -0
  136. package/dist/plugins/ping/login.js.map +1 -0
  137. package/dist/plugins/ssh/index.js +80 -49
  138. package/dist/plugins/ssh/index.js.map +1 -0
  139. package/dist/plugins/ssh/types.d.ts +3 -3
  140. package/dist/plugins/ssh/types.js +1 -0
  141. package/dist/plugins/ssh/types.js.map +1 -0
  142. package/dist/testing/firestore.js +1 -0
  143. package/dist/testing/firestore.js.map +1 -0
  144. package/dist/testing/yargs.js +1 -0
  145. package/dist/testing/yargs.js.map +1 -0
  146. package/dist/types/allow.d.ts +1 -1
  147. package/dist/types/allow.js +1 -0
  148. package/dist/types/allow.js.map +1 -0
  149. package/dist/types/aws/oidc.d.ts +3 -3
  150. package/dist/types/aws/oidc.js +1 -0
  151. package/dist/types/aws/oidc.js.map +1 -0
  152. package/dist/types/identity.d.ts +2 -2
  153. package/dist/types/identity.js +1 -0
  154. package/dist/types/identity.js.map +1 -0
  155. package/dist/types/index.js +1 -0
  156. package/dist/types/index.js.map +1 -0
  157. package/dist/types/oidc.d.ts +5 -5
  158. package/dist/types/oidc.js +1 -0
  159. package/dist/types/oidc.js.map +1 -0
  160. package/dist/types/org.d.ts +3 -3
  161. package/dist/types/org.js +1 -0
  162. package/dist/types/org.js.map +1 -0
  163. package/dist/types/request.d.ts +4 -4
  164. package/dist/types/request.js +1 -0
  165. package/dist/types/request.js.map +1 -0
  166. package/dist/types/ssh.d.ts +6 -6
  167. package/dist/types/ssh.js +1 -0
  168. package/dist/types/ssh.js.map +1 -0
  169. package/dist/util.d.ts +1 -10
  170. package/dist/util.js +6 -2
  171. package/dist/util.js.map +1 -0
  172. package/package.json +5 -1
  173. package/dist/plugins/ssh-agent/index.d.ts +0 -4
  174. package/dist/plugins/ssh-agent/index.js +0 -102
  175. package/dist/plugins/ssh-agent/types.d.ts +0 -13
  176. package/dist/plugins/ssh-agent/types.js +0 -2
package/dist/util.d.ts CHANGED
@@ -1,13 +1,3 @@
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
1
  import child_process from "node:child_process";
12
2
  export declare const P0_PATH: string;
13
3
  /** Waits the specified delay (in ms)
@@ -54,3 +44,4 @@ export declare const unexpectedValueError: (value: any) => Error;
54
44
  * @returns true if the strings are equal, ignoring case
55
45
  */
56
46
  export declare const ciEquals: (a: string, b: string) => boolean;
47
+ export declare const delay: (ms: number) => Promise<unknown>;
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.ciEquals = exports.unexpectedValueError = exports.assertNever = exports.throwAssertNever = exports.exec = exports.timeout = exports.sleep = exports.P0_PATH = void 0;
15
+ exports.delay = exports.ciEquals = 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
@@ -23,10 +23,11 @@ This file is part of @p0security/cli
23
23
 
24
24
  You should have received a copy of the GNU General Public License along with @p0security/cli. If not, see <https://www.gnu.org/licenses/>.
25
25
  **/
26
+ const env_1 = require("./drivers/env");
26
27
  const node_child_process_1 = __importDefault(require("node:child_process"));
27
28
  const node_os_1 = __importDefault(require("node:os"));
28
29
  const node_path_1 = __importDefault(require("node:path"));
29
- exports.P0_PATH = node_path_1.default.join(node_os_1.default.homedir(), ".p0");
30
+ exports.P0_PATH = node_path_1.default.join(node_os_1.default.homedir(), env_1.config.environment === "production" ? ".p0" : `.p0-${env_1.config.environment}`);
30
31
  /** Waits the specified delay (in ms)
31
32
  *
32
33
  * The returned promise is cancelable:
@@ -107,3 +108,6 @@ exports.unexpectedValueError = unexpectedValueError;
107
108
  */
108
109
  const ciEquals = (a, b) => a.localeCompare(b, undefined, { sensitivity: "accent" }) === 0;
109
110
  exports.ciEquals = ciEquals;
111
+ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
112
+ exports.delay = delay;
113
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;GASG;AACH,uCAAuC;AACvC,4EAA+C;AAC/C,sDAAyB;AACzB,0DAA6B;AAEhB,QAAA,OAAO,GAAG,mBAAI,CAAC,IAAI,CAC9B,iBAAE,CAAC,OAAO,EAAE,EACZ,YAAM,CAAC,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,YAAM,CAAC,WAAW,EAAE,CAC1E,CAAC;AAEF;;;;;;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,GAAG,CAAC,KAAU,EAAE,EAAE,CACjD,IAAI,KAAK,CAAC,gCAAgC,KAAK,sBAAsB,CAAC,CAAC;AAD5D,QAAA,oBAAoB,wBACwC;AAEzE;;;;;;;;;GASG;AACI,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAC/C,CAAC,CAAC,aAAa,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC;AADpD,QAAA,QAAQ,YAC4C;AAE1D,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAClC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AADvC,QAAA,KAAK,SACkC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@p0security/cli",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Execute infra CLI commands with P0 grants",
5
5
  "main": "index.ts",
6
6
  "repository": {
@@ -12,6 +12,9 @@
12
12
  "bin": {
13
13
  "p0": "p0"
14
14
  },
15
+ "engines": {
16
+ "node": ">=20.14"
17
+ },
15
18
  "files": [
16
19
  "dist",
17
20
  "p0",
@@ -62,6 +65,7 @@
62
65
  "eslint-plugin-promise": "^6.1.1",
63
66
  "jest": "^29.7.0",
64
67
  "prettier": "^3.2.4",
68
+ "ts-node": "^10.9.2",
65
69
  "ts-jest": "^29.1.2"
66
70
  },
67
71
  "scripts": {
@@ -1,4 +0,0 @@
1
- import { AgentArgs } from "./types";
2
- export declare const privateKeyExists: (args: AgentArgs) => Promise<boolean>;
3
- export declare const addPrivateKey: (args: AgentArgs) => Promise<boolean>;
4
- export declare const withSshAgent: <T>(args: AgentArgs, fn: () => Promise<T>) => Promise<T>;
@@ -1,102 +0,0 @@
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.addPrivateKey = exports.privateKeyExists = 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 keys_1 = require("../../common/keys");
24
- const subprocess_1 = require("../../common/subprocess");
25
- const stdio_1 = require("../../drivers/stdio");
26
- const isSshAgentRunning = (args) => __awaiter(void 0, void 0, void 0, function* () {
27
- try {
28
- if (args.debug)
29
- (0, stdio_1.print2)("Searching for active ssh-agents");
30
- // TODO: There's a possible edge-case but unlikely that ssh-agent has an invalid process or PID.
31
- // We can check to see if the active PID matches the current socket to mitigate this.
32
- yield (0, subprocess_1.asyncSpawn)(args, `pgrep`, ["-x", "ssh-agent"]);
33
- if (args.debug)
34
- (0, stdio_1.print2)("At least one SSH agent is running");
35
- return true;
36
- }
37
- catch (_a) {
38
- if (args.debug)
39
- (0, stdio_1.print2)("No SSH agent is running!");
40
- return false;
41
- }
42
- });
43
- const isSshAgentAuthSocketSet = (args) => __awaiter(void 0, void 0, void 0, function* () {
44
- try {
45
- yield (0, subprocess_1.asyncSpawn)(args, `sh`, ["-c", '[ -n "$SSH_AUTH_SOCK" ]']);
46
- if (args.debug)
47
- (0, stdio_1.print2)(`SSH_AUTH_SOCK=${process.env.SSH_AUTH_SOCK}`);
48
- return true;
49
- }
50
- catch (_b) {
51
- if (args.debug)
52
- (0, stdio_1.print2)("SSH_AUTH_SOCK is not set!");
53
- return false;
54
- }
55
- });
56
- const privateKeyExists = (args) => __awaiter(void 0, void 0, void 0, function* () {
57
- try {
58
- yield (0, subprocess_1.asyncSpawn)(args, `sh`, [
59
- "-c",
60
- `KEY_PATH="${keys_1.PRIVATE_KEY_PATH}" && KEY_FINGERPRINT=$(ssh-keygen -lf "$KEY_PATH" | awk '{print $2}') && ssh-add -l | grep -q "$KEY_FINGERPRINT" && exit 0 || exit 1`,
61
- ]);
62
- if (args.debug)
63
- (0, stdio_1.print2)("Private key exists in ssh agent");
64
- return true;
65
- }
66
- catch (_c) {
67
- if (args.debug)
68
- (0, stdio_1.print2)("Private key does not exist in ssh agent");
69
- return false;
70
- }
71
- });
72
- exports.privateKeyExists = privateKeyExists;
73
- const addPrivateKey = (args) => __awaiter(void 0, void 0, void 0, function* () {
74
- try {
75
- yield (0, subprocess_1.asyncSpawn)(args, `ssh-add`, [
76
- keys_1.PRIVATE_KEY_PATH,
77
- ...(args.debug ? ["-v", "-v", "-v"] : ["-q"]),
78
- ]);
79
- if (args.debug)
80
- (0, stdio_1.print2)("Private key added to ssh agent");
81
- return true;
82
- }
83
- catch (_d) {
84
- if (args.debug)
85
- (0, stdio_1.print2)("Failed to add private key to ssh agent");
86
- return false;
87
- }
88
- });
89
- exports.addPrivateKey = addPrivateKey;
90
- const withSshAgent = (args, fn) => __awaiter(void 0, void 0, void 0, function* () {
91
- const isRunning = yield isSshAgentRunning(args);
92
- const hasSocket = yield isSshAgentAuthSocketSet(args);
93
- if (!isRunning || !hasSocket) {
94
- throw "SSH agent is not running. Please start it by running: eval $(ssh-agent)";
95
- }
96
- const hasKey = yield (0, exports.privateKeyExists)(args);
97
- if (!hasKey) {
98
- yield (0, exports.addPrivateKey)(args);
99
- }
100
- return yield fn();
101
- });
102
- exports.withSshAgent = withSshAgent;
@@ -1,13 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });