forked from hanwen/go-fuse
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fuse: support special /dev/fd/N mountpoint
libfuse introduced [1] a special `/dev/fd/N` syntax for the mountpoint: It means that a privileged parent process: * Opened /dev/fuse * Called mount() on a real mountpoint directory * Inherited the fd to /dev/fuse to us * Informs us about the fd number via /dev/fd/N This functionality is used to allow FUSE mounts inside containers that have neither root permissions nor suid binaries [2], and for the --drop_privileges flag of mount.fuse3 [4] Tested with singularity and gocryptfs and actually works [3]. v2: Added doccomment for NewServer. v3: Added specific error message on Server.Unmount(). v4: Moved mount details to package comment [1] libfuse/libfuse@64e1107 [2] rfjakob/gocryptfs#590 [3] $ singularity run --fusemount "host:gocryptfs --extpass echo --extpass test /tmp/a /mnt" docker://ubuntu INFO: Using cached SIF image Reading password from extpass program "echo", arguments: ["test"] Decrypting master key bash: /home/jakob/.cargo/env: No such file or directory bash: /home/jakob/.cargo/env: No such file or directory bash: /home/jakob/.cargo/env: No such file or directory Singularity> Filesystem mounted and ready. [4] man mount.fuse3 Change-Id: Ibcc2464b0ef1e3d236207981b487fd9a7d94c910
- Loading branch information
1 parent
6ffb07f
commit 09dcd03
Showing
4 changed files
with
153 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package fuse | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"syscall" | ||
"testing" | ||
) | ||
|
||
// TestMountDevFd tests the special `/dev/fd/N` mountpoint syntax, where a | ||
// privileged parent process opens /dev/fuse and calls mount() for us. | ||
// | ||
// In this test, we simulate a privileged parent by using the `fusermount` suid | ||
// helper. | ||
func TestMountDevFd(t *testing.T) { | ||
realMountPoint, err := ioutil.TempDir("", t.Name()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer syscall.Rmdir(realMountPoint) | ||
|
||
// Call the fusermount suid helper to obtain the file descriptor in place | ||
// of a privileged parent. | ||
var fuOpts MountOptions | ||
fd, err := callFusermount(realMountPoint, &fuOpts) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
fdMountPoint := fmt.Sprintf("/dev/fd/%d", fd) | ||
|
||
// Real test starts here: | ||
// See if we can feed fdMountPoint to NewServer | ||
fs := NewDefaultRawFileSystem() | ||
opts := MountOptions{ | ||
Debug: true, | ||
} | ||
srv, err := NewServer(fs, fdMountPoint, &opts) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
go srv.Serve() | ||
if err := srv.WaitMount(); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// If we are actually mounted, we should get ENOSYS. | ||
// | ||
// This won't deadlock despite pollHack not working for `/dev/fd/N` mounts | ||
// because functions in the syscall package don't use the poller. | ||
var st syscall.Stat_t | ||
err = syscall.Stat(realMountPoint, &st) | ||
if err != syscall.ENOSYS { | ||
t.Errorf("expected ENOSYS, got %v", err) | ||
} | ||
|
||
// Cleanup is somewhat tricky because `srv` does not know about | ||
// `realMountPoint`, so `srv.Unmount()` cannot work. | ||
// | ||
// A normal user has to call `fusermount -u` for themselves to unmount. | ||
// But in this test we can monkey-patch `srv.mountPoint`. | ||
srv.mountPoint = realMountPoint | ||
if err := srv.Unmount(); err != nil { | ||
t.Error(err) | ||
} | ||
} |
This file contains 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