-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Test jailer bindmounts to root #5025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -664,3 +664,68 @@ def test_cgroupsv2_written_only_once(uvm_plain, cgroups_info): | |
assert len(write_lines) == 1 | ||
assert len(mkdir_lines) != len(cgroups), "mkdir equal to number of cgroups" | ||
assert len(mkdir_lines) == 1 | ||
|
||
|
||
def test_jail_mount(uvm_plain): | ||
""" | ||
Test that the jailer mounts are propagated to the root mount namespace. | ||
""" | ||
# setup the microvm | ||
test_microvm = uvm_plain | ||
|
||
chroot_base = test_microvm.jailer.chroot_base | ||
# make a directory to hold the original content | ||
original_content_dir = chroot_base / "original_content" | ||
original_content_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
# make a directory to hold the jailed content | ||
jailed_content_dir = Path(test_microvm.jailer.chroot_path()) | ||
jailed_content_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
# assert that the directory was created | ||
assert original_content_dir.exists() | ||
assert jailed_content_dir.exists() | ||
|
||
# create the files that will be mounted | ||
test_data = original_content_dir / "test_data" | ||
test_data.touch() | ||
assert test_data.exists() | ||
test_data.write_text("test_data") | ||
assert test_data.read_text() == "test_data" | ||
|
||
jailed_test_data = jailed_content_dir / "test_data" | ||
jailed_test_data.touch() | ||
assert jailed_test_data.exists() | ||
assert jailed_test_data.read_text() == "" | ||
|
||
# mount the data | ||
subprocess.run(["mount", "--bind", test_data, jailed_test_data], check=True) | ||
Comment on lines
+701
to
+702
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's bind-mount a kernel image and a rootfs like the original reporter did [ref]. This is why I proposed like that in the previous round. |
||
|
||
# spawn the microvm | ||
test_microvm.spawn() | ||
test_microvm.basic_config() | ||
|
||
# set params for the microvm | ||
test_microvm.jailer.gid = 0 | ||
test_microvm.jailer.uid = 0 | ||
test_microvm.jailer.daemonize = True | ||
test_microvm.extra_args = {"seccomp-level": 0} | ||
test_microvm.add_net_iface() | ||
test_microvm.start() | ||
|
||
# mock jailer | ||
for cmd in [ | ||
"unshare --mount --propagation unchanged", | ||
"mount --make-rslave /", | ||
f"mount --rbind {jailed_content_dir} {jailed_content_dir}", | ||
]: | ||
subprocess.run(cmd.split(), check=True, capture_output=True) | ||
Comment on lines
+716
to
+722
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not mock jailer. If my previous explanation made you write like this, I apologize. I used the mock jailer just to make it easier to understand what we want to test. |
||
|
||
# check that the file output is there | ||
output = subprocess.run( | ||
f"cat {jailed_content_dir}/test_data", | ||
shell=True, | ||
check=True, | ||
capture_output=True, | ||
) | ||
assert output.stdout.decode() == "test_data" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're testing bind mounts, so
test_bind_mount
,test_bind_mount_kernel_and_rootfs
or something would be preferable.