@@ -664,3 +664,76 @@ 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_mount_proagation_to_root (uvm_plain , tmp_path , guest_kernel , rootfs_rw ):
670
+ """
671
+ Test that the jailer mounts are propagated to the root mount namespace.
672
+
673
+ This is a test for
674
+ https://github.com/firecracker-microvm/firecracker/pull/#1093
675
+ """
676
+
677
+ test_microvm = uvm_plain
678
+
679
+ # make a directory to hold the original content
680
+ original_content_dir = tmp_path / "original"
681
+ original_content_dir .mkdir (parents = True )
682
+
683
+ # make a directory to hold the jailed content
684
+ jailed_content_dir = tmp_path / "firecracker" / "testbindmount" / "root"
685
+ jailed_content_dir .mkdir (parents = True )
686
+
687
+ test_microvm .jailer .jailer_id = "testbindmount"
688
+ test_microvm .jailer .chroot_base = tmp_path
689
+ test_microvm .jailer .daemonize = True
690
+ test_microvm .jailer .gid = 0
691
+ test_microvm .jailer .uid = 0
692
+ test_microvm .extra_args = {"seccomp-level" : 0 }
693
+
694
+ # assert that the directory was created
695
+ assert jailed_content_dir .exists ()
696
+
697
+ # Create the guest kernel and rootfs in the jailed content directory
698
+ # and mount them in the jailed content directory
699
+ os .system (f"cp { guest_kernel } { original_content_dir } " )
700
+ os .system (f"cp { rootfs_rw } { original_content_dir } " )
701
+ guest_kernel_mount_path = jailed_content_dir / os .path .basename (guest_kernel )
702
+ rootfs_mount_path = jailed_content_dir / os .path .basename (rootfs_rw )
703
+ guest_kernel_mount_path .touch ()
704
+ rootfs_mount_path .touch ()
705
+
706
+ # assert that the files were created
707
+ assert guest_kernel_mount_path .exists ()
708
+ assert rootfs_mount_path .exists ()
709
+
710
+ # mount the rootfs
711
+ subprocess .run (
712
+ [
713
+ "mount" ,
714
+ "--bind" ,
715
+ original_content_dir / os .path .basename (guest_kernel ),
716
+ guest_kernel_mount_path ,
717
+ ],
718
+ check = True ,
719
+ )
720
+ subprocess .run (
721
+ [
722
+ "mount" ,
723
+ "--bind" ,
724
+ original_content_dir / os .path .basename (rootfs_rw ),
725
+ rootfs_mount_path ,
726
+ ],
727
+ check = True ,
728
+ )
729
+
730
+ # assert that the mounts are present
731
+ assert guest_kernel_mount_path .exists ()
732
+ assert rootfs_mount_path .exists ()
733
+
734
+ # run
735
+ test_microvm .spawn ()
736
+
737
+ # assert that the mounts are present
738
+ assert guest_kernel_mount_path .exists ()
739
+ assert rootfs_mount_path .exists ()
0 commit comments