forge
Explore
Log in

Don't you dare go Hollow

Forge runner check run from an SSH shell fails the cgroup line with the reason and the systemd-run --user command to use, instead of passing it and then failing the sandbox run with a bare permission error

Browse files at this commit

9dc61f03231396fbbd73fc58788d73791da2cd51Ahmet Kaan GümüşParent: 810de83
Some checks failed
Show checks
  • ✗ci/buildworkspace: workspace io: No such file or directory (os error 2)Details
  • fix
    • forge runner check run from an SSH shell fails the cgroup line with the reason and the systemd-run --user command to use, instead of passing it and then failing the sandbox run with a bare permission error
Show full message
🐛 fix: forge runner check run from an SSH shell fails the cgroup line with the reason and the systemd-run --user command to use, instead of passing it and then failing the sandbox run with a bare permission error
crates/forge-runner/src/check.rsmodified+14 -13
@@ -14,6 +14,7 @@ use tokio::process::Command;
14 14
15 use crate::config::{Limits, UsernsMode};15 use crate::config::{Limits, UsernsMode};
16 use crate::sandbox::SandboxRequest;16 use crate::sandbox::SandboxRequest;
17+use crate::sandbox::helper::job_cgroup_base;
17 use crate::sandbox::idmap::IdMap;18 use crate::sandbox::idmap::IdMap;
18 19
19 /// The probe job. It prints the seccomp mode of the job, then succeeds.20 /// The probe job. It prints the seccomp mode of the job, then succeeds.
@@ -211,20 +212,20 @@ fn sandbox_lines(stderr: &str) -> Vec<&str> {
211 .collect()212 .collect()
212 }213 }
213 214
214-/// The cgroup v2 controllers enabled for the job cgroup, which is a child of the runner's parent215+/// The cgroup v2 controllers enabled for job cgroups, read where the helper puts them. Fails when
215-/// slice (see the helper). Returns the enabled list, or why it could not be read.216+/// that cgroup is not ours to write, as in an SSH session's scope.
216 fn delegated_controllers() -> Result<Vec<String>, String> {217 fn delegated_controllers() -> Result<Vec<String>, String> {
217- let text = fs::read_to_string("/proc/self/cgroup")218+ let base = job_cgroup_base().map_err(|e| e.to_string())?;
218- .map_err(|e| format!("cannot read /proc/self/cgroup: {e}"))?;219+ let dir = Path::new("/sys/fs/cgroup").join(base.strip_prefix("/").unwrap_or(&base));
219- let own = text220+ let probe = dir.join(format!("forge-check-{}", std::process::id()));
220- .lines()221+ fs::create_dir(&probe).map_err(|e| {
221- .find_map(|line| line.strip_prefix("0::"))222+ format!(
222- .ok_or_else(|| "cgroup v2 is not in use by this process".to_owned())?;223+ "cannot create a cgroup in {}: {e}; run under systemd --user, e.g. `systemd-run --user -P forge runner check`",
223- let own = PathBuf::from(own.trim());224+ dir.display()
224- let base = own.parent().unwrap_or(&own);225+ )
225- let file = Path::new("/sys/fs/cgroup")226+ })?;
226- .join(base.strip_prefix("/").unwrap_or(base))227+ let _ = fs::remove_dir(&probe);
227- .join("cgroup.subtree_control");228+ let file = dir.join("cgroup.subtree_control");
228 let enabled =229 let enabled =
229 fs::read_to_string(&file).map_err(|e| format!("cannot read {}: {e}", file.display()))?;230 fs::read_to_string(&file).map_err(|e| format!("cannot read {}: {e}", file.display()))?;
230 Ok(enabled.split_whitespace().map(str::to_owned).collect())231 Ok(enabled.split_whitespace().map(str::to_owned).collect())