@p0security/cli 0.9.0 → 0.10.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.
Files changed (179) 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 +12 -10
  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 +15 -7
  46. package/dist/commands/shared/ssh.js +16 -5
  47. package/dist/commands/shared/ssh.js.map +1 -0
  48. package/dist/commands/ssh.js +23 -12
  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 +5 -2
  102. package/dist/plugins/aws/ssh.js.map +1 -0
  103. package/dist/plugins/aws/ssm/install.js +2 -21
  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.d.ts +2 -0
  109. package/dist/plugins/google/install.js +39 -0
  110. package/dist/plugins/google/install.js.map +1 -0
  111. package/dist/plugins/google/login.js +1 -0
  112. package/dist/plugins/google/login.js.map +1 -0
  113. package/dist/plugins/google/ssh-key.js +4 -0
  114. package/dist/plugins/google/ssh-key.js.map +1 -0
  115. package/dist/plugins/google/ssh.js +7 -0
  116. package/dist/plugins/google/ssh.js.map +1 -0
  117. package/dist/plugins/google/types.d.ts +8 -8
  118. package/dist/plugins/google/types.js +1 -0
  119. package/dist/plugins/google/types.js.map +1 -0
  120. package/dist/plugins/kubeconfig/index.d.ts +6 -2
  121. package/dist/plugins/kubeconfig/index.js +14 -7
  122. package/dist/plugins/kubeconfig/index.js.map +1 -0
  123. package/dist/plugins/kubeconfig/install.js +1 -0
  124. package/dist/plugins/kubeconfig/install.js.map +1 -0
  125. package/dist/plugins/kubeconfig/types.d.ts +17 -23
  126. package/dist/plugins/kubeconfig/types.js +1 -0
  127. package/dist/plugins/kubeconfig/types.js.map +1 -0
  128. package/dist/plugins/login.d.ts +1 -1
  129. package/dist/plugins/login.js +1 -0
  130. package/dist/plugins/login.js.map +1 -0
  131. package/dist/plugins/oidc/login.js +1 -0
  132. package/dist/plugins/oidc/login.js.map +1 -0
  133. package/dist/plugins/okta/aws.js +1 -0
  134. package/dist/plugins/okta/aws.js.map +1 -0
  135. package/dist/plugins/okta/login.js +1 -0
  136. package/dist/plugins/okta/login.js.map +1 -0
  137. package/dist/plugins/ping/login.js +1 -0
  138. package/dist/plugins/ping/login.js.map +1 -0
  139. package/dist/plugins/ssh/index.d.ts +8 -2
  140. package/dist/plugins/ssh/index.js +43 -35
  141. package/dist/plugins/ssh/index.js.map +1 -0
  142. package/dist/plugins/ssh/types.d.ts +3 -3
  143. package/dist/plugins/ssh/types.js +1 -0
  144. package/dist/plugins/ssh/types.js.map +1 -0
  145. package/dist/testing/firestore.js +1 -0
  146. package/dist/testing/firestore.js.map +1 -0
  147. package/dist/testing/yargs.js +1 -0
  148. package/dist/testing/yargs.js.map +1 -0
  149. package/dist/types/allow.d.ts +1 -1
  150. package/dist/types/allow.js +1 -0
  151. package/dist/types/allow.js.map +1 -0
  152. package/dist/types/aws/oidc.d.ts +3 -3
  153. package/dist/types/aws/oidc.js +1 -0
  154. package/dist/types/aws/oidc.js.map +1 -0
  155. package/dist/types/identity.d.ts +2 -2
  156. package/dist/types/identity.js +1 -0
  157. package/dist/types/identity.js.map +1 -0
  158. package/dist/types/index.js +1 -0
  159. package/dist/types/index.js.map +1 -0
  160. package/dist/types/oidc.d.ts +5 -5
  161. package/dist/types/oidc.js +1 -0
  162. package/dist/types/oidc.js.map +1 -0
  163. package/dist/types/org.d.ts +3 -3
  164. package/dist/types/org.js +1 -0
  165. package/dist/types/org.js.map +1 -0
  166. package/dist/types/request.d.ts +4 -4
  167. package/dist/types/request.js +1 -0
  168. package/dist/types/request.js.map +1 -0
  169. package/dist/types/ssh.d.ts +7 -6
  170. package/dist/types/ssh.js +1 -0
  171. package/dist/types/ssh.js.map +1 -0
  172. package/dist/util.d.ts +0 -10
  173. package/dist/util.js +3 -1
  174. package/dist/util.js.map +1 -0
  175. package/package.json +5 -1
  176. package/dist/plugins/ssh-agent/index.d.ts +0 -4
  177. package/dist/plugins/ssh-agent/index.js +0 -102
  178. package/dist/plugins/ssh-agent/types.d.ts +0 -13
  179. package/dist/plugins/ssh-agent/types.js +0 -2
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/types/identity.ts"],"names":[],"mappings":""}
@@ -13,3 +13,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.isa = void 0;
14
14
  const isa = (values) => (item) => values.includes(item);
