Skip to content

Commit

Permalink
create: Forbid --privileged
Browse files Browse the repository at this point in the history
There should be no reason to use it with crun-vm and it causes problems
with additional devices being mounted into the container and crun-vm
trying to pass those through to the guest.

Signed-off-by: Alberto Faria <[email protected]>
  • Loading branch information
albertofaria committed Apr 17, 2024
1 parent 34b7b1b commit 640ddd6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/commands/create/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ pub fn create(args: &liboci_cli::Create, raw_args: &[impl AsRef<OsStr>]) -> Resu
let mut spec = oci_spec::runtime::Spec::load(&config_path)?;
let original_root_path: Utf8PathBuf = spec.root_path()?.canonicalize()?.try_into()?; // ensure absolute

if let Some(process) = spec.process().as_ref() {
if let Some(capabilities) = process.capabilities().as_ref() {
fn any_is_cap_sys_admin(caps: &Option<oci_spec::runtime::Capabilities>) -> bool {
caps.as_ref()
.is_some_and(|set| set.contains(&oci_spec::runtime::Capability::SysAdmin))
}

ensure!(
!any_is_cap_sys_admin(capabilities.bounding())
&& !any_is_cap_sys_admin(capabilities.effective())
&& !any_is_cap_sys_admin(capabilities.inheritable())
&& !any_is_cap_sys_admin(capabilities.permitted())
&& !any_is_cap_sys_admin(capabilities.ambient()),
"crun-vm should not be used with --privileged"
);
}
}

let runtime_env = RuntimeEnv::current(&spec, &original_root_path)?;
let custom_options = CustomOptions::from_spec(&spec, runtime_env)?;

Expand Down

0 comments on commit 640ddd6

Please sign in to comment.