@@ -664,3 +664,68 @@ def test_cgroupsv2_written_only_once(uvm_plain, cgroups_info):
664
664
assert len (write_lines ) == 1
665
665
assert len (mkdir_lines ) != len (cgroups ), "mkdir equal to number of cgroups"
666
666
assert len (mkdir_lines ) == 1
667
+
668
+
669
+ def test_jail_mount (uvm_plain ):
670
+ """
671
+ Test that the jailer mounts are propagated to the root mount namespace.
672
+ """
673
+ # setup the microvm
674
+ test_microvm = uvm_plain
675
+
676
+ chroot_base = test_microvm .jailer .chroot_base
677
+ # make a directory to hold the original content
678
+ original_content_dir = chroot_base / "original_content"
679
+ original_content_dir .mkdir (parents = True , exist_ok = True )
680
+
681
+ # make a directory to hold the jailed content
682
+ jailed_content_dir = Path (test_microvm .jailer .chroot_path ())
683
+ jailed_content_dir .mkdir (parents = True , exist_ok = True )
684
+
685
+ # assert that the directory was created
686
+ assert original_content_dir .exists ()
687
+ assert jailed_content_dir .exists ()
688
+
689
+ # create the files that will be mounted
690
+ test_data = original_content_dir / "test_data"
691
+ test_data .touch ()
692
+ assert test_data .exists ()
693
+ test_data .write_text ("test_data" )
694
+ assert test_data .read_text () == "test_data"
695
+
696
+ jailed_test_data = jailed_content_dir / "test_data"
697
+ jailed_test_data .touch ()
698
+ assert jailed_test_data .exists ()
699
+ assert jailed_test_data .read_text () == ""
700
+
701
+ # mount the data
702
+ subprocess .run (["mount" , "--bind" , test_data , jailed_test_data ], check = True )
703
+
704
+ # spawn the microvm
705
+ test_microvm .spawn ()
706
+ test_microvm .basic_config ()
707
+
708
+ # set params for the microvm
709
+ test_microvm .jailer .gid = 0
710
+ test_microvm .jailer .uid = 0
711
+ test_microvm .jailer .daemonize = True
712
+ test_microvm .extra_args = {"seccomp-level" : 0 }
713
+ test_microvm .add_net_iface ()
714
+ test_microvm .start ()
715
+
716
+ # mock jailer
717
+ for cmd in [
718
+ "unshare --mount --propagation unchanged" ,
719
+ "mount --make-rslave /" ,
720
+ f"mount --rbind { jailed_content_dir } { jailed_content_dir } " ,
721
+ ]:
722
+ subprocess .run (cmd .split (), check = True , capture_output = True )
723
+
724
+ # check that the file output is there
725
+ output = subprocess .run (
726
+ f"cat { jailed_content_dir } /test_data" ,
727
+ shell = True ,
728
+ check = True ,
729
+ capture_output = True ,
730
+ )
731
+ assert output .stdout .decode () == "test_data"
0 commit comments