Skip to content

Commit

Permalink
Use Capsicum within unftp-sbe-fs, on FreeBSD.
Browse files Browse the repository at this point in the history
After authenticating a connection, limit the process's rights to
mitigate any potential attacks.
  • Loading branch information
asomers committed Mar 18, 2024
1 parent a665885 commit 7cc7aab
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
unftp-sbe-fs = { path = "../libunftp/crates/unftp-sbe-fs"}

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

[lints]
workspace=true
workspace=true
3 changes: 3 additions & 0 deletions crates/unftp-sbe-fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
tracing-subscriber = "0.3.18"
getrandom = "0.2.12"

[target.'cfg(target_os = "freebsd")'.dependencies]
capsicum = { version = "0.3.0", features = [] }

[target.'cfg(target_os = "freebsd")'.dev-dependencies]
capsicum = { version = "0.3.0", features = ["casper"] }
capsicum-net = { version = "0.1.0", features = ["tokio"], git = "https://github.com/asomers/capsicum-net", rev = "c6fc574" }
Expand Down
22 changes: 22 additions & 0 deletions crates/unftp-sbe-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,28 @@ impl<User: UserDetail> StorageBackend<User> for Filesystem {
};
self.root_fd = Arc::new(self.root_fd.open_dir(relpath)?);
}
cfg_if! {
if #[cfg(target_os = "freebsd")] {
use capsicum::CapRights;

let mut rights = capsicum::RightsBuilder::new();
rights.allow(capsicum::Right::Fcntl);
rights.allow(capsicum::Right::Fstatat);
rights.allow(capsicum::Right::Lookup);
rights.allow(capsicum::Right::Read);
rights.allow(capsicum::Right::Seek);
if !user_detail.read_only() {
rights.allow(capsicum::Right::Create);
rights.allow(capsicum::Right::Ftruncate);
rights.allow(capsicum::Right::Mkdirat);
rights.allow(capsicum::Right::RenameatSource);
rights.allow(capsicum::Right::RenameatTarget);
rights.allow(capsicum::Right::Unlinkat);
rights.allow(capsicum::Right::Write);
}
rights.finalize().limit(&self.root_fd)?;
}
}
Ok(())
}

Expand Down

0 comments on commit 7cc7aab

Please sign in to comment.