15
15
  exports.isa = isa;
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEI,MAAM,GAAG,GACd,CAAI,MAAoB,EAAE,EAAE,CAC5B,CAAC,IAAS,EAAa,EAAE,CACvB,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAHb,QAAA,GAAG,OAGU"}
@@ -9,7 +9,7 @@ This file is part of @p0security/cli
9
9
 
10
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
11
  **/
12
- export declare type AuthorizeRequest = {
12
+ export type AuthorizeRequest = {
13
13
  client_id: string;
14
14
  code_challenge: string;
15
15
  code_challenge_method: "plain" | "S256";
@@ -19,7 +19,7 @@ export declare type AuthorizeRequest = {
19
19
  state?: string;
20
20
  login_hint?: string;
21
21
  };
22
- export declare type AuthorizeResponse = {
22
+ export type AuthorizeResponse = {
23
23
  device_code: string;
24
24
  user_code: string;
25
25
  verification_uri: string;
@@ -27,7 +27,7 @@ export declare type AuthorizeResponse = {
27
27
  expires_in: number;
28
28
  interval: number;
29
29
  };
30
- export declare type TokenResponse = {
30
+ export type TokenResponse = {
31
31
  access_token: string;
32
32
  id_token: string;
33
33
  token_type: string;
@@ -37,10 +37,10 @@ export declare type TokenResponse = {
37
37
  device_secret: string;
38
38
  expiry: string;
39
39
  };
40
- export declare type TokenErrorResponse = {
40
+ export type TokenErrorResponse = {
41
41
  error: "access_denied" | "authorization_pending" | "bad grant type" | "expired_token" | "missing parameter" | "not found" | "slow_down";
42
42
  };
43
- export declare type OidcLoginSteps<A> = {
43
+ export type OidcLoginSteps<A> = {
44
44
  providerType: LoginPluginType;
45
45
  validateResponse: (response: Response) => Promise<Response>;
46
46
  buildAuthorizeRequest: () => {
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=oidc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oidc.js","sourceRoot":"","sources":["../../src/types/oidc.ts"],"names":[],"mappings":""}
@@ -8,7 +8,7 @@ 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
- declare type BaseOrgData = {
11
+ type BaseOrgData = {
12
12
  clientId: string;
13
13
  providerId: string;
14
14
  providerDomain?: string;
@@ -16,13 +16,13 @@ declare type BaseOrgData = {
16
16
  tenantId: string;
17
17
  };
18
18
  /** Publicly readable organization data */
19
- export declare type RawOrgData = BaseOrgData & ({
19
+ export type RawOrgData = BaseOrgData & ({
20
20
  providerType?: "okta";
21
21
  } | {
22
22
  providerType?: "ping";
23
23
  environmentId: string;
24
24
  });
25
- export declare type OrgData = RawOrgData & {
25
+ export type OrgData = RawOrgData & {
26
26
  slug: string;
27
27
  };
28
28
  export {};
package/dist/types/org.js CHANGED
@@ -10,3 +10,4 @@ This file is part of @p0security/cli
10
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
11
  **/
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
+ //# sourceMappingURL=org.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org.js","sourceRoot":"","sources":["../../src/types/org.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG"}
@@ -13,19 +13,19 @@ import { PluginSshRequest } 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
- export declare type PermissionSpec<K extends string, P extends {
16
+ export type PermissionSpec<K extends string, P extends {
17
17
  type: string;
18
18
  }, G extends object | undefined = undefined> = {
19
19
  type: K;
20
20
  permission: P;
21
21
  generated: G;
22
22
  };
23
- export declare type PluginRequest = K8sPermissionSpec | PluginSshRequest;
24
- export declare type Request<P extends PluginRequest> = P & {
23
+ export type PluginRequest = K8sPermissionSpec | PluginSshRequest;
24
+ export type Request<P extends PluginRequest> = P & {
25
25
  status: string;
26
26
  principal: string;
27
27
  };
28
- export declare type RequestResponse<T> = {
28
+ export type RequestResponse<T> = {
29
29
  ok: true;
30
30
  message: string;
31
31
  id: string;
@@ -8,3 +8,4 @@ exports.ERROR_STATUSES = [
8
8
  "ERRORED",
9
9
  "ERRORED_NOTIFIED",
10
10
  ];
11
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/types/request.ts"],"names":[],"mappings":";;;AAaa,QAAA,aAAa,GAAG,CAAC,MAAM,EAAE,eAAe,CAAU,CAAC;AACnD,QAAA,eAAe,GAAG,CAAC,QAAQ,EAAE,iBAAiB,CAAU,CAAC;AACzD,QAAA,cAAc,GAAG;IAC5B,SAAS;IACT,SAAS;IACT,kBAAkB;CACV,CAAC"}
@@ -13,19 +13,20 @@ import { AwsSsh, AwsSshPermissionSpec, AwsSshRequest } from "../plugins/aws/type
13
13
  import { GcpSsh, GcpSshPermissionSpec, GcpSshRequest } from "../plugins/google/types";
14
14
  import { Authn } from "./identity";
15
15
  import { Request } from "./request";
16
- export declare type CliSshRequest = AwsSsh | GcpSsh;
17
- export declare type PluginSshRequest = AwsSshPermissionSpec | GcpSshPermissionSpec;
18
- export declare type CliPermissionSpec<P extends PluginSshRequest, C extends object | undefined> = P & {
16
+ export type CliSshRequest = AwsSsh | GcpSsh;
17
+ export type PluginSshRequest = AwsSshPermissionSpec | GcpSshPermissionSpec;
18
+ export type CliPermissionSpec<P extends PluginSshRequest, C extends object | undefined> = P & {
19
19
  cliLocalData: C;
20
20
  };
21
21
  export declare const SupportedSshProviders: readonly ["aws", "gcloud"];
22
- export declare type SupportedSshProvider = (typeof SupportedSshProviders)[number];
23
- export declare type SshProvider<PR extends PluginSshRequest = PluginSshRequest, O extends object | undefined = undefined, SR extends SshRequest = SshRequest, C extends object | undefined = undefined> = {
22
+ export type SupportedSshProvider = (typeof SupportedSshProviders)[number];
23
+ export type SshProvider<PR extends PluginSshRequest = PluginSshRequest, O extends object | undefined = undefined, SR extends SshRequest = SshRequest, C extends object | undefined = undefined> = {
24
24
  requestToSsh: (request: CliPermissionSpec<PR, O>) => SR;
25
25
  /** Converts a backend request to a CLI request */
26
26
  toCliRequest: (request: Request<PR>, options?: {
27
27
  debug?: boolean;
28
28
  }) => Promise<Request<CliSshRequest>>;
29
+ ensureInstall: () => Promise<void>;
29
30
  /** Logs in the user to the cloud provider */
30
31
  cloudProviderLogin: (authn: Authn, request: SR) => Promise<C>;
31
32
  /** Returns the command and its arguments that are going to be injected as the ssh ProxyCommand option */
@@ -44,4 +45,4 @@ export declare type SshProvider<PR extends PluginSshRequest = PluginSshRequest,
44
45
  maxRetries: number;
45
46
  friendlyName: string;
46
47
  };
47
- export declare type SshRequest = AwsSshRequest | GcpSshRequest;
48
+ export type SshRequest = AwsSshRequest | GcpSshRequest;
package/dist/types/ssh.js CHANGED
@@ -3,3 +3,4 @@ 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
5
  exports.SupportedSshProviders = ["aws", "gcloud"];
6
+ //# sourceMappingURL=ssh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssh.js","sourceRoot":"","sources":["../../src/types/ssh.ts"],"names":[],"mappings":";;;AAkCA,kEAAkE;AACrD,QAAA,qBAAqB,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAC"}
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)
package/dist/util.js CHANGED
@@ -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,4 @@ exports.unexpectedValueError = unexpectedValueError;
107
108
  */
108
109
  const ciEquals = (a, b) => a.localeCompare(b, undefined, { sensitivity: "accent" }) === 0;
109
110
  exports.ciEquals = ciEquals;
111
+ //# 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;;;;;;;;GAQG;AACI,MAAM,KAAK,GAAG,CAAC,aAAqB,EAAE,EAAE;IAC7C,IAAI,KAAK,GAA+B,SAAS,CAAC;IAClD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAC5C,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CA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+1,6 @@
1
1
  {
2
2
  "name": "@p0security/cli",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
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 });