Skip to content

Commit 38bfeaa

Browse files
committed
Add support for requesting groups during ssh request
1 parent d7132a6 commit 38bfeaa

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/commands/ssh.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import yargs from "yargs";
3030
export type SshCommandArgs = {
3131
destination: string;
3232
command?: string;
33+
requestGroup?: boolean;
3334
L?: string; // Port forwarding option
3435
N?: boolean; // No remote command
3536
arguments: string[];
@@ -88,6 +89,11 @@ export const sshCommand = (yargs: yargs.Argv) =>
8889
describe:
8990
"Do not execute a remote command. Useful for forwarding ports.",
9091
})
92+
.option("request-group", {
93+
type: "boolean",
94+
describe:
95+
"Request access to all other instances that share a group with the destination",
96+
})
9197
// Match `p0 request --reason`
9298
.option("reason", {
9399
describe: "Reason access is needed",
@@ -163,6 +169,27 @@ const ssh = async (args: yargs.ArgumentsCamelCase<SshCommandArgs>) => {
163169
// Prefix is required because the backend uses it to determine that this is an AWS request
164170
const authn = await authenticate();
165171
await validateSshInstall(authn);
172+
173+
if (args.requestGroup) {
174+
// When requesting for a group of a specific node first gain access to the group. Subsequent
175+
// requests will detect that the node is a part of the group and can use the group permission
176+
// to gain access to the node.
177+
const response = await request(
178+
{
179+
...pick(args, "$0", "_"),
180+
arguments: ["ssh", "group", "--destination", args.destination],
181+
wait: true,
182+
},
183+
authn,
184+
{ message: "approval-required" }
185+
);
186+
if (!response) {
187+
print2("Did not receive access ID from server");
188+
return;
189+
}
190+
await waitForProvisioning<AwsSsh>(authn, response.id);
191+
}
192+
166193
const response = await request<AwsSsh>(
167194
{
168195
...pick(args, "$0", "_"),

0 commit comments

Comments
 (0)