-
Notifications
You must be signed in to change notification settings - Fork 31
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bcpeinhardt
merged 5 commits into
cj/config-ssh/handle-malformed
from
cj/config-ssh/atomic-write
May 23, 2025
+150
−22
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f9943cb
fix: SSHConfig: atomically write ssh config
johnstcn 1925567
preserve existing mode on config file if present
johnstcn 4997f50
adjust tempfile naming
johnstcn b61468b
escape dots in sshTempFilePathExpr
johnstcn 8ac1e78
improve error message on failure to write/rename
johnstcn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
fix: SSHConfig: atomically write ssh config
- Loading branch information
commit f9943cb2df7c6fb16692bdd137d50302fbde423e
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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 use
flag: "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
.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.
/tmp
config.vscode-coder.${timestamp}.${randSuffix}
to minimize the likelihood of collisionsThoughts?
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 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".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.
What about a ULID? It would be sufficiently random and you could sort them by time to determine write order when debugging.
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.
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.Uh oh!
There was an error while loading. Please reload this page.
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 like the idea in theory, but it would be another import.
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.
Forgot to write down one more thing, we should also respect the existing file modes and permissions and make sure they're copied over.
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.
Done. I've also adjusted the tempfile naming convention to
~/.ssh/.config.vscode-coder-tmp.abc123
to make it abundantly clear that~/.ssh/config
vscode-coder