Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: SSHConfig: atomically write ssh config#511

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedMay 20, 2025
edited
Loading

Relates to#504

To avoid race conditions, write to a tempfile and then rename.

Smoke-tested by:

  • Setting immutable flag on/Users/cian/.ssh/config (sudo chflags uchg $PATH) and validating that the rename failed:
    Screenshot 2025-05-21 at 20 13 14

  • Setting immutable flag on/Users/cian/.ssh and validating that writing the temp file failed:
    Screenshot 2025-05-21 at 20 13 56

  • Once immutable flag removed (sudo chflags nouchg $PATH), connecting to workspace is successful.

@johnstcnjohnstcn self-assigned thisMay 20, 2025
@johnstcnjohnstcnforce-pushed thecj/config-ssh/atomic-write branch from9b53e6c to2c491b7CompareMay 20, 2025 16:45
@johnstcnjohnstcnforce-pushed thecj/config-ssh/handle-malformed branch from09777c5 toeda19a2CompareMay 20, 2025 17:03
@johnstcnjohnstcnforce-pushed thecj/config-ssh/atomic-write branch from2c491b7 to5277656CompareMay 20, 2025 17:03
return this.fileSystem.writeFile(this.filePath, this.getRaw(), {
const randSuffix = Math.random().toString(36).substring(8)
const tempFilePath = `${this.filePath}.${randSuffix}`
await this.fileSystem.writeFile(tempFilePath, this.getRaw(), {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I am probably overthinking this, but if there is somehow a file with this suffix already, would we want to error instead of overwrite? We could useflag: "wx" on thewriteFile call to error if the path already exists.

Vanishingly unlikely, but maybe there could be a freak collision where a user has a~/.ssh/config.conf and the random suffix was alsoconf.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

  1. We could just write to/tmp
  2. We could instead name it something likeconfig.vscode-coder.${timestamp}.${randSuffix} to minimize the likelihood of collisions

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I like 2 personally because I think it gives us a better chance to get the temp files for debugging, with/tmp they could be long gone.

But I could see an argument for/tmp to avoid "clutter".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What about a ULID? It would be sufficiently random and you could sort them by time to determine write order when debugging.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If we want to guarantee atomicity, same folder is best (/tmp for instance could be on another filesystem).

To hide clutter in the case of error, I'd suggest a. prefix on the filename, perhaps.tmp.[filename].[rand]. At this point guaranteeing uniqueness beyond this would seem like overkill.

I.e. my suggestion is just/home/user/.ssh/config -> /home/user/.ssh/.tmp.config.XXXXXX.

One use-case that won't work here is if/home/user/.ssh/config is bind-mounted. In that situation we either error out or try to write the file directly. Erroring is obviously safest so perhaps we go with that.

Copy link
MemberAuthor

@johnstcnjohnstcnMay 21, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What about a ULID?

I like the idea in theory, but it would be another import.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Forgot to write down one more thing, we should also respect the existing file modes and permissions and make sure they're copied over.

johnstcn reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done. I've also adjusted the tempfile naming convention to~/.ssh/.config.vscode-coder-tmp.abc123 to make it abundantly clear that

  1. This refers to~/.ssh/config
  2. It was created byvscode-coder

mafredri, code-asher, and bcpeinhardt reacted with hooray emoji
@johnstcnjohnstcnforce-pushed thecj/config-ssh/atomic-write branch from5277656 to698b334CompareMay 21, 2025 10:59
Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nice work!

@johnstcnjohnstcnforce-pushed thecj/config-ssh/atomic-write branch from71e2751 to8ac1e78CompareMay 21, 2025 19:04
@bcpeinhardtbcpeinhardt merged commitca32d99 intocj/config-ssh/handle-malformedMay 23, 2025
2 checks passed
@bcpeinhardtbcpeinhardt deleted the cj/config-ssh/atomic-write branchMay 23, 2025 00:45
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@code-ashercode-ashercode-asher approved these changes

@mafredrimafredrimafredri approved these changes

@bcpeinhardtbcpeinhardtbcpeinhardt approved these changes

Assignees

@johnstcnjohnstcn

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@johnstcn@mafredri@code-asher@bcpeinhardt

[8]ページ先頭

©2009-2025 Movatter.jp