Skip to content

Commit 13026d8

Browse files
cbrewstereryugey
authored andcommitted
linux_session: Make allow_other mount option optional
The `allow_other` mount option typically requires root user permissions unless configured otherwise on the machine. It would be nice if this was configurable to allow for unprivileged mounting. For non-root users to use this option the system must have 'user_allow_other' set in /etc/fuse.conf. Signed-off-by: Connor Brewster <[email protected]>
1 parent 6e8cf3e commit 13026d8

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/transport/fusedev/linux_session.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub struct FuseSession {
5252
readonly: bool,
5353
wakers: Mutex<Vec<Arc<Waker>>>,
5454
auto_unmount: bool,
55+
allow_other: bool,
5556
target_mntns: Option<libc::pid_t>,
5657
// fusermount binary, default to fusermount3
5758
fusermount: String,
@@ -95,6 +96,7 @@ impl FuseSession {
9596
auto_unmount,
9697
target_mntns: None,
9798
fusermount: FUSERMOUNT_BIN.to_string(),
99+
allow_other: true,
98100
})
99101
}
100102

@@ -109,6 +111,13 @@ impl FuseSession {
109111
self.fusermount = bin.to_string();
110112
}
111113

114+
/// Set the allow_other mount option. This allows other users than the one mounting the
115+
/// filesystem to access the filesystem. However, this option is usually restricted to the root
116+
/// user unless configured otherwise.
117+
pub fn set_allow_other(&mut self, allow_other: bool) {
118+
self.allow_other = allow_other;
119+
}
120+
112121
/// Get current fusermount binary.
113122
pub fn get_fusermount(&self) -> &str {
114123
self.fusermount.as_str()
@@ -126,6 +135,7 @@ impl FuseSession {
126135
&self.subtype,
127136
flags,
128137
self.auto_unmount,
138+
self.allow_other,
129139
self.target_mntns,
130140
&self.fusermount,
131141
)?;
@@ -362,12 +372,14 @@ impl FuseChannel {
362372
}
363373

364374
/// Mount a fuse file system
375+
#[allow(clippy::too_many_arguments)]
365376
fn fuse_kern_mount(
366377
mountpoint: &Path,
367378
fsname: &str,
368379
subtype: &str,
369380
flags: MsFlags,
370381
auto_unmount: bool,
382+
allow_other: bool,
371383
target_mntns: Option<libc::pid_t>,
372384
fusermount: &str,
373385
) -> Result<(File, Option<UnixStream>)> {
@@ -380,13 +392,16 @@ fn fuse_kern_mount(
380392
let meta = mountpoint
381393
.metadata()
382394
.map_err(|e| SessionFailure(format!("stat {mountpoint:?}: {e}")))?;
383-
let opts = format!(
384-
"default_permissions,allow_other,fd={},rootmode={:o},user_id={},group_id={}",
395+
let mut opts = format!(
396+
"default_permissions,fd={},rootmode={:o},user_id={},group_id={}",
385397
file.as_raw_fd(),
386398
meta.permissions().mode() & libc::S_IFMT,
387399
getuid(),
388400
getgid(),
389401
);
402+
if allow_other {
403+
opts.push_str(",allow_other");
404+
}
390405
let mut fstype = String::from(FUSE_FSTYPE);
391406
if !subtype.is_empty() {
392407
fstype.push('.');

0 commit comments

Comments
 (0)