Skip to content

Commit 326442b

Browse files
committed
fix(supervisor): harden tests for restricted CI container environments
Guard tests against CI-specific constraints: root without CAP_SETPCAP, UIDs with no /etc/passwd entry, and restricted /proc access. Signed-off-by: Seth Jennings <sjennings@nvidia.com> Signed-off-by: Seth Jennings <sjenning@redhat.com>
1 parent be05115 commit 326442b

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

crates/openshell-supervisor-process/src/bypass_monitor/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,18 @@ mod tests {
540540
}
541541
}
542542

543+
if std::fs::read_link(format!("/proc/{child_pid}/exe")).is_err()
544+
|| std::fs::read_dir(format!("/proc/{child_pid}/fd")).is_err()
545+
{
546+
#[allow(unsafe_code)]
547+
unsafe {
548+
libc::kill(child_pid, libc::SIGKILL);
549+
libc::waitpid(child_pid, std::ptr::null_mut(), 0);
550+
}
551+
eprintln!("skipping: cannot read /proc/{child_pid} (restricted /proc)");
552+
return;
553+
}
554+
543555
let deadline = Instant::now() + Duration::from_secs(2);
544556
loop {
545557
if let Ok(link) = std::fs::read_link(format!("/proc/{child_pid}/exe"))

crates/openshell-supervisor-process/src/process.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,17 @@ mod tests {
15991599
});
16001600

16011601
let result = drop_privileges(&policy);
1602+
#[cfg(target_os = "linux")]
1603+
{
1604+
if nix::unistd::geteuid().is_root() && !capability_bounding_set_clear_available() {
1605+
let msg = format!("{}", result.unwrap_err());
1606+
assert!(
1607+
msg.contains("Failed to clear child capability bounding set"),
1608+
"unexpected failure: {msg}"
1609+
);
1610+
return;
1611+
}
1612+
}
16021613
assert!(result.is_ok(), "drop_privileges failed: {result:?}");
16031614
}
16041615

@@ -1913,9 +1924,10 @@ mod tests {
19131924
return;
19141925
}
19151926

1916-
let current_user = User::from_uid(nix::unistd::geteuid())
1917-
.unwrap()
1918-
.expect("current user entry");
1927+
let Ok(Some(current_user)) = User::from_uid(nix::unistd::geteuid()) else {
1928+
eprintln!("skipping: current UID has no /etc/passwd entry");
1929+
return;
1930+
};
19191931
let restricted_group = Group::from_gid(Gid::from_raw(0))
19201932
.unwrap()
19211933
.expect("gid 0 group entry");

0 commit comments

Comments
 (0)