Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(spaces): register gVisor with --allow-suid so the Space user can sudo and mount FUSE (#4852)

ddupontcacc4409baed
diff --git a/libs/cua/crates/cua-cli/src/doctor/host.rs b/libs/cua/crates/cua-cli/src/doctor/host.rs
index 4d2a8427a5..85e48daca1 100644
--- a/libs/cua/crates/cua-cli/src/doctor/host.rs
+++ b/libs/cua/crates/cua-cli/src/doctor/host.rs
@@ -180,6 +180,17 @@ pub async fn host_checks(cua: &Arc<Cua>, runtime_type: Option<&str>, arch: &str)
),
wants_gvisor,
));
+ if gvisor && vmm["container"]["gvisor_allow_suid"].as_bool() == Some(false) {
+ checks.push(with_severity(
+ Check::new(
+ "host.gvisor_setuid",
+ Status::Warn,
+ "runsc is registered without --allow-suid: the Space user cannot sudo or mount FUSE",
+ )
+ .fix("`sudo runsc install -- --allow-suid && sudo systemctl restart docker` (Colima: add `runtimeArgs: [--allow-suid]` under docker.runtimes.runsc and `colima restart`)"),
+ wants_gvisor,
+ ));
+ }
let qemu_arch = if arch == "arm64" { "aarch64" } else { "x86_64" };
let accel = vmm["host"]["accel"][qemu_arch]
.as_str()
diff --git a/libs/cua/crates/cua-vmm/src/auto.rs b/libs/cua/crates/cua-vmm/src/auto.rs
index d193518fcf..ac2759c762 100644
--- a/libs/cua/crates/cua-vmm/src/auto.rs
+++ b/libs/cua/crates/cua-vmm/src/auto.rs
@@ -107,6 +107,10 @@ pub struct ContainerReport {
pub gvisor: bool,
/// How runsc would be installed, or why it cannot be.
pub gvisor_provisioning: Option<String>,
+ /// Whether runsc is registered with `--allow-suid` (setuid, so `sudo`
+ /// and `fusermount3`, work for the Space user); `None` when unknown.
+ #[serde(default)]
+ pub gvisor_allow_suid: Option<bool>,
}
/// Structured `cua runtime doctor` output.
@@ -286,6 +290,13 @@ pub async fn doctor() -> DoctorReport {
container.reachable = true;
container.runtimes = rt.runtimes().await.unwrap_or_default();
container.gvisor = container.runtimes.iter().any(|r| r == "runsc");
+ if container.gvisor {
+ container.gvisor_allow_suid =
+ rt.runtime_args("runsc").await.ok().flatten().map(|a| {
+ a.iter()
+ .any(|x| x == "--allow-suid" || x == "--allow-suid=true")
+ });
+ }
container_status.ready = true;
container_status.detail = if container.gvisor {
format!("{} with gVisor (runsc)", ep.uri)
diff --git a/libs/cua/crates/cua-vmm/src/container/gvisor.rs b/libs/cua/crates/cua-vmm/src/container/gvisor.rs
index ab709ef124..908d916ab7 100644
--- a/libs/cua/crates/cua-vmm/src/container/gvisor.rs
+++ b/libs/cua/crates/cua-vmm/src/container/gvisor.rs
@@ -42,13 +42,30 @@ if ! command -v runsc >/dev/null 2>&1; then
fi
"#;
+/// The flags `runsc` is registered with. `--allow-suid`: gVisor ignores
+/// setuid bits by default, so the Space user could not `sudo` or mount FUSE
+/// through `fusermount3`. The elevation stays inside the sandbox's kernel.
+pub const RUNSC_ARGS: &[&str] = &["--allow-suid"];
+
/// Native Linux: install, register in /etc/docker/daemon.json, restart dockerd.
pub fn linux_script() -> String {
format!(
- "{INSTALL_BINARY_SCRIPT}runsc install\n(systemctl restart docker || service docker restart)\n"
+ "{INSTALL_BINARY_SCRIPT}runsc install -- {}\n(systemctl restart docker || service docker restart)\n",
+ RUNSC_ARGS.join(" ")
)
}
+/// The `runsc:` entry of a Docker `runtimes` map in YAML (Colima's
+/// `docker:` config), at `indent`.
+pub fn runsc_yaml_entry(indent: usize, runsc_path: &str) -> String {
+ let p = " ".repeat(indent);
+ let mut s = format!("{p}runsc:\n{p} path: {runsc_path}\n{p} runtimeArgs:");
+ for a in RUNSC_ARGS {
+ s.push_str(&format!("\n{p} - {a}"));
+ }
+ s
+}
+
/// One provisioning step.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
@@ -129,10 +146,7 @@ pub fn install_plan(kind: &EngineKind) -> Result<InstallPlan, String> {
/// a `docker:` block with other keys, and an existing `runtimes:` map.
pub fn colima_yaml_with_runsc(yaml: &str, runsc_path: &str) -> Option<String> {
let lines: Vec<&str> = yaml.lines().collect();
- let entry = |indent: usize| {
- let p = " ".repeat(indent);
- format!("{p}runsc:\n{p} path: {runsc_path}")
- };
+ let entry = |indent: usize| runsc_yaml_entry(indent, runsc_path);
let docker = lines.iter().position(|l| {
l.trim_end() == "docker: {}" || l.trim_end() == "docker:" || l.starts_with("docker: ")
});
@@ -266,7 +280,23 @@ mod tests {
assert!(argv.contains(&"-n".to_string()) && argv.last().unwrap().contains("runsc install"));
}
- const RUNSC: &str = " runtimes:\n runsc:\n path: /usr/bin/runsc";
+ const RUNSC: &str = " runtimes:\n runsc:\n path: /usr/bin/runsc\n runtimeArgs:\n - --allow-suid";
+
+ /// gVisor ignores setuid bits unless runsc runs with `--allow-suid`, so
+ /// without it the Space user cannot `sudo` or `fusermount3` (#4667).
+ #[test]
+ fn runsc_is_registered_with_setuid_allowed() {
+ assert!(
+ linux_script().contains("runsc install -- --allow-suid\n"),
+ "{}",
+ linux_script()
+ );
+ let out = colima_yaml_with_runsc("docker: {}\n", RUNSC_PATH).unwrap();
+ assert!(
+ out.contains(" runtimeArgs:\n - --allow-suid\n"),
+ "{out}"
+ );
+ }
#[test]
fn colima_yaml_default_empty_docker_map() {
@@ -295,7 +325,7 @@ mod tests {
let out = colima_yaml_with_runsc(y, RUNSC_PATH).unwrap();
assert_eq!(
out,
- "docker:\n runtimes:\n runsc:\n path: /usr/bin/runsc\n crun:\n path: /usr/bin/crun\nvmType: vz\n"
+ "docker:\n runtimes:\n runsc:\n path: /usr/bin/runsc\n runtimeArgs:\n - --allow-suid\n crun:\n path: /usr/bin/crun\nvmType: vz\n"
);
let y = "docker:\n runtimes: {}\n";
diff --git a/libs/cua/crates/cua-vmm/src/container/mod.rs b/libs/cua/crates/cua-vmm/src/container/mod.rs
index 5b08a83b73..533a0b4bee 100644
--- a/libs/cua/crates/cua-vmm/src/container/mod.rs
+++ b/libs/cua/crates/cua-vmm/src/container/mod.rs
@@ -214,6 +214,17 @@ impl ContainerRuntime {
Ok(v)
}
+ /// The extra arguments the engine runs runtime `name` with (`None` when
+ /// it is not registered).
+ pub async fn runtime_args(&self, name: &str) -> Result<Option<Vec<String>>> {
+ let info = self.docker.info().await.map_err(engine_err)?;
+ Ok(info
+ .runtimes
+ .unwrap_or_default()
+ .remove(name)
+ .map(|r| r.runtime_args.unwrap_or_default()))
+ }
+
/// Decide `runsc` vs `runc`, provisioning gVisor when permitted.
pub async fn resolve_oci_runtime(&self) -> Result<String> {
let mut cached = self.oci_runtime.lock().await;
diff --git a/libs/cua/crates/cua-vmm/src/managed.rs b/libs/cua/crates/cua-vmm/src/managed.rs
index 796d067678..7e81239e79 100644
--- a/libs/cua/crates/cua-vmm/src/managed.rs
+++ b/libs/cua/crates/cua-vmm/src/managed.rs
@@ -356,7 +356,8 @@ pub fn profile_yaml(arch: &str, cpus: u32, memory_gib: u32) -> String {
network:\n address: false\n\
kubernetes:\n enabled: false\n\
forceDiskImage: true\n\
- docker:\n default-runtime: runsc\n runtimes:\n runsc:\n path: /usr/local/bin/runsc\n"
+ docker:\n default-runtime: runsc\n runtimes:\n runsc:\n path: /usr/local/bin/runsc\n \
+ runtimeArgs:\n - --allow-suid\n"
)
}
@@ -1168,6 +1169,11 @@ mod tests {
let y = profile_yaml("aarch64", 4, 4);
assert!(y.contains("default-runtime: runsc"));
assert!(y.contains("path: /usr/local/bin/runsc"));
+ // Setuid (`sudo`, `fusermount3`) works for the Space user (#4667).
+ assert!(
+ y.contains(" runtimeArgs:\n - --allow-suid\n"),
+ "{y}"
+ );
assert!(y.contains("vmType: vz"));
assert!(y.contains("autoActivate: false"));
assert!(y.contains("forceDiskImage: true"));