Merge pull request #4335 from ManaSugi/runk/fix-invalid-rootfs

runk: Handle rootfs path in config.json properly
This commit is contained in:
James O. D. Hunt 2022-05-30 14:03:58 +01:00 committed by GitHub
commit 96c8df40b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 9 deletions

View File

@ -37,20 +37,20 @@ impl Container {
// If the rootfs path in the spec file is a relative path,
// convert it into a canonical path to pass validation of rootfs in the agent.
if !&rootfs_path.is_absolute() {
let rootfs_name = rootfs_path
.file_name()
.ok_or_else(|| anyhow!("invalid rootfs name"))?;
spec_root.path = bundle_canon
.join(rootfs_name)
.join(rootfs_path)
.canonicalize()?
.to_str()
.map(|s| s.to_string())
.ok_or_else(|| anyhow!("failed to convert bundle path"))?;
.ok_or_else(|| {
anyhow!("failed to convert a rootfs path into a canonical path")
})?;
}
}
Ok(ContainerContext {
id: self.id,
bundle: self.bundle,
bundle: bundle_canon,
state_root: self.root,
spec,
// TODO: liboci-cli does not support --no-pivot option for create and run command.

View File

@ -95,6 +95,7 @@ impl ContainerContext {
let oci_state = ctr.oci_state()?;
let status = Status::new(
&self.state_root,
&self.bundle,
oci_state,
ctr.init_process_start_time,
ctr.created,
@ -141,7 +142,7 @@ mod tests {
#[test]
fn test_get_fifo_path() {
let test_data = PathBuf::from(TEST_BUNDLE_PATH)
let test_data = PathBuf::from(TEST_STATE_ROOT_PATH)
.join(TEST_CONTAINER_ID)
.join(EXEC_FIFO_FILENAME);
let status = create_dummy_status();

View File

@ -42,6 +42,7 @@ pub struct Status {
impl Status {
pub fn new(
root: &Path,
bundle: &Path,
oci_state: OCIState,
process_start_time: u64,
created_time: SystemTime,
@ -64,7 +65,7 @@ impl Status {
id: oci_state.id,
pid: oci_state.pid,
root: root.to_path_buf(),
bundle: PathBuf::from(&oci_state.bundle),
bundle: bundle.to_path_buf(),
rootfs,
process_start_time,
created,
@ -209,6 +210,7 @@ mod tests {
let oci_state = create_dummy_oci_state();
let created = SystemTime::now();
let status = Status::new(
Path::new(TEST_STATE_ROOT_PATH),
Path::new(TEST_BUNDLE_PATH),
oci_state.clone(),
1,

View File

@ -45,7 +45,8 @@ pub(crate) mod test_utils {
use std::time::SystemTime;
pub const TEST_CONTAINER_ID: &str = "test";
pub const TEST_BUNDLE_PATH: &str = "/test";
pub const TEST_STATE_ROOT_PATH: &str = "/state";
pub const TEST_BUNDLE_PATH: &str = "/bundle";
pub const TEST_ANNOTATION: &str = "test";
pub const TEST_CGM_DATA: &str = r#"{
"paths": {
@ -92,6 +93,7 @@ pub(crate) mod test_utils {
let oci_state = create_dummy_oci_state();
let created = SystemTime::now();
let status = Status::new(
Path::new(TEST_STATE_ROOT_PATH),
Path::new(TEST_BUNDLE_PATH),
oci_state.clone(),
1,