Confine package ownership changes to private mounts
This commit is contained in:
parent
2c420012bd
commit
8334fd379f
1 changed files with 402 additions and 25 deletions
|
|
@ -67,6 +67,7 @@ fn run() -> io::Result<()> {
|
|||
}
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
enter_runtime_user_namespace()?;
|
||||
let tree = TestTree::new().map_err(|error| io::Error::other(format!("test tree: {error}")))?;
|
||||
let configuration = configuration(&tree)
|
||||
.map_err(|error| io::Error::other(format!("configuration: {error}")))?;
|
||||
|
|
@ -251,6 +252,25 @@ fn run() -> io::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
fn enter_runtime_user_namespace() -> io::Result<()> {
|
||||
let uid = rustix::process::getuid().as_raw();
|
||||
let gid = rustix::process::getgid().as_raw();
|
||||
rustix::thread::unshare(rustix::thread::UnshareFlags::NEWUSER)
|
||||
.map_err(|error| io::Error::other(format!("fixture user namespace: {error}")))?;
|
||||
fs::write("/proc/self/setgroups", "deny")?;
|
||||
fs::write("/proc/self/uid_map", format!("0 {uid} 1\n"))?;
|
||||
fs::write("/proc/self/gid_map", format!("0 {gid} 1\n"))?;
|
||||
rustix::thread::unshare(rustix::thread::UnshareFlags::NEWNS)
|
||||
.map_err(|error| io::Error::other(format!("fixture mount namespace: {error}")))?;
|
||||
rustix::mount::mount_change(
|
||||
"/",
|
||||
rustix::mount::MountPropagationFlags::PRIVATE | rustix::mount::MountPropagationFlags::REC,
|
||||
)
|
||||
.map_err(|error| io::Error::other(format!("fixture private propagation: {error}")))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
fn run_private_recovery_holder(arguments: &[OsString]) -> io::Result<()> {
|
||||
if arguments.len() != 2 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue