Adding pledge(2) and unveil(2) support for OpenBSD-stable #4033
Closed
zacknewman
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
As a very rough sketch on a completely self-serving example that works for my specific configuration (i.e., real code would obviously rely on reading the configuration values and perhaps have different #[cfg(all(feature = "priv_sep", target_os = "openbsd"))]
use priv_sep::{Permissions, Promise, Promises};
#[cfg(all(feature = "priv_sep", target_os = "openbsd"))]
use tokio::runtime::Builder;
#[cfg(all(feature = "priv_sep", target_os = "openbsd"))]
fn main() -> Result<(), Error> {
let mut promises = Promises::new([
Promise::Cpath,
Promise::Dns,
Promise::Flock,
Promise::Inet,
Promise::Rpath,
Promise::Stdio,
Promise::Unveil,
Promise::Wpath,
]);
promises.pledge()?;
Permissions::READ.unveil("/dev/urandom")?;
Permissions::READ.unveil("/etc/ssl/pmd.philomathiclife.com.fullchain")?;
Permissions::READ.unveil("/etc/ssl/pmd.philomathiclife.com.fullchain.key")?;
Permissions::READ.unveil("/var/vaultwarden/")?;
let mut perms = Permissions::ALL;
perms.execute = false;
perms.unveil("/var/vaultwarden/data/db.sqlite3")?;
perms.unveil("/var/vaultwarden/data/db.sqlite3-shm")?;
perms.unveil("/var/vaultwarden/data/db.sqlite3-wal")?;
perms.unveil("/var/vaultwarden/data/tmp/")?;
promises.remove(Promise::Unveil);
promises.pledge()?;
parse_args();
launch_info();
use log::LevelFilter as LF;
let level = LF::from_str(&CONFIG.log_level()).expect("Valid log level");
init_logging(level).ok();
let extra_debug = matches!(level, LF::Trace | LF::Debug);
Builder::new_multi_thread().enable_all().build().map_or_else(
|e| Err(Error::from(e)),
|runtime| {
runtime.block_on(async {
check_data_folder().await;
check_rsa_keys().unwrap_or_else(|_| {
error!("Error creating keys, exiting...");
exit(1);
});
check_web_vault();
create_dir(&CONFIG.icon_cache_folder(), "icon cache");
create_dir(&CONFIG.tmp_folder(), "tmp folder");
create_dir(&CONFIG.sends_folder(), "sends folder");
create_dir(&CONFIG.attachments_folder(), "attachments folder");
let pool = create_db_pool().await;
schedule_jobs(pool.clone());
crate::db::models::TwoFactor::migrate_u2f_to_webauthn(&mut pool.get().await.unwrap()).await.unwrap();
launch_rocket(pool, extra_debug).await.map_err(Error::from) // Blocks until program termination.
})
},
)
}
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm currently working on patching
pledge(2)
andunveil(2)
functionality on a local clone of this repo to be run on OpenBSD-stable that is based on thepriv_sep
crate I maintain. Would a pull request of such be of any interest? If not, then I likely won't bother heavily testing it on a variety of configurations.I realize a vast majority of people host
vaultwarden
on Linux-based OSes, so I understand if such platform-specific extensions are not welcome especially for such a "niche" OS. OpenBSD does have a vaultwarden port that is maintained that would benefit from such an extension though.I would be more than happy to work with you all in deciding how such functionality could be added if you are interested. There are two paths forward that make the most sense to me:
main
functions one with the#[cfg(all(feature = "priv_sep", target_os = "openbsd"))]
attribute and another with the#[cfg(not(all(feature = "priv_sep", target_os = "openbsd")))]
attribute. Then have apriv_sep
module that is hidden behind the#[cfg(all(feature = "priv_sep", target_os = "openbsd"))]
attribute.priv_sep
module that contains functions with the#[cfg(all(feature = "priv_sep", target_os = "openbsd"))]
attribute and functions with compatible signatures that are just no-ops with the#[cfg(not(all(feature = "priv_sep", target_os = "openbsd")))]
attribute. Then have a singlemain
function that calls these functions.Beta Was this translation helpful? Give feedback.
All reactions