-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSH: Support executing commands and interactive shell with port forwarding #50
Conversation
0674ed8
to
83b9792
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the package-lock.json
please?
src/plugins/aws/ssm/index.ts
Outdated
]; | ||
}; | ||
|
||
const createSsmCommands = (args: Omit<SsmArgs, "requestId">): string[][] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More stable I think as
const createSsmCommands = (args: Omit<SsmArgs, "requestId">): string[][] => { | |
const createSsmCommands = (args: Omit<SsmArgs, "requestId">): { | |
interactiveShellCommand: string[]; | |
portForwardingCommand: string[]; | |
} => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed to {shellCommand, subCommand}
because the shell command sometimes wont be interactive. It can be the portforwarding command for example p0 ssh <instance> -NL <ports>
src/plugins/aws/ssm/index.ts
Outdated
...credential, | ||
}, | ||
stdio, | ||
}) as ChildProcessByStdio< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type casting here is a little sus. It would be nicer to use typescript overloading. You could get away with just the two variants that you actually used:
const spawnChildProcess = (credential: AwsCredentials, command: string[], stdio: [StdioNull, StdioPipe, StdioPipe]): ChildProcessByStdio<null, Readable, Readable>;
const spawnChildProcess = (credential: AwsCredentials, command: string[], stdio: [StdioNull, StdioNull, StdioNull]): ChildProcessByStdio<null, null, null>;
const spanwChildProcess = (credential: AwsCredentials, command: string[], stdio: [StdioNull, StdioNull | StdioPipe, StdioNull | StdioPipe]): ChildProcessByStdio<null, Readable, Readable> | ChildProcessByStdio<null, null, null> => {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL! This is much neater.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the package-lock.json please?
I removed it and I reran yarn add ps-tree
because I had previously installed it with npm.
src/plugins/aws/ssm/index.ts
Outdated
...credential, | ||
}, | ||
stdio, | ||
}) as ChildProcessByStdio< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL! This is much neater.
src/plugins/aws/ssm/index.ts
Outdated
]; | ||
}; | ||
|
||
const createSsmCommands = (args: Omit<SsmArgs, "requestId">): string[][] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed to {shellCommand, subCommand}
because the shell command sometimes wont be interactive. It can be the portforwarding command for example p0 ssh <instance> -NL <ports>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lookin' good 👌
This PR enables
p0 ssh <instance> -L 56789:80
p0 ssh <instance> sleep 10 -L 56789:80
p0 ssh <instance> -NL 56789:80
In order to support this behavior a new package
ps-tree
was added to ensure that grandchild processes spawned by the AWS CLI are cleaned up.Solves:
https://linear.app/p0-security/issue/ENG-1651/support-p0-ssh-n
https://linear.app/p0-security/issue/ENG-1653/p0-cli-ssh-support-executing-commands-with-port-forwarding