@p0security/cli 0.26.14 → 0.27.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 (49) hide show
  1. package/build/dist/commands/aws/rds.js +7 -5
  2. package/build/dist/commands/aws/rds.js.map +1 -1
  3. package/build/dist/commands/claude/index.d.ts +2 -0
  4. package/build/dist/commands/claude/index.js +24 -0
  5. package/build/dist/commands/claude/index.js.map +1 -0
  6. package/build/dist/commands/claude/mcp.d.ts +7 -0
  7. package/build/dist/commands/claude/mcp.js +187 -0
  8. package/build/dist/commands/claude/mcp.js.map +1 -0
  9. package/build/dist/commands/file-transfer.d.ts +8 -0
  10. package/build/dist/commands/file-transfer.js +130 -0
  11. package/build/dist/commands/file-transfer.js.map +1 -0
  12. package/build/dist/commands/index.js +4 -0
  13. package/build/dist/commands/index.js.map +1 -1
  14. package/build/dist/commands/kubeconfig.js +2 -1
  15. package/build/dist/commands/kubeconfig.js.map +1 -1
  16. package/build/dist/drivers/api.d.ts +8 -0
  17. package/build/dist/drivers/api.js +20 -18
  18. package/build/dist/drivers/api.js.map +1 -1
  19. package/build/dist/drivers/auth/path.d.ts +1 -0
  20. package/build/dist/drivers/auth/path.js +12 -10
  21. package/build/dist/drivers/auth/path.js.map +1 -1
  22. package/build/dist/drivers/stdio.d.ts +8 -0
  23. package/build/dist/drivers/stdio.js +12 -1
  24. package/build/dist/drivers/stdio.js.map +1 -1
  25. package/build/dist/plugins/aws/api.d.ts +6 -1
  26. package/build/dist/plugins/aws/api.js +16 -2
  27. package/build/dist/plugins/aws/api.js.map +1 -1
  28. package/build/dist/plugins/aws/assumeRole.d.ts +2 -0
  29. package/build/dist/plugins/aws/assumeRole.js +8 -6
  30. package/build/dist/plugins/aws/assumeRole.js.map +1 -1
  31. package/build/dist/plugins/aws/ssh.js +8 -3
  32. package/build/dist/plugins/aws/ssh.js.map +1 -1
  33. package/build/dist/plugins/db/types.d.ts +13 -10
  34. package/build/dist/plugins/file-transfer/index.d.ts +35 -0
  35. package/build/dist/plugins/file-transfer/index.js +74 -0
  36. package/build/dist/plugins/file-transfer/index.js.map +1 -0
  37. package/build/dist/plugins/file-transfer/types.d.ts +31 -0
  38. package/build/dist/plugins/file-transfer/types.js +3 -0
  39. package/build/dist/plugins/file-transfer/types.js.map +1 -0
  40. package/build/dist/plugins/kubeconfig/types.d.ts +3 -5
  41. package/build/dist/plugins/okta/aws.js +13 -6
  42. package/build/dist/plugins/okta/aws.js.map +1 -1
  43. package/build/dist/types/delegation.d.ts +39 -0
  44. package/build/dist/types/delegation.js +36 -0
  45. package/build/dist/types/delegation.js.map +1 -0
  46. package/build/dist/types/request.d.ts +5 -3
  47. package/build/dist/types/request.js.map +1 -1
  48. package/build/tsconfig.build.tsbuildinfo +1 -1
  49. package/package.json +4 -1
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/plugins/file-transfer/types.ts"],"names":[],"mappings":""}
@@ -30,11 +30,9 @@ export type K8sClusterConfig = {
30
30
  export type K8sConfig = {
31
31
  "iam-write": Record<string, K8sClusterConfig>;
32
32
  };
33
- export type K8sPermissionSpec = PermissionSpec<"k8s", K8sResourcePermission, K8sGenerated> & {
34
- delegation?: {
35
- aws?: AwsResourcePermissionSpec;
36
- };
37
- };
33
+ export type K8sPermissionSpec = PermissionSpec<"k8s", K8sResourcePermission, K8sGenerated, {
34
+ aws?: AwsResourcePermissionSpec;
35
+ }>;
38
36
  export type K8sResourcePermission = {
39
37
  resource: {
40
38
  name: string;
@@ -34,9 +34,12 @@ const RETRY_ATTEMPTS = 14;
34
34
  const INITIAL_RETRY_DELAY_MS = 1000;
35
35
  const RETRY_MULTIPLIER = 2.0;
36
36
  const MAX_RETRY_DELAY_MS = 30000;
37
+ // Matches IAM role ARNs in known AWS partitions (commercial or GovCloud).
38
+ // Capture group 1: partition; capture group 2: account ID.
39
+ const ROLE_ARN_PATTERN = /^arn:(aws|aws-us-gov):iam::([^:]+):role\//;
37
40
  /** Extracts all roles from a SAML assertion */
38
41
  const rolesFromSaml = (account, saml) => {
39
- var _a;
42
+ var _a, _b, _c;
40
43
  const samlText = Buffer.from(saml, "base64").toString("ascii");
41
44
  const samlObject = (0, xml_1.parseXml)(samlText);
42
45
  const samlAttributes = samlObject["saml2p:Response"]["saml2:Assertion"]["saml2:AttributeStatement"]["saml2:Attribute"];
@@ -44,10 +47,13 @@ const rolesFromSaml = (account, saml) => {
44
47
  // Format:
45
48
  // 'arn:aws:iam::391052057035:saml-provider/p0dev-ext_okta_sso,arn:aws:iam::391052057035:role/path/to/role/SSOAmazonS3FullAccess'
46
49
  const arns = (_a = (0, lodash_1.flatten)([roleAttribute === null || roleAttribute === void 0 ? void 0 : roleAttribute["saml2:AttributeValue"]])) === null || _a === void 0 ? void 0 : _a.map((r) => r.split(",")[1]);
47
- const roles = arns
48
- .filter((r) => r.startsWith(`arn:aws:iam::${account}:role/`))
49
- .map((r) => r.split("/").slice(1).join("/"));
50
- return { arns, roles };
50
+ const matched = arns
51
+ .map((arn) => ({ arn, match: ROLE_ARN_PATTERN.exec(arn) }))
52
+ .filter((x) => x.match !== null && x.match[2] === account);
53
+ // Partition must flow to STS so we hit the right endpoint and emit ARNs in the matching partition.
54
+ const partition = (_c = (_b = matched[0]) === null || _b === void 0 ? void 0 : _b.match[1]) !== null && _c !== void 0 ? _c : "aws";
55
+ const roles = matched.map(({ arn }) => arn.split("/").slice(1).join("/"));
56
+ return { arns, roles, partition };
51
57
  };
52
58
  const isFederatedLogin = (config) => { var _a; return ((_a = config.login) === null || _a === void 0 ? void 0 : _a.type) === "federated"; };
53
59
  /** Retrieves the configured Okta SAML response for the specified account
@@ -74,12 +80,13 @@ const assumeRoleWithOktaSaml = (authn, args, debug) => __awaiter(void 0, void 0,
74
80
  // Add retry logic to handle this race condition.
75
81
  return yield (0, retry_1.retryWithSleep)(() => __awaiter(void 0, void 0, void 0, function* () {
76
82
  const { account, config, samlResponse } = yield initOktaSaml(authn, args.accountId, debug);
77
- const { roles } = rolesFromSaml(account, samlResponse);
83
+ const { roles, partition } = rolesFromSaml(account, samlResponse);
78
84
  if (!roles.includes(args.role)) {
79
85
  throw `Role ${args.role} not available. Available roles:\n${roles.map((r) => ` ${r}`).join("\n")}`;
80
86
  }
81
87
  return yield (0, assumeRole_1.assumeRoleWithSaml)({
82
88
  account,
89
+ partition,
83
90
  role: args.role,
84
91
  saml: {
85
92
  providerName: config.login.provider.identityProvider,
@@ -1 +1 @@
1
- {"version":3,"file":"aws.js","sourceRoot":"","sources":["../../../../src/plugins/okta/aws.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;GASG;AACH,8CAAoD;AACpD,0CAA4C;AAC5C,6CAA4C;AAE5C,kDAAuD;AACvD,0CAA6C;AAE7C,mCAAmD;AACnD,mCAAiC;AAEjC,6DAA6D;AAC7D,oFAAoF;AACpF,MAAM,0BAA0B,GAAG,0BAA0B,CAAC;AAC9D,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,sBAAsB,GAAG,IAAI,CAAC;AACpC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAEjC,+CAA+C;AAC/C,MAAM,aAAa,GAAG,CAAC,OAAe,EAAE,IAAY,EAAE,EAAE;;IACtD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC/D,MAAM,UAAU,GAAG,IAAA,cAAQ,EAAC,QAAQ,CAAC,CAAC;IACtC,MAAM,cAAc,GAClB,UAAU,CAAC,iBAAiB,CAAC,CAAC,iBAAiB,CAAC,CAC9C,0BAA0B,CAC3B,CAAC,iBAAiB,CAAC,CAAC;IACvB,MAAM,aAAa,GAAG,cA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AC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;aACrG;YACD,OAAO,MAAM,IAAA,+BAAkB,EAAC;gBAC9B,OAAO;gBACP,SAAS;gBACT,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,IAAI,EAAE;oBACJ,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,gBAAgB;oBACpD,QAAQ,EAAE,YAAY;iBACvB;aACF,CAAC,CAAC;QACL,CAAC,CAAA,EACD;YACE,WAAW,EAAE,CAAC,KAAc,EAAE,EAAE;gBAC9B,0EAA0E;gBAC1E,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;oBACzB,0BAA0B,CAAC,IAAI,CAAC,KAAK,CAAC,CACvC,CAAC;YACJ,CAAC;YACD,OAAO,EAAE,cAAc;YACvB,OAAO,EAAE,sBAAsB;YAC/B,UAAU,EAAE,gBAAgB;YAC5B,UAAU,EAAE,kBAAkB;YAC9B,KAAK;SACN,CACF,CAAC;IACJ,CAAC,CAAA,EACD,EAAE,QAAQ,EAAE,MAAM,EAAE,CACrB,CAAA;EAAA,CAAC;AAjDS,QAAA,sBAAsB,0BAiD/B"}
@@ -0,0 +1,39 @@
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
+ /** An entry in the new array-form delegation shape.
12
+ *
13
+ * The backend used to send delegation as a record (`{ aws: { ... } }`); it now
14
+ * sends it as an array of `{ key, request }` entries. The `request` field holds
15
+ * what used to be the record's value (permission, generated, nested delegation).
16
+ */
17
+ export type DelegationEntry<K extends string, R> = {
18
+ key: K;
19
+ request: R;
20
+ };
21
+ /** Delegation field that tolerates both the legacy record form and the new
22
+ * array form. Callers should not read this directly — use {@link getDelegate}.
23
+ */
24
+ export type DelegationField<Spec extends Record<string, any>> = {
25
+ [K in keyof Spec & string]: DelegationEntry<K, Spec[K]>;
26
+ }[keyof Spec & string][] | Spec;
27
+ /** Resolve a delegate by key, accepting either the legacy record-form
28
+ * delegation or the new array-form delegation.
29
+ *
30
+ * Returns the underlying delegate value (with `permission`, `generated`,
31
+ * and nested `delegation` fields), or `undefined` if no entry matches.
32
+ *
33
+ * The generic shape (`K`, `V` rather than the full `Spec` record) is
34
+ * deliberate: matching the union `DelegationField<Spec>` bidirectionally
35
+ * confuses TS's inference and can lock `Spec` onto the array branch.
36
+ * Pinning `K` to the key argument and inferring `V` from the value avoids
37
+ * that.
38
+ */
39
+ export declare const getDelegate: <K extends string, V>(delegation: { [P in K]?: V | undefined; } | DelegationEntry<K, V>[] | null | undefined, key: K) => V | undefined;
@@ -0,0 +1,36 @@
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
+ **/
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.getDelegate = void 0;
14
+ /** Resolve a delegate by key, accepting either the legacy record-form
15
+ * delegation or the new array-form delegation.
16
+ *
17
+ * Returns the underlying delegate value (with `permission`, `generated`,
18
+ * and nested `delegation` fields), or `undefined` if no entry matches.
19
+ *
20
+ * The generic shape (`K`, `V` rather than the full `Spec` record) is
21
+ * deliberate: matching the union `DelegationField<Spec>` bidirectionally
22
+ * confuses TS's inference and can lock `Spec` onto the array branch.
23
+ * Pinning `K` to the key argument and inferring `V` from the value avoids
24
+ * that.
25
+ */
26
+ const getDelegate = (delegation, key) => {
27
+ if (delegation == null)
28
+ return undefined;
29
+ if (Array.isArray(delegation)) {
30
+ const entry = delegation.find((e) => (e === null || e === void 0 ? void 0 : e.key) === key);
31
+ return entry === null || entry === void 0 ? void 0 : entry.request;
32
+ }
33
+ return delegation[key];
34
+ };
35
+ exports.getDelegate = getDelegate;
36
+ //# sourceMappingURL=delegation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegation.js","sourceRoot":"","sources":["../../../src/types/delegation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAsBH;;;;;;;;;;;GAWG;AACI,MAAM,WAAW,GAAG,CACzB,UAAyE,EACzE,GAAM,EACS,EAAE;IACjB,IAAI,UAAU,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC;IACzC,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;QAC7B,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,GAAG,MAAK,GAAG,CAAC,CAAC;QACrD,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,CAAC;KACvB;IACD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC,CAAC;AAVW,QAAA,WAAW,eAUtB"}
@@ -9,19 +9,21 @@ 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 { DbPermissionSpec } from "../plugins/db/types";
12
+ import { FileTransferPermissionSpec } from "../plugins/file-transfer/types";
12
13
  import { K8sPermissionSpec } from "../plugins/kubeconfig/types";
14
+ import { DelegationField } from "./delegation";
13
15
  import { AzureRdpRequest } from "./rdp";
14
16
  import { PluginSshRequest } from "./ssh";
15
17
  export declare const DONE_STATUSES: readonly ["DONE", "DONE_NOTIFIED"];
16
18
  export declare const DENIED_STATUSES: readonly ["DENIED", "DENIED_NOTIFIED"];
17
19
  export declare const ERROR_STATUSES: readonly ["ERRORED", "ERRORED", "ERRORED_NOTIFIED"];
18
- export type PermissionSpec<K extends string, P extends Record<string, any>, G extends object | undefined = undefined, D extends Record<string, PermissionSpec<any, any, any, any>> = Record<string, never>> = {
20
+ export type PermissionSpec<K extends string, P extends Record<string, any>, G extends object | undefined = undefined, D extends Record<string, PermissionSpec<any, any, any, any> | undefined> = Record<string, never>> = {
19
21
  type: K;
20
22
  permission: P;
21
23
  generated: G;
22
- delegation: D;
24
+ delegation?: DelegationField<D>;
23
25
  };
24
- export type PluginRequest = AzureRdpRequest | DbPermissionSpec | K8sPermissionSpec | PluginSshRequest;
26
+ export type PluginRequest = AzureRdpRequest | DbPermissionSpec | FileTransferPermissionSpec | K8sPermissionSpec | PluginSshRequest;
25
27
  export type PermissionRequest<P extends PluginRequest> = P & {
26
28
  error?: {
27
29
  message: string;
@@ -1 +1 @@
1
- {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/types/request.ts"],"names":[],"mappings":";;;AAea,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"}
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/types/request.ts"],"names":[],"mappings":";;;AAiBa,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"}