Skip to content

Commit bfde4ae

Browse files
committed
test(sandbox): isolate credential probes from filtered threads
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 2c361fe commit bfde4ae

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎crates/openshell-sandbox/src/process.rs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,8 +3730,34 @@ mod tests {
37303730

37313731
// ---- Numeric UID tests (Phase 2) ----
37323732

3733+
// Even a failing setuid(0) probe synchronizes libc credentials across all
3734+
// threads. Other tests own seccomp-notified launcher threads in this same
3735+
// process; signaling those while they await their broker can deadlock the
3736+
// parallel harness. Re-exec just the credential probe, without those threads.
3737+
fn numeric_uid_probe_runs_in_child(test_name: &str) -> bool {
3738+
const MARKER: &str = "OPENSHELL_TEST_ISOLATED_NUMERIC_UID_PROBE";
3739+
if std::env::var(MARKER).as_deref() == Ok(test_name) {
3740+
return true;
3741+
}
3742+
let output = std::process::Command::new(std::env::current_exe().expect("test executable"))
3743+
.args(["--exact", test_name, "--test-threads=1", "--nocapture"])
3744+
.env(MARKER, test_name)
3745+
.output()
3746+
.expect("run isolated credential probe");
3747+
assert!(
3748+
output.status.success(),
3749+
"isolated credential probe failed: {}\n{}",
3750+
String::from_utf8_lossy(&output.stdout),
3751+
String::from_utf8_lossy(&output.stderr)
3752+
);
3753+
false
3754+
}
3755+
37333756
#[test]
37343757
fn drop_privileges_accepts_numeric_uid() {
3758+
if !numeric_uid_probe_runs_in_child("process::tests::drop_privileges_accepts_numeric_uid") {
3759+
return;
3760+
}
37353761
// When running as non-root, a numeric UID/GID that matches the
37363762
// current process should succeed without any passwd lookup.
37373763
if nix::unistd::geteuid().is_root() {
@@ -3754,6 +3780,11 @@ mod tests {
37543780

37553781
#[test]
37563782
fn drop_privileges_numeric_uid_skips_initgroups() {
3783+
if !numeric_uid_probe_runs_in_child(
3784+
"process::tests::drop_privileges_numeric_uid_skips_initgroups",
3785+
) {
3786+
return;
3787+
}
37573788
// When running as non-root with a numeric user but group matches,
37583789
// initgroups should not be called (guard: target_uid != geteuid()).
37593790
if nix::unistd::geteuid().is_root() {

0 commit comments

Comments
 (0)