scratch: probe unshare semantics on runner (will be reverted)

This commit is contained in:
code-yeongyu 2026-08-06 18:58:55 +09:00
parent 7e09224d77
commit 01337d55c1
2 changed files with 51 additions and 0 deletions

View File

@ -6,6 +6,7 @@ license.workspace = true
publish.workspace = true
[dependencies]
libc = "0.2"
sha2 = "0.10"
glob = "0.3"
plugins = { path = "../plugins" }

View File

@ -0,0 +1,50 @@
//! Scratch probe: dump GitHub runner unshare semantics (temporary, PR will be closed).
#![cfg(target_os = "linux")]
use std::process::Command;
fn run(args: &[&str]) -> (i32, String, String) {
let out = Command::new("unshare").args(args).output();
match out {
Ok(o) => (
o.status.code().unwrap_or(-1),
String::from_utf8_lossy(&o.stdout).trim().to_string(),
String::from_utf8_lossy(&o.stderr).trim().to_string(),
),
Err(e) => (-1, String::new(), format!("spawn error: {e}")),
}
}
#[test]
fn dump_unshare_semantics() {
let uid = unsafe { libc::getuid() };
let mut report = String::new();
report.push_str(&format!("uid={uid} euid={}\n", unsafe { libc::geteuid() }));
for f in ["/etc/subuid", "/etc/subgid"] {
report.push_str(&format!("--- {f} ---\n"));
if let Ok(s) = std::fs::read_to_string(f) {
report.push_str(&s);
} else {
report.push_str("(unreadable)\n");
}
}
for k in ["/proc/sys/kernel/unprivileged_userns_clone", "/proc/sys/kernel/apparmor_restrict_unprivileged_userns"] {
report.push_str(&format!("{k} = {}\n", std::fs::read_to_string(k).unwrap_or_else(|_| "(n/a)".into())));
}
for (name, args) in [
("plain", &["--user", "--map-root-user", "true"][..]),
("auto", &["--user", "--map-root-user", "--map-auto", "true"][..]),
(
"plain-full",
&["--user", "--map-root-user", "--mount", "--ipc", "--pid", "--uts", "--fork", "sh", "-lc", "echo alpha"][..],
),
(
"auto-full",
&["--user", "--map-root-user", "--map-auto", "--mount", "--ipc", "--pid", "--uts", "--fork", "sh", "-lc", "echo alpha"][..],
),
] {
let (rc, so, se) = run(args);
report.push_str(&format!("[{name}] rc={rc} stdout={so:?} stderr={se:?}\n"));
}
panic!("PROBE REPORT:\n{report}");
}