Skip to content

Conversation

@Hweinstock
Copy link
Contributor

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.

License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions
Copy link

  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

@Hweinstock Hweinstock changed the title fix(ec2): avoid wiping authorized_keys files on each connection. fix(ec2): avoid wiping authorized_keys files on each connection (WIP) Dec 10, 2024
@Hweinstock Hweinstock changed the title fix(ec2): avoid wiping authorized_keys files on each connection (WIP) fix(ec2): avoid wiping authorized_keys files on each connection Dec 10, 2024
@Hweinstock Hweinstock marked this pull request as ready for review December 10, 2024 21:29
@Hweinstock Hweinstock requested a review from a team as a code owner December 10, 2024 21:29
* @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.
Copy link
Contributor

@justinmk3 justinmk3 Dec 10, 2024

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...

Copy link
Contributor Author

@Hweinstock Hweinstock Dec 11, 2024

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.
image

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@Hweinstock Hweinstock Dec 12, 2024

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.

@Hweinstock Hweinstock merged commit 4335e1e into aws:master Dec 12, 2024
26 checks passed
@Hweinstock Hweinstock deleted the ec2/commentkeys branch December 12, 2024 17:44
jpinkney-aws pushed a commit to jpinkney-aws/aws-toolkit-vscode that referenced this pull request Jan 6, 2025
…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]>
karanA-aws pushed a commit to karanA-aws/aws-toolkit-vscode that referenced this pull request Jan 17, 2025
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants