Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rrw/rexec recursive mount test #1611

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,47 @@ fn check_recursive_noexec() -> TestResult {
result
}

fn check_recursive_rexec() -> TestResult {
let rnoexec_test_base_dir = PathBuf::from_str("/tmp").unwrap();
let rnoexec_dir_path = rnoexec_test_base_dir.join("rexec_dir");
let rnoexec_subdir_path = rnoexec_dir_path.join("rexec_subdir");
let mount_dest_path = PathBuf::from_str("/mnt").unwrap();

let mount_options = vec!["rbind".to_string(), "rexec".to_string()];
let mut mount_spec = Mount::default();
mount_spec
.set_destination(mount_dest_path)
.set_typ(None)
.set_source(Some(rnoexec_dir_path.clone()))
.set_options(Some(mount_options));
let spec = get_spec(
vec![mount_spec],
vec!["runtimetest".to_string(), "mounts_recursive".to_string()],
);

let result = test_inside_container(spec, &|bundle_path| {
setup_mount(&rnoexec_dir_path, &rnoexec_subdir_path);

let executable_file_name = "echo";
let executable_file_path = bundle_path.join("bin").join(executable_file_name);
let in_container_executable_file_path = rnoexec_dir_path.join(executable_file_name);
let in_container_executable_subdir_file_path =
rnoexec_subdir_path.join(executable_file_name);

fs::copy(&executable_file_path, in_container_executable_file_path)?;
fs::copy(
&executable_file_path,
in_container_executable_subdir_file_path,
)?;

Ok(())
});

clean_mount(&rnoexec_dir_path, &rnoexec_subdir_path);

result
}

/// rdiratime If set in attr_clr, removes the restriction that prevented updating access time for directories.
fn check_recursive_rdiratime() -> TestResult {
let rdiratime_base_dir = PathBuf::from_str("/tmp/rdiratime").unwrap();
Expand Down Expand Up @@ -330,6 +371,34 @@ fn check_recursive_rnodev() -> TestResult {
result
}

fn check_recursive_readwrite() -> TestResult {
let rrw_test_base_dir = PathBuf::from_str("/tmp").unwrap();
let rrw_dir_path = rrw_test_base_dir.join("rrw_dir");
let rrw_subdir_path = rrw_dir_path.join("rrw_subdir");
let mount_dest_path = PathBuf::from_str("/rrw").unwrap();

let mount_options = vec!["rbind".to_string(), "rrw".to_string()];
let mut mount_spec = Mount::default();
mount_spec
.set_destination(mount_dest_path)
.set_typ(None)
.set_source(Some(rrw_dir_path.clone()))
.set_options(Some(mount_options));
let spec = get_spec(
vec![mount_spec],
vec!["runtimetest".to_string(), "mounts_recursive".to_string()],
);

let result = test_inside_container(spec, &|_| {
setup_mount(&rrw_dir_path, &rrw_subdir_path);
Ok(())
});

clean_mount(&rrw_dir_path, &rrw_subdir_path);

result
}

pub fn get_mounts_recursive_test() -> TestGroup {
let rro_test = Test::new("rro_test", Box::new(check_recursive_readonly));
let rnosuid_test = Test::new("rnosuid_test", Box::new(check_recursive_nosuid));
Expand All @@ -338,6 +407,8 @@ pub fn get_mounts_recursive_test() -> TestGroup {
let rdiratime_test = Test::new("rdiratime_test", Box::new(check_recursive_rdiratime));
let rdev_test = Test::new("rdev_test", Box::new(check_recursive_rdev));
let rnodev_test = Test::new("rnodev_test", Box::new(check_recursive_rnodev));
let rrw_test = Test::new("rrw_test", Box::new(check_recursive_readwrite));
let rexec_test = Test::new("rexec_test", Box::new(check_recursive_rexec));

let mut tg = TestGroup::new("mounts_recursive");
tg.add(vec![
Expand All @@ -348,6 +419,8 @@ pub fn get_mounts_recursive_test() -> TestGroup {
Box::new(rnodiratime_test),
Box::new(rdev_test),
Box::new(rnodev_test),
Box::new(rrw_test),
Box::new(rexec_test),
]);

tg
Expand Down
33 changes: 33 additions & 0 deletions tests/rust-integration-tests/runtimetest/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ pub fn validate_mounts_recursive(spec: &Spec) {
eprintln!("error in testing rro recursive mounting : {e}");
}
}
"rrw" => {
if let Err(e) =
do_test_mounts_recursive(mount.destination(), &|test_file_path| {
if utils::test_write_access(test_file_path.to_str().unwrap())
.is_err()
{
// Return Err if not writeable
bail!(
"path {:?} expected to be writable, found read-only",
test_file_path
);
}
Ok(())
})
{
eprintln!("error in testing rro recursive mounting : {e}");
}
}
"rnoexec" => {
if let Err(e) = do_test_mounts_recursive(
mount.destination(),
Expand All @@ -131,6 +149,21 @@ pub fn validate_mounts_recursive(spec: &Spec) {
eprintln!("error in testing rnoexec recursive mounting: {e}");
}
}
"rexec" => {
if let Err(e) = do_test_mounts_recursive(
mount.destination(),
&|test_file_path| {
if let Err(ee) = utils::test_file_executable(
test_file_path.to_str().unwrap(),
) {
bail!("path {:?} expected to be executable, found not executable, error: {ee}", test_file_path);
}
Ok(())
},
) {
eprintln!("error in testing rexec recursive mounting: {e}");
}
}
"rdiratime" => {
println!("test_dir_update_access_time: {:?}", mount);
let rest = utils::test_dir_update_access_time(
Expand Down
1 change: 1 addition & 0 deletions tests/rust-integration-tests/runtimetest/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub fn test_file_executable(path: &str) -> Result<(), std::io::Error> {
let mode = fstat.st_mode;
if is_file_like(mode) {
Command::new(path).output()?;
return Ok(());
}

Err(std::io::Error::new(
Expand Down