From 9dc61f03231396fbbd73fc58788d73791da2cd51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 1 Dec 2026 00:56:38 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20forge=20runner=20check=20?= =?UTF-8?q?run=20from=20an=20SSH=20shell=20fails=20the=20cgroup=20line=20w?= =?UTF-8?q?ith=20the=20reason=20and=20the=20systemd-run=20--user=20command?= =?UTF-8?q?=20to=20use,=20instead=20of=20passing=20it=20and=20then=20faili?= =?UTF-8?q?ng=20the=20sandbox=20run=20with=20a=20bare=20permission=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/forge-runner/src/check.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/crates/forge-runner/src/check.rs b/crates/forge-runner/src/check.rs index 346f821..56f516f 100644 --- a/crates/forge-runner/src/check.rs +++ b/crates/forge-runner/src/check.rs @@ -14,6 +14,7 @@ use tokio::process::Command; use crate::config::{Limits, UsernsMode}; use crate::sandbox::SandboxRequest; +use crate::sandbox::helper::job_cgroup_base; use crate::sandbox::idmap::IdMap; /// The probe job. It prints the seccomp mode of the job, then succeeds. @@ -211,20 +212,20 @@ fn sandbox_lines(stderr: &str) -> Vec<&str> { .collect() } -/// The cgroup v2 controllers enabled for the job cgroup, which is a child of the runner's parent -/// slice (see the helper). Returns the enabled list, or why it could not be read. +/// The cgroup v2 controllers enabled for job cgroups, read where the helper puts them. Fails when +/// that cgroup is not ours to write, as in an SSH session's scope. fn delegated_controllers() -> Result, String> { - let text = fs::read_to_string("/proc/self/cgroup") - .map_err(|e| format!("cannot read /proc/self/cgroup: {e}"))?; - let own = text - .lines() - .find_map(|line| line.strip_prefix("0::")) - .ok_or_else(|| "cgroup v2 is not in use by this process".to_owned())?; - let own = PathBuf::from(own.trim()); - let base = own.parent().unwrap_or(&own); - let file = Path::new("/sys/fs/cgroup") - .join(base.strip_prefix("/").unwrap_or(base)) - .join("cgroup.subtree_control"); + let base = job_cgroup_base().map_err(|e| e.to_string())?; + let dir = Path::new("/sys/fs/cgroup").join(base.strip_prefix("/").unwrap_or(&base)); + let probe = dir.join(format!("forge-check-{}", std::process::id())); + fs::create_dir(&probe).map_err(|e| { + format!( + "cannot create a cgroup in {}: {e}; run under systemd --user, e.g. `systemd-run --user -P forge runner check`", + dir.display() + ) + })?; + let _ = fs::remove_dir(&probe); + let file = dir.join("cgroup.subtree_control"); let enabled = fs::read_to_string(&file).map_err(|e| format!("cannot read {}: {e}", file.display()))?; Ok(enabled.split_whitespace().map(str::to_owned).collect())