@p0security/cli 0.8.3 → 0.10.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.
@@ -0,0 +1,120 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ensureInstall = exports.guidedInstall = exports.AwsInstall = exports.AwsItems = exports.SupportedPlatforms = void 0;
16
+ /** Copyright © 2024-present P0 Security
17
+
18
+ This file is part of @p0security/cli
19
+
20
+ @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.
21
+
22
+ @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.
23
+
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
+ **/
26
+ const stdio_1 = require("../drivers/stdio");
27
+ const types_1 = require("../types");
28
+ const lodash_1 = require("lodash");
29
+ const node_child_process_1 = require("node:child_process");
30
+ const node_os_1 = __importDefault(require("node:os"));
31
+ const typescript_1 = require("typescript");
32
+ const which_1 = __importDefault(require("which"));
33
+ exports.SupportedPlatforms = ["darwin"];
34
+ exports.AwsItems = ["aws"];
35
+ exports.AwsInstall = {
36
+ aws: {
37
+ label: "AWS CLI v2",
38
+ commands: {
39
+ darwin: [
40
+ 'curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"',
41
+ "sudo installer -pkg AWSCLIV2.pkg -target /",
42
+ 'rm "AWSCLIV2.pkg"',
43
+ ],
44
+ },
45
+ },
46
+ };
47
+ const printToInstall = (toInstall, installMetadata) => {
48
+ (0, stdio_1.print2)("The following items must be installed on your system to continue:");
49
+ for (const item of toInstall) {
50
+ (0, stdio_1.print2)(` - ${installMetadata[item].label} (${item})`);
51
+ }
52
+ (0, stdio_1.print2)("");
53
+ };
54
+ const queryInteractive = () => __awaiter(void 0, void 0, void 0, function* () {
55
+ const inquirer = (yield import("inquirer")).default;
56
+ const { isGuided } = yield inquirer.prompt([
57
+ {
58
+ type: "confirm",
59
+ name: "isGuided",
60
+ message: "Do you want P0 to install these for you (sudo access required)?",
61
+ },
62
+ ]);
63
+ (0, stdio_1.print2)("");
64
+ return isGuided;
65
+ });
66
+ const requiredInstalls = (installItems) => __awaiter(void 0, void 0, void 0, function* () {
67
+ return (0, lodash_1.compact)(yield Promise.all(installItems.map((item) => __awaiter(void 0, void 0, void 0, function* () { return (yield (0, which_1.default)(item, { nothrow: true })) === null ? item : undefined; }))));
68
+ });
69
+ const printInstallCommands = (platform, item, installData) => {
70
+ const { label, commands } = installData[item];
71
+ (0, stdio_1.print2)(`To install ${label}, run the following commands:\n`);
72
+ for (const command of commands[platform]) {
73
+ (0, stdio_1.print1)(` ${command}`);
74
+ }
75
+ (0, stdio_1.print1)(""); // Newline is useful for reading command output in a script, so send to /fd/1
76
+ };
77
+ const guidedInstall = (platform, item, installData) => __awaiter(void 0, void 0, void 0, function* () {
78
+ const commands = installData[item].commands[platform];
79
+ const combined = commands.join(" && \\\n");
80
+ (0, stdio_1.print2)(`Executing:\n${combined}`);
81
+ (0, stdio_1.print2)("");
82
+ yield new Promise((resolve, reject) => {
83
+ const child = (0, node_child_process_1.spawn)("bash", ["-c", combined], { stdio: "inherit" });
84
+ child.on("exit", (code) => {
85
+ if (code === 0)
86
+ resolve();
87
+ else
88
+ reject(`Shell exited with code ${code}`);
89
+ });
90
+ });
91
+ (0, stdio_1.print2)("");
92
+ });
93
+ exports.guidedInstall = guidedInstall;
94
+ const ensureInstall = (installItems, installData) => __awaiter(void 0, void 0, void 0, function* () {
95
+ var _a;
96
+ const toInstall = yield requiredInstalls(installItems);
97
+ if (toInstall.length === 0) {
98
+ return true;
99
+ }
100
+ const platform = node_os_1.default.platform();
101
+ printToInstall(toInstall, installData);
102
+ if (!(0, types_1.isa)(exports.SupportedPlatforms)(platform)) {
103
+ throw (`Guided dependency installation is not available on platform ${platform}\n` +
104
+ "Please install the above dependencies manually, or ensure they are on your PATH.");
105
+ }
106
+ const interactive = !!((_a = typescript_1.sys.writeOutputIsTTY) === null || _a === void 0 ? void 0 : _a.call(typescript_1.sys)) && (yield queryInteractive());
107
+ for (const item of toInstall) {
108
+ if (interactive)
109
+ yield (0, exports.guidedInstall)(platform, item, installData);
110
+ else
111
+ printInstallCommands(platform, item, installData);
112
+ }
113
+ const remaining = yield requiredInstalls(installItems);
114
+ if (remaining.length === 0) {
115
+ (0, stdio_1.print2)("All packages successfully installed");
116
+ return true;
117
+ }
118
+ return false;
119
+ });
120
+ exports.ensureInstall = ensureInstall;
@@ -22,4 +22,5 @@ export declare function print2(message: any): void;
22
22
  export declare const Ansi: {
23
23
  readonly Reset: string;
24
24
  readonly Dim: string;
25
+ readonly Yellow: string;
25
26
  };
