scratch: fix probe to avoid unsafe
This commit is contained in:
parent
01337d55c1
commit
c54d860474
|
|
@ -1,4 +1,4 @@
|
||||||
//! Scratch probe: dump GitHub runner unshare semantics (temporary, PR will be closed).
|
//! Scratch probe: dump GitHub runner unshare semantics (temporary, PRs will be closed).
|
||||||
#![cfg(target_os = "linux")]
|
#![cfg(target_os = "linux")]
|
||||||
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
@ -15,11 +15,18 @@ fn run(args: &[&str]) -> (i32, String, String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sh(cmd: &str) -> String {
|
||||||
|
Command::new("sh")
|
||||||
|
.args(["-lc", cmd])
|
||||||
|
.output()
|
||||||
|
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dump_unshare_semantics() {
|
fn dump_unshare_semantics() {
|
||||||
let uid = unsafe { libc::getuid() };
|
|
||||||
let mut report = String::new();
|
let mut report = String::new();
|
||||||
report.push_str(&format!("uid={uid} euid={}\n", unsafe { libc::geteuid() }));
|
report.push_str(&format!("uid line: {}\n", sh("id")));
|
||||||
for f in ["/etc/subuid", "/etc/subgid"] {
|
for f in ["/etc/subuid", "/etc/subgid"] {
|
||||||
report.push_str(&format!("--- {f} ---\n"));
|
report.push_str(&format!("--- {f} ---\n"));
|
||||||
if let Ok(s) = std::fs::read_to_string(f) {
|
if let Ok(s) = std::fs::read_to_string(f) {
|
||||||
|
|
@ -42,6 +49,10 @@ fn dump_unshare_semantics() {
|
||||||
"auto-full",
|
"auto-full",
|
||||||
&["--user", "--map-root-user", "--map-auto", "--mount", "--ipc", "--pid", "--uts", "--fork", "sh", "-lc", "echo alpha"][..],
|
&["--user", "--map-root-user", "--map-auto", "--mount", "--ipc", "--pid", "--uts", "--fork", "sh", "-lc", "echo alpha"][..],
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"auto-full-echo-multi",
|
||||||
|
&["--user", "--map-root-user", "--map-auto", "--mount", "--ipc", "--pid", "--uts", "--fork", "sh", "-lc", "echo alpha from bash"][..],
|
||||||
|
),
|
||||||
] {
|
] {
|
||||||
let (rc, so, se) = run(args);
|
let (rc, so, se) = run(args);
|
||||||
report.push_str(&format!("[{name}] rc={rc} stdout={so:?} stderr={se:?}\n"));
|
report.push_str(&format!("[{name}] rc={rc} stdout={so:?} stderr={se:?}\n"));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue