Repository navigation
Conversation
Connect to the editor over a UNIX socket, as the Ruby rmate does. The path comes from -s/--unixsocket, RMATE_UNIXSOCKET, or the unixsocket key in rmate.rc, and defaults to ~/.rmate.socket. The socket takes precedence over host/port if the file exists; otherwise rmate connects to host/port as before. A forwarded TCP port on a shared server accepts connections from every user on that machine. A socket forwarded with SSH RemoteForward is created with owner-only permissions, so only its owner can connect.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR lets rmate connect to the editor over a UNIX socket, as the Ruby implementation does.
Motivation
On a shared server, such as the login node of an HPC cluster, a port opened with
RemoteForward 52698 localhost:52698listens onlocalhost, and every user on that machine can connect to this port:sshprints only a warning, andrmatesends the file to that user's tunnel and editor. This can be quite annoying because it breaks the expected behavior and in the worst case, it can lead to a leakage of sensitive information like passwords and credentials.Luckily there is a solution. OpenSSH can forward a UNIX socket instead:
sshd creates the socket with owner-only permissions (
StreamLocalBindMask, default0177), so only its owner can connect.The socket works both under macOS and Linux systems.
Details about the implementation design
-s/--unixsocket <PATH>, theRMATE_UNIXSOCKETenvironment variable, or theunixsocketkey in rmate.rc. It defaults to~/.rmate.socket, and a leading~/is expanded.Changes
List of changes automatically generated by CLAUDE:
src/settings.rs: newunixsocketoption (-s,--unixsocket,RMATE_UNIXSOCKET) andRMATE_UNIXSOCKETdefault.read_disk_settings()now also returns theunixsocketkey from rmate.rc; theRcSettingsstruct already had the field but did not use it. Newexpand_home()helper.src/main.rs: fillsunixsocketfrom rmate.rc or the default when it is not given on the command line or in the environment.src/remote_editor.rs:connect_to_editor()connects to the UNIX socket if the file exists, and otherwise to host/port. The existingsocket2dependency already enables theunixfeature, so no dependency is added.README.md: one entry under Features.Testing
Tested on macOS (aarch64) against a test editor that receives the file, then sends
saveandclose:-sRMATE_UNIXSOCKET~/expandedConnection refused, exit 1Also tested end to end on Linux (RHEL 9, kernel 5.14, x86_64): rmate on the remote host connected through a socket created by
RemoteForward /u/%r/.rmate.socket localhost:52698, and the file opened in the editor on macOS.The repository has no automated tests for the connection code (
cargo testruns 0 tests), so this PR adds none.Further notes about interactions via sockets
Connection refusedinstead of trying host/port. sshd leaves the socket behind on disconnect unless the server setsStreamLocalBindUnlink yes.SockAddr::unix()returns an error for longer paths.