Skip to content

Commit 7cc7aab

Browse files
committed
Use Capsicum within unftp-sbe-fs, on FreeBSD.
After authenticating a connection, limit the process's rights to mitigate any potential attacks.
1 parent a665885 commit 7cc7aab

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
7171
unftp-sbe-fs = { path = "../libunftp/crates/unftp-sbe-fs"}
7272

7373
[patch.crates-io]
74-
capsicum = { git = "https://github.com/asomers/capsicum-rs", rev = "24330ee"}
75-
casper-sys = { git = "https://github.com/asomers/capsicum-rs", rev = "24330ee"}
74+
capsicum = { git = "https://github.com/asomers/capsicum-rs", rev = "2feefa0"}
75+
casper-sys = { git = "https://github.com/asomers/capsicum-rs", rev = "2feefa0"}
7676

7777
[lints]
78-
workspace=true
78+
workspace=true

crates/unftp-sbe-fs/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
4747
tracing-subscriber = "0.3.18"
4848
getrandom = "0.2.12"
4949

50+
[target.'cfg(target_os = "freebsd")'.dependencies]
51+
capsicum = { version = "0.3.0", features = [] }
52+
5053
[target.'cfg(target_os = "freebsd")'.dev-dependencies]
5154
capsicum = { version = "0.3.0", features = ["casper"] }
5255
capsicum-net = { version = "0.1.0", features = ["tokio"], git = "https://github.com/asomers/capsicum-net", rev = "c6fc574" }

crates/unftp-sbe-fs/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,28 @@ impl<User: UserDetail> StorageBackend<User> for Filesystem {
100100
};
101101
self.root_fd = Arc::new(self.root_fd.open_dir(relpath)?);
102102
}
103+
cfg_if! {
104+
if #[cfg(target_os = "freebsd")] {
105+
use capsicum::CapRights;
106+
107+
let mut rights = capsicum::RightsBuilder::new();
108+
rights.allow(capsicum::Right::Fcntl);
109+
rights.allow(capsicum::Right::Fstatat);
110+
rights.allow(capsicum::Right::Lookup);
111+
rights.allow(capsicum::Right::Read);
112+
rights.allow(capsicum::Right::Seek);
113+
if !user_detail.read_only() {
114+
rights.allow(capsicum::Right::Create);
115+
rights.allow(capsicum::Right::Ftruncate);
116+
rights.allow(capsicum::Right::Mkdirat);
117+
rights.allow(capsicum::Right::RenameatSource);
118+
rights.allow(capsicum::Right::RenameatTarget);
119+
rights.allow(capsicum::Right::Unlinkat);
120+
rights.allow(capsicum::Right::Write);
121+
}
122+
rights.finalize().limit(&self.root_fd)?;
123+
}
124+
}
103125
Ok(())
104126
}
105127

0 commit comments

Comments
 (0)