Skip to content

Commit

Permalink
Merge pull request #28 from slp/fix-root
Browse files Browse the repository at this point in the history
Use xattr to fix container image root ownership and mode
  • Loading branch information
slp authored Aug 4, 2022
2 parents a99b7b9 + 7459968 commit ba9e585
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "krunvm"
version = "0.2.0"
version = "0.2.1"
authors = ["Sergio Lopez <[email protected]>"]
description = "Create microVMs from OCI images"
repository = "https://github.com/containers/krunvm"
Expand Down
32 changes: 32 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,34 @@ pub fn parse_mapped_volumes(volume_matches: Vec<&str>) -> HashMap<String, String
mapped_volumes
}

#[cfg(target_os = "macos")]
fn fix_root_mode(rootfs: &str) {
let mut args = vec!["-w", "user.containers.override_stat", "0:0:0555"];
args.push(rootfs);

let output = match Command::new("xattr")
.args(&args)
.stderr(std::process::Stdio::inherit())
.output()
{
Ok(output) => output,
Err(err) => {
if err.kind() == std::io::ErrorKind::NotFound {
println!("{} requires xattr to manage the OCI images, and it wasn't found on this system.", APP_NAME);
} else {
println!("Error executing xattr: {}", err);
}
std::process::exit(-1);
}
};

let exit_code = output.status.code().unwrap_or(-1);
if exit_code != 0 {
println!("xattr returned an error: {}", exit_code);
std::process::exit(-1);
}
}

#[allow(unused_variables)]
pub fn mount_container(cfg: &KrunvmConfig, vmcfg: &VmConfig) -> Result<String, std::io::Error> {
let mut args = get_buildah_args(cfg, BuildahCommand::Mount);
Expand Down Expand Up @@ -168,6 +196,10 @@ pub fn mount_container(cfg: &KrunvmConfig, vmcfg: &VmConfig) -> Result<String, s
}

let rootfs = std::str::from_utf8(&output.stdout).unwrap().trim();

#[cfg(target_os = "macos")]
fix_root_mode(&rootfs);

Ok(rootfs.to_string())
}

Expand Down

0 comments on commit ba9e585

Please sign in to comment.