diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/runner/runc/run.rs | 16 | ||||
-rw-r--r-- | src/util.rs | 13 |
2 files changed, 19 insertions, 10 deletions
diff --git a/src/runner/runc/run.rs b/src/runner/runc/run.rs index 0735128..39adbc1 100644 --- a/src/runner/runc/run.rs +++ b/src/runner/runc/run.rs @@ -1,5 +1,5 @@ use std::{ - fs::{DirBuilder, File}, + fs::DirBuilder, io, path::{Path, PathBuf}, process, @@ -68,15 +68,11 @@ fn output_filename(task: TaskRef) -> PathBuf { } fn collect_output(task: TaskRef, task_def: Task) -> Result<(), io::Error> { - // Temporarily switch to the user running Rebel to get the right - // owner for the tar files - let file = { - let _setegid = util::setegid(unshare::BUILD_GID)?; - let _seteuid = util::seteuid(unshare::BUILD_UID)?; - - File::create(output_filename(task))? - }; - + let file = util::create_as( + output_filename(task), + Some(unshare::BUILD_UID), + Some(unshare::BUILD_GID), + )?; util::tar::pack(file, "build/tmp/runc/workdir", task_def.output.iter())?.sync_all() } diff --git a/src/util.rs b/src/util.rs index d388a59..460f735 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,7 +1,9 @@ pub mod tar; use std::{ + fs::File, io::{Error, ErrorKind, Result}, + path::Path, process::ExitStatus, result, }; @@ -96,3 +98,14 @@ pub fn setegid(gid: unistd::Gid) -> Result<SetEGID> { unistd::setegid(gid).to_io_result()?; Ok(SetEGID(old_gid)) } + +pub fn create_as<P: AsRef<Path>>( + path: P, + uid: Option<unistd::Uid>, + gid: Option<unistd::Gid>, +) -> Result<File> { + let _setegid = gid.map(setegid).transpose()?; + let _seteuid = uid.map(seteuid).transpose()?; + + File::create(path) +} |