diff --git a/src/agent/src/grpc.rs b/src/agent/src/grpc.rs index f1c4dbd167..9b724a1d25 100644 --- a/src/agent/src/grpc.rs +++ b/src/agent/src/grpc.rs @@ -284,7 +284,7 @@ impl agentService { let pipe_size = AGENT_CONFIG.read().unwrap().container_pipe_size; let ocip = rustjail::process_grpc_to_oci(process); - let p = Process::new(&sl!(), &ocip, cid.as_str(), false, pipe_size)?; + let p = Process::new(&sl!(), &ocip, exec_id.as_str(), false, pipe_size)?; let ctr = match sandbox.get_container(cid.as_str()) { Some(v) => v, diff --git a/src/agent/src/namespace.rs b/src/agent/src/namespace.rs index e4d2ee1b35..f1e4b34ef9 100644 --- a/src/agent/src/namespace.rs +++ b/src/agent/src/namespace.rs @@ -37,6 +37,8 @@ pub struct Namespace { pub path: String, persistent_ns_dir: String, ns_type: NamespaceType, + //only used for uts namespace + pub hostname: Option, } impl Namespace { @@ -46,6 +48,7 @@ impl Namespace { path: String::from(""), persistent_ns_dir: String::from(PERSISTENT_NS_DIR), ns_type: NamespaceType::IPC, + hostname: None, } } @@ -54,8 +57,11 @@ impl Namespace { self } - pub fn as_uts(mut self) -> Self { + pub fn as_uts(mut self, hostname: &str) -> Self { self.ns_type = NamespaceType::UTS; + if hostname != "" { + self.hostname = Some(String::from(hostname)); + } self } @@ -82,6 +88,7 @@ impl Namespace { } self.path = new_ns_path.clone().into_os_string().into_string().unwrap(); + let hostname = self.hostname.clone(); let new_thread = thread::spawn(move || { let origin_ns_path = get_current_thread_ns_path(&ns_type.get()); @@ -98,6 +105,12 @@ impl Namespace { return Err(err.to_string()); } + if ns_type == NamespaceType::UTS && hostname.is_some() { + match nix::unistd::sethostname(hostname.unwrap()) { + Err(err) => return Err(err.to_string()), + Ok(_) => (), + } + } // Bind mount the new namespace from the current thread onto the mount point to persist it. let source: &str = origin_ns_path.as_str(); let destination: &str = new_ns_path.as_path().to_str().unwrap_or("none"); @@ -136,7 +149,7 @@ impl Namespace { } /// Represents the Namespace type. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq)] enum NamespaceType { IPC, UTS, @@ -201,7 +214,7 @@ mod tests { let tmpdir = Builder::new().prefix("ipc").tempdir().unwrap(); let ns_uts = Namespace::new(&logger) - .as_uts() + .as_uts("test_hostname") .set_root_dir(tmpdir.path().to_str().unwrap()) .setup(); diff --git a/src/agent/src/sandbox.rs b/src/agent/src/sandbox.rs index 414c2a7454..1f0cb28bd9 100644 --- a/src/agent/src/sandbox.rs +++ b/src/agent/src/sandbox.rs @@ -171,7 +171,10 @@ impl Sandbox { }; // // Set up shared UTS namespace - self.shared_utsns = match Namespace::new(&self.logger).as_uts().setup() { + self.shared_utsns = match Namespace::new(&self.logger) + .as_uts(self.hostname.as_str()) + .setup() + { Ok(ns) => ns, Err(err) => { return Err(ErrorKind::ErrorCode(format!(