Skip to content

reversesshfs: serve only the mounted directory, add ReadonlyNames - #118

Open
sylvinus wants to merge 1 commit into
lima-vm:masterfrom
sylvinus:readonly-names
Open

sylvinus wants to merge 1 commit into
lima-vm:masterfrom
sylvinus:readonly-names

Conversation

@sylvinus

Copy link
Copy Markdown

Addresses #6 for Linux and macOS hosts (Windows keeps sftp.NewServer).

Needed for lima-vm/lima#5529

  • The builtin driver now uses sftp.NewRequestServer with handlers rooted at LocalPath. Reads go through os.Root, writes never follow symlinks.
  • New ReadonlyNames field: paths with a matching component are read-only (case-insensitive, HFS+ ignorable code points handled as in git).
  • Setting the times of a read-only name to its current mtime is a no-op, so Lima's mountInotify keeps working on those files.

Tested:

  • unit tests on Linux and macOS, plus an e2e test with a real sshfs (runs when $SSHFS is set)
  • Debian 12 VM (kernel 6.1, no fchmodat2), to cover the chmod fallback that CI kernels (6.6+) never take for regular files
  • end to end with Lima on macOS

Assisted-by: Claude Opus 5.5 (1M context)

The builtin driver used sftp.NewServer, which serves the whole host file
system to the guest. On Linux and macOS hosts, it now uses
sftp.NewRequestServer with handlers rooted at LocalPath: reads go
through os.Root, and writes open each parent directory with O_NOFOLLOW,
so they never follow a symlink. A path outside the root gets EACCES.
Windows keeps sftp.NewServer.

Setting the mode fails on a symlink, on macOS as on Linux. On Linux
kernels without fchmodat2 (< 6.6), it goes through /proc/self/fd of an
O_PATH fd, as glibc does, so it needs no read permission.

ReadonlyNames makes a path read-only when any of its components matches
one of these names, compared case-insensitively and ignoring the code
points that HFS+ ignores, as git does. For example, [".git"] keeps the
working tree writable while hooks and config stay read-only. Setting
ReadonlyNames selects the builtin driver in auto mode, and fails with
the OpenSSH driver or on Windows.

Setting the times of a read-only name to its current mtime is a no-op
that succeeds, because this is how the Lima guest agent triggers
IN_ATTRIB for host changes (mountInotify).

Addresses lima-vm#6 for Linux and macOS hosts.

Assisted-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Sylvain Zimmer <sylvain@sylvainzimmer.com>
@AkihiroSuda

Copy link
Copy Markdown
Member

#6.

An alternative idea: execute limactl inside sandbox-exec (macOS) or landlock (Linux).
It should work with any mount driver.

Originally posted by @AkihiroSuda in lima#5529

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