-
Notifications
You must be signed in to change notification settings - Fork 751
fix(ec2): avoid wiping authorized_keys files on each connection
#6197
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
Conversation
|
authorized_keys files on each connection. authorized_keys files on each connection (WIP)
authorized_keys files on each connection (WIP)authorized_keys files on each connection
| * @returns bash command to remove lines from file. | ||
| */ | ||
| export function getRemoveLinesCommand(pattern: string, hostOS: Ec2OS, filepath: string): string { | ||
| // Linux allows not passing extension to -i, whereas macOS requires zero length extension. |
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.
Also any BSD flavor. Does the '' work on Linux so we can just always do sed -i ''? According to Claude, it should...
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 saw it in the docs, and double checked I wasn't able to get it to work on Amazon Linux.

Its annoying :(
I also thought about not using the -i option and instead piping it to another temporary file, then overwrite authorized_keys with the temporary file so that we could use same command on all OS, but I thought the tradeoff of taking 3-4 steps instead of 1 didn't feel worth it.
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.
Yeah, another option is to actually pass something like -i '.bk' on all platforms. That assumes one can write to the ~/.ssh/ directory, which is probably a fine assumption.
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.
Yeah, I wasn't sure if there would be any problems leaving backup files around. My thinking was to leave as little state/artifacts as possible on the remote machine, but having different commands for different OS is annoying.
Co-authored-by: Justin M. Keyes <[email protected]>
…scode into ec2/commentkeys
Co-authored-by: Justin M. Keyes <[email protected]>
…scode into ec2/commentkeys
…s#6197) ## Problem Each EC2 remote vscode connection wipes the remote `.ssh/authorized_keys` file as a preventative measure to leaving stale keys there. However, we can do better by adding comments to the keys we add to this file, then selectively removing those keys on subsequent connections. ## Solution - Whenever we send keys to the instance, use `sed` to wipe all of the keys added by us. - determine keys added by us using a hint comment `#AWSToolkitForVSCode`. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Justin M. Keyes <[email protected]>
…s#6197) ## Problem Each EC2 remote vscode connection wipes the remote `.ssh/authorized_keys` file as a preventative measure to leaving stale keys there. However, we can do better by adding comments to the keys we add to this file, then selectively removing those keys on subsequent connections. ## Solution - Whenever we send keys to the instance, use `sed` to wipe all of the keys added by us. - determine keys added by us using a hint comment `#AWSToolkitForVSCode`. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Justin M. Keyes <[email protected]>
Problem
Each EC2 remote vscode connection wipes the remote
.ssh/authorized_keysfile as a preventative measure to leaving stale keys there. However, we can do better by adding comments to the keys we add to this file, then selectively removing those keys on subsequent connections.Solution
sedto wipe all of the keys added by us.#AWSToolkitForVSCode.feature/xbranches will not be squash-merged at release time.License: I confirm that my contribution is made under the terms of the Apache 2.0 license.