@@ -40,5 +40,6 @@ exports.print2 = print2;
40
40
  const AnsiCodes = {
41
41
  Reset: "00",
42
42
  Dim: "02",
43
+ Yellow: "33",
43
44
  };
44
45
  exports.Ansi = (0, lodash_1.mapValues)(AnsiCodes, (v) => `\u001b[${v}m`);
@@ -33,11 +33,13 @@ exports.awsSshProvider = {
33
33
  ? Object.assign(Object.assign({}, common), { role: name, type: "aws", access: "role" }) : Object.assign(Object.assign({}, common), { idc, permissionSet: name, type: "aws", access: "idc" });
34
34
  },
35
35
  toCliRequest: (request) => __awaiter(void 0, void 0, void 0, function* () { return (Object.assign(Object.assign({}, request), { cliLocalData: undefined })); }),
36
- cloudProviderLogin: (authn, request) => __awaiter(void 0, void 0, void 0, function* () {
37
- var _a, _b, _c, _d;
36
+ ensureInstall: () => __awaiter(void 0, void 0, void 0, function* () {
38
37
  if (!(yield (0, install_1.ensureSsmInstall)())) {
39
38
  throw "Please try again after installing the required AWS utilities";
40
39
  }
40
+ }),
41
+ cloudProviderLogin: (authn, request) => __awaiter(void 0, void 0, void 0, function* () {
42
+ var _a, _b, _c, _d;
41
43
  const { config } = yield (0, config_1.getAwsConfig)(authn, request.accountId);
42
44
  if (!((_a = config.login) === null || _a === void 0 ? void 0 : _a.type) || ((_b = config.login) === null || _b === void 0 ? void 0 : _b.type) === "iam") {
43
45
  throw "This account is not configured for SSH access via the P0 CLI";
@@ -1,16 +1,4 @@
1
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
3
  exports.ensureSsmInstall = void 0;
16
4
  /** Copyright © 2024-present P0 Security
@@ -23,27 +11,9 @@ This file is part of @p0security/cli
23
11
 
24
12
  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
13
  **/
26
- const stdio_1 = require("../../../drivers/stdio");
27
- const types_1 = require("../../../types");
28
- const lodash_1 = require("lodash");
29
- const node_child_process_1 = require("node:child_process");
30
- const node_os_1 = __importDefault(require("node:os"));
31
- const typescript_1 = require("typescript");
32
- const which_1 = __importDefault(require("which"));
33
- const SupportedPlatforms = ["darwin"];
34
- const AwsItems = ["aws", "session-manager-plugin"];
35
- const AwsInstall = {
36
- aws: {
37
- label: "AWS CLI v2",
38
- commands: {
39
- darwin: [
40
- 'curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"',
41
- "sudo installer -pkg AWSCLIV2.pkg -target /",
42
- 'rm "AWSCLIV2.pkg"',
43
- ],
44
- },
45
- },
46
- "session-manager-plugin": {
14
+ const install_1 = require("../../../common/install");
15
+ const SsmItems = [...install_1.AwsItems, "session-manager-plugin"];
16
+ const SsmInstall = Object.assign(Object.assign({}, install_1.AwsInstall), { "session-manager-plugin": {
47
17
  label: "the AWS CLI Session Manager plugin",
48
18
  commands: {
49
19
  darwin: [
@@ -53,81 +23,12 @@ const AwsInstall = {
53
23
  'rm "session-manager-plugin.pkg"',
54
24
  ],
55
25
  },
56
- },
57
- };
58
- const printToInstall = (toInstall) => {
59
- (0, stdio_1.print2)("The following items must be installed on your system to continue:");
60
- for (const item of toInstall) {
61
- (0, stdio_1.print2)(` - ${AwsInstall[item].label}`);
62
- }
63
- (0, stdio_1.print2)("");
64
- };
65
- const queryInteractive = () => __awaiter(void 0, void 0, void 0, function* () {
66
- const inquirer = (yield import("inquirer")).default;
67
- const { isGuided } = yield inquirer.prompt([
68
- {
69
- type: "confirm",
70
- name: "isGuided",
71
- message: "Do you want P0 to install these for you (sudo access required)?",
72
- },
73
- ]);
74
- (0, stdio_1.print2)("");
75
- return isGuided;
76
- });
77
- const requiredInstalls = () => __awaiter(void 0, void 0, void 0, function* () {
78
- return (0, lodash_1.compact)(yield Promise.all(AwsItems.map((item) => __awaiter(void 0, void 0, void 0, function* () { return (yield (0, which_1.default)(item, { nothrow: true })) === null ? item : undefined; }))));
79
- });
80
- const printInstallCommands = (platform, item) => {
81
- const { label, commands } = AwsInstall[item];
82
- (0, stdio_1.print2)(`To install ${label}, run the following commands:\n`);
83
- for (const command of commands[platform]) {
84
- (0, stdio_1.print1)(` ${command}`);
85
- }
86
- (0, stdio_1.print1)(""); // Newline is useful for reading command output in a script, so send to /fd/1
87
- };
88
- const guidedInstall = (platform, item) => __awaiter(void 0, void 0, void 0, function* () {
89
- const commands = AwsInstall[item].commands[platform];
90
- const combined = commands.join(" && \\\n");
91
- (0, stdio_1.print2)(`Executing:\n${combined}`);
92
- (0, stdio_1.print2)("");
93
- yield new Promise((resolve, reject) => {
94
- const child = (0, node_child_process_1.spawn)("bash", ["-c", combined], { stdio: "inherit" });
95
- child.on("exit", (code) => {
96
- if (code === 0)
97
- resolve();
98
- else
99
- reject(`Shell exited with code ${code}`);
100
- });
101
- });
102
- (0, stdio_1.print2)("");
103
- });
26
+ } });
104
27
  /** Ensures that AWS CLI and SSM plugin are installed on the user environment
105
28
  *
106
29
  * If they are not, and the session is a TTY, prompt the user to auto-install. If
107
30
  * the user declines, or if not a TTY, the installation commands are printed to
108
31
  * stdout.
109
32
  */
110
- const ensureSsmInstall = () => __awaiter(void 0, void 0, void 0, function* () {
111
- var _a;
112
- const platform = node_os_1.default.platform();
113
- if (!(0, types_1.isa)(SupportedPlatforms)(platform))
114
- throw "SSH to AWS managed instances is only available on MacOS";
115
- const toInstall = yield requiredInstalls();
116
- if (toInstall.length === 0)
117
- return true;
118
- printToInstall(toInstall);
119
- const interactive = !!((_a = typescript_1.sys.writeOutputIsTTY) === null || _a === void 0 ? void 0 : _a.call(typescript_1.sys)) && (yield queryInteractive());
120
- for (const item of toInstall) {
121
- if (interactive)
122
- yield guidedInstall(platform, item);
123
- else
124
- printInstallCommands(platform, item);
125
- }
126
- const remaining = yield requiredInstalls();
127
- if (remaining.length === 0) {
128
- (0, stdio_1.print2)("All packages successfully installed");
129
- return true;
130
- }
131
- return false;
132
- });
33
+ const ensureSsmInstall = () => (0, install_1.ensureInstall)(SsmItems, SsmInstall);
133
34
  exports.ensureSsmInstall = ensureSsmInstall;
@@ -0,0 +1,2 @@
1
+ export declare const SupportedPlatforms: readonly ["darwin"];
2
+ export declare const ensureGcpSshInstall: () => Promise<boolean>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureGcpSshInstall = exports.SupportedPlatforms = void 0;
4
+ /** Copyright © 2024-present P0 Security
5
+
6
+ This file is part of @p0security/cli
7
+
8
+ @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.
9
+
10
+ @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.
11
+
12
+ You should have received a copy of the GNU General Public License along with @p0security/cli. If not, see <https://www.gnu.org/licenses/>.
13
+ **/
14
+ const install_1 = require("../../common/install");
15
+ exports.SupportedPlatforms = ["darwin"];
16
+ const GcpSshItems = ["gcloud"];
17
+ const GcpSshInstall = {
18
+ gcloud: {
19
+ label: "GCloud CLI",
20
+ commands: {
21
+ darwin: [
22
+ // See https://cloud.google.com/sdk/docs/install-sdk
23
+ "architecture=$(arch)",
24
+ 'package=$([ $architecture = "arm64" ] && echo "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-darwin-arm.tar.gz" || "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-darwin-x86_64.tar.gz" )',
25
+ "wget -O ~/google-cloud-cli.tar.gz $package",
26
+ "tar -xzf ~/google-cloud-cli.tar.gz -C ~",
27
+ "~/google-cloud-sdk/install.sh",
28
+ "rm -rf ~/google-cloud-cli.tar.gz",
29
+ // Symlink gcloud to /usr/local/bin - assumes /usr/local/bin is already in $PATH so next time `gcloud` is run it will be found
30
+ "sudo mkdir -p /usr/local/bin",
31
+ "sudo ln -s ~/google-cloud-sdk/bin/gcloud /usr/local/bin/gcloud",
32
+ "sudo chown root: /usr/local/bin/gcloud",
33
+ ],
34
+ },
35
+ },
36
+ };
37
+ const ensureGcpSshInstall = () => (0, install_1.ensureInstall)(GcpSshItems, GcpSshInstall);
38
+ exports.ensureGcpSshInstall = ensureGcpSshInstall;
@@ -21,6 +21,7 @@ This file is part of @p0security/cli
21
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
22
  **/
23
23
  const ssh_1 = require("../../commands/shared/ssh");
24
+ const install_1 = require("./install");
24
25
  const ssh_key_1 = require("./ssh-key");
25
26
  /** Maximum number of attempts to start an SSH session
26
27
  *
@@ -42,6 +43,11 @@ exports.gcpSshProvider = {
42
43
  linuxUserName: yield (0, ssh_key_1.importSshKey)(request.permission.spec.publicKey, options),
43
44
  } }));
44
45
  }),
46
+ ensureInstall: () => __awaiter(void 0, void 0, void 0, function* () {
47
+ if (!(yield (0, install_1.ensureGcpSshInstall)())) {
48
+ throw "Please try again after installing the required GCP utilities";
49
+ }
50
+ }),
45
51
  cloudProviderLogin: () => __awaiter(void 0, void 0, void 0, function* () { return undefined; }),
46
52
  proxyCommand: (request) => {
47
53
  return [
@@ -0,0 +1,27 @@
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 { KubeconfigCommandArgs } from "../../commands/kubeconfig";
12
+ import { Authn } from "../../types/identity";
13
+ import { Request } from "../../types/request";
14
+ import { AwsCredentials } from "../aws/types";
15
+ import { K8sGenerated, K8sPermissionSpec } from "./types";
16
+ import yargs from "yargs";
17
+ export declare const getAndValidateK8sIntegration: (authn: Authn, clusterId: string) => Promise<{
18
+ clusterConfig: {
19
+ clusterId: string;
20
+ awsAccountId: string;
21
+ awsClusterArn: string;
22
+ };
23
+ awsLoginType: "federated" | "idc";
24
+ }>;
25
+ export declare const requestAccessToCluster: (authn: Authn, args: yargs.ArgumentsCamelCase<KubeconfigCommandArgs>, clusterId: string, role: string) => Promise<Request<K8sPermissionSpec>>;
26
+ export declare const profileName: (eksCluterName: string) => string;
27
+ export declare const awsCloudAuth: (authn: Authn, awsAccountId: string, generated: K8sGenerated, loginType: "federated" | "idc") => Promise<AwsCredentials>;
@@ -0,0 +1,104 @@
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.awsCloudAuth = exports.profileName = exports.requestAccessToCluster = exports.getAndValidateK8sIntegration = void 0;
13
+ const shared_1 = require("../../commands/shared");
14
+ const request_1 = require("../../commands/shared/request");
15
+ const firestore_1 = require("../../drivers/firestore");
16
+ const stdio_1 = require("../../drivers/stdio");
17
+ const util_1 = require("../../util");
18
+ const config_1 = require("../aws/config");
19
+ const idc_1 = require("../aws/idc");
20
+ const aws_1 = require("../okta/aws");
21
+ const firestore_2 = require("firebase/firestore");
22
+ const lodash_1 = require("lodash");
23
+ const getAndValidateK8sIntegration = (authn, clusterId) => __awaiter(void 0, void 0, void 0, function* () {
24
+ var _a, _b;
25
+ const configDoc = yield (0, firestore_2.getDoc)((0, firestore_1.doc)(`o/${authn.identity.org.tenantId}/integrations/k8s`));
26
+ // Validation done here in lieu of the backend, since the backend doesn't validate until approval. TODO: ENG-2365.
27
+ const config = (_b = (_a = configDoc.data()) === null || _a === void 0 ? void 0 : _a["iam-write"]) === null || _b === void 0 ? void 0 : _b[clusterId];
28
+ if (!config) {
29
+ throw `Cluster with ID ${clusterId} not found`;
30
+ }
31
+ if (config.state !== "installed" || config.provider.type !== "aws") {
32
+ throw `Cluster with ID ${clusterId} is not installed`;
33
+ }
34
+ const { provider } = config;
35
+ const { accountId: awsAccountId, clusterArn: awsClusterArn } = provider;
36
+ if (!awsAccountId || !awsClusterArn) {
37
+ throw (`This command currently only supports AWS EKS clusters, and ${clusterId} is not configured as one.\n` +
38
+ "You can request access to the cluster using the `p0 request k8s` command.");
39
+ }
40
+ const { config: awsConfig } = yield (0, config_1.getAwsConfig)(authn, awsAccountId);
41
+ const { login: awsLogin } = awsConfig;
42
+ // Verify that the AWS auth type is supported before issuing the requests
43
+ if (!(awsLogin === null || awsLogin === void 0 ? void 0 : awsLogin.type) || (awsLogin === null || awsLogin === void 0 ? void 0 : awsLogin.type) === "iam") {
44
+ throw "This AWS account is not configured for kubectl access via the P0 CLI.\nYou can request access to the cluster using the `p0 request k8s` command.";
45
+ }
46
+ return {
47
+ clusterConfig: {
48
+ clusterId,
49
+ awsAccountId,
50
+ awsClusterArn,
51
+ },
52
+ awsLoginType: awsLogin.type,
53
+ };
54
+ });
55
+ exports.getAndValidateK8sIntegration = getAndValidateK8sIntegration;
56
+ const requestAccessToCluster = (authn, args, clusterId, role) => __awaiter(void 0, void 0, void 0, function* () {
57
+ const response = yield (0, request_1.request)("request")(Object.assign(Object.assign({}, (0, lodash_1.pick)(args, "$0", "_")), { arguments: [
58
+ "k8s",
59
+ "resource",
60
+ "--cluster",
61
+ clusterId,
62
+ "--role",
63
+ role,
64
+ ...(args.resource ? ["--locator", args.resource] : []),
65
+ ...(args.reason ? ["--reason", args.reason] : []),
66
+ ...(args.requestedDuration
67
+ ? ["--requested-duration", args.requestedDuration]
68
+ : []),
69
+ ], wait: true }), authn, { message: "approval-required" });
70
+ if (!response) {
71
+ throw "Did not receive access ID from server";
72
+ }
73
+ const { id, isPreexisting } = response;
74
+ if (!isPreexisting) {
75
+ (0, stdio_1.print2)("Waiting for access to be provisioned. This may take up to a minute.");
76
+ }
77
+ return yield (0, shared_1.waitForProvisioning)(authn, id);
78
+ });
79
+ exports.requestAccessToCluster = requestAccessToCluster;
80
+ const profileName = (eksCluterName) => `p0cli-managed-eks-${eksCluterName}`;
81
+ exports.profileName = profileName;
82
+ const awsCloudAuth = (authn, awsAccountId, generated, loginType) => __awaiter(void 0, void 0, void 0, function* () {
83
+ const { eksGenerated } = generated;
84
+ const { name, idc } = eksGenerated;
85
+ switch (loginType) {
86
+ case "idc":
87
+ if (!idc) {
88
+ throw "AWS is configured to use Identity Center, but IDC information wasn't received in the request.";
89
+ }
90
+ return yield (0, idc_1.assumeRoleWithIdc)({
91
+ accountId: awsAccountId,
92
+ permissionSet: name,
93
+ idc,
94
+ });
95
+ case "federated":
96
+ return yield (0, aws_1.assumeRoleWithOktaSaml)(authn, {
97
+ accountId: awsAccountId,
98
+ role: name,
99
+ });
100
+ default:
101
+ throw (0, util_1.assertNever)(loginType);
102
+ }
103
+ });
104
+ exports.awsCloudAuth = awsCloudAuth;
@@ -0,0 +1 @@
1
+ export declare const ensureEksInstall: () => Promise<boolean>;
@@ -0,0 +1,65 @@
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.ensureEksInstall = 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 install_1 = require("../../common/install");
24
+ const EksItems = [...install_1.AwsItems, "kubectl"];
25
+ /**
26
+ * Converts the current system architecture, as represented in TypeScript, to
27
+ * the value used in the kubectl download URL, or throw an exception if the
28
+ * current architecture is not one kubectl has an official build for.
29
+ */
30
+ const kubectlDownloadArch = () => {
31
+ const arch = process.arch;
32
+ switch (arch) {
33
+ case "x64": // macOS, Linux, and Windows
34
+ return "amd64";
35
+ case "arm64": // macOS and Linux only
36
+ return arch;
37
+ default:
38
+ throw `Unsupported system architecture for kubectl: ${arch}. Please install kubectl manually, or check that it is available in your PATH.`;
39
+ }
40
+ };
41
+ const kubectlInstallCommandsDarwin = () => {
42
+ const arch = kubectlDownloadArch();
43
+ // The download is the kubectl binary itself
44
+ return [
45
+ `curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/${arch}/kubectl"`,
46
+ "chmod +x kubectl",
47
+ "sudo mkdir -p /usr/local/bin",
48
+ "sudo mv -i ./kubectl /usr/local/bin/kubectl",
49
+ "sudo chown root: /usr/local/bin/kubectl",
50
+ ];
51
+ };
52
+ const EksInstall = Object.assign(Object.assign({}, install_1.AwsInstall), { kubectl: {
53
+ label: "Kubernetes command-line tool",
54
+ commands: {
55
+ get darwin() {
56
+ // Use a getter so that we only invoke kubectlInstallCommandsDarwin() if and when we
57
+ // need to generate the installation commands so that we only check the architecture as
58
+ // needed; if kubectl is already installed, doesn't really matter how it was installed
59
+ // or whether it's an officially-supported architecture.
60
+ return kubectlInstallCommandsDarwin();
61
+ },
62
+ },
63
+ } });
64
+ const ensureEksInstall = () => __awaiter(void 0, void 0, void 0, function* () { return yield (0, install_1.ensureInstall)(EksItems, EksInstall); });
65
+ exports.ensureEksInstall = ensureEksInstall;
@@ -0,0 +1,51 @@
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
+ export declare type K8sClusterConfig = {
13
+ label?: string;
14
+ clusterServer: string;
15
+ clusterCertificate: string;
16
+ isProxy: boolean;
17
+ token: string;
18
+ publicJwk?: string;
19
+ provider: {
20
+ type: "aws";
21
+ clusterArn: string;
22
+ accountId: string;
23
+ } | {
24
+ type: "email";
25
+ };
26
+ state: string;
27
+ };
28
+ export declare type K8sConfig = {
29
+ "iam-write": Record<string, K8sClusterConfig>;
30
+ };
31
+ export declare type K8sPermissionSpec = PermissionSpec<"k8s", K8sResourcePermission, K8sGenerated>;
32
+ export declare type K8sResourcePermission = {
33
+ resource: {
34
+ name: string;
35
+ namespace: string;
36
+ kind: string;
37
+ };
38
+ role: string;
39
+ clusterId: string;
40
+ type: "resource";
41
+ };
42
+ export declare type K8sGenerated = {
43
+ eksGenerated: {
44
+ name: string;
45
+ idc?: {
46
+ id: string;
47
+ region: string;
48
+ };
49
+ };
50
+ role: string;
51
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -10,5 +10,11 @@ You should have received a copy of the GNU General Public License along with @p0
10
10
  **/
11
11
  import { CommandArgs } from "../../commands/shared/ssh";
12
12
  import { Authn } from "../../types/identity";
13
- import { SshRequest } from "../../types/ssh";
14
- export declare const sshOrScp: (authn: Authn, request: SshRequest, cmdArgs: CommandArgs, privateKey: string) => Promise<number | null>;
13
+ import { SshProvider, SshRequest } from "../../types/ssh";
14
+ export declare const sshOrScp: (args: {
15
+ authn: Authn;
16
+ request: SshRequest;
17
+ cmdArgs: CommandArgs;
18
+ privateKey: string;
19
+ sshProvider: SshProvider<any, any, any, any>;
20
+ }) => Promise<number | null>;