From 7baf904cffdc4074ba5529b095f98a8c1ed6707a Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Sat, 26 Aug 2017 21:42:04 +0100 Subject: Enable UID/GID mapping for qcow2 Apply ownership mapping in qcow2 images using libguestfs python bindings. To make this solution more general we introduce function guestfs_walk() which will return the root file system tree of disk image along with UID/GID values. These changes are applied in additional qcow2 disk image using the last layer as backing file. For FileSource this is layer-1.qcow2 with backing file layer-0.qcow2. --- tests/docker_source.py | 23 +++++++++++++++++++++++ tests/file_source.py | 10 ++++++++++ 2 files changed, 33 insertions(+) (limited to 'tests') diff --git a/tests/docker_source.py b/tests/docker_source.py index 9dc25d9..eeea379 100644 --- a/tests/docker_source.py +++ b/tests/docker_source.py @@ -263,6 +263,29 @@ class TestQcow2DockerSource(Qcow2ImageAccessor): g.umount('/') g.shutdown() + def test_qcow2_ownership_mapping(self): + """ + Ensures that UID/GID mapping works correctly for qcow2 conversion. + """ + self.uid_map = [[1000, 2000, 10], [0, 1000, 10], [500, 500, 10]] + self.gid_map = [[1000, 2000, 10], [0, 1000, 10], [500, 500, 10]] + layers_rootfs = self.call_bootstrap() + + g = guestfs.GuestFS(python_return_dict=True) + g.add_drive_opts( + self.get_image_path(len(layers_rootfs)), + readonly=True + ) + + g.launch() + for rootfs in layers_rootfs[::-1]: + self.rootfs_tree = rootfs + self.apply_mapping() + g.mount('/dev/sda', '/') + self.check_image(g) + g.umount('/') + g.shutdown() + class TestDockerSource(unittest.TestCase): """ diff --git a/tests/file_source.py b/tests/file_source.py index 391ca48..9ffd4e3 100644 --- a/tests/file_source.py +++ b/tests/file_source.py @@ -105,3 +105,13 @@ class TestQcow2FileSource(Qcow2ImageAccessor): """ self.call_bootstrap() self.check_qcow2_images(self.get_image_path()) + + def test_qcow2_ownership_mapping(self): + """ + Ensures that UID/GID mapping works correctly for qcow2 conversion. + """ + self.uid_map = [[1000, 2000, 10], [0, 1000, 10], [500, 500, 10]] + self.gid_map = [[1000, 2000, 10], [0, 1000, 10], [500, 500, 10]] + self.call_bootstrap() + self.apply_mapping() + self.check_qcow2_images(self.get_image_path(1)) -- cgit