From a0007b48a9d25ba03e31a6adfc48a8fade012f34 Mon Sep 17 00:00:00 2001 From: Veli-Matti Lintu Date: Thu, 25 Jan 2018 14:48:34 +0200 Subject: [PATCH] Add new attribute 'mode' for partitions to set the permissions of the mountpoints. Without this having /tmp on separate partition results in error as the permissions of /tmp are 0755. Setting them to 01777 fixes the setup. --- bootstrapvz/base/manifest-schema.yml | 1 + bootstrapvz/common/task_groups.py | 1 + bootstrapvz/common/tasks/filesystem.py | 26 +++++++++++++++++++ manifests/README.rst | 1 + .../kvm/stretch-virtio-partitions.yml | 1 + 5 files changed, 30 insertions(+) diff --git a/bootstrapvz/base/manifest-schema.yml b/bootstrapvz/base/manifest-schema.yml index 1046b4e..74e3821 100644 --- a/bootstrapvz/base/manifest-schema.yml +++ b/bootstrapvz/base/manifest-schema.yml @@ -191,6 +191,7 @@ definitions: minItems: 1 type: array size: {$ref: '#/definitions/bytes'} + mode: {type: string} required: [size, filesystem] additionalProperties: false partition_table: diff --git a/bootstrapvz/common/task_groups.py b/bootstrapvz/common/task_groups.py index 33db010..bbd0637 100644 --- a/bootstrapvz/common/task_groups.py +++ b/bootstrapvz/common/task_groups.py @@ -76,6 +76,7 @@ mounting_group = [filesystem.CreateMountDir, filesystem.MountRoot, filesystem.MountAdditional, filesystem.MountSpecials, + filesystem.ChmodMountDirs, filesystem.CopyMountTable, filesystem.RemoveMountTable, filesystem.UnmountRoot, diff --git a/bootstrapvz/common/tasks/filesystem.py b/bootstrapvz/common/tasks/filesystem.py index 03dcfa6..c6b7c53 100644 --- a/bootstrapvz/common/tasks/filesystem.py +++ b/bootstrapvz/common/tasks/filesystem.py @@ -127,6 +127,32 @@ class MountAdditional(Task): p_map.root.add_mount(getattr(p_map, partition.name), partition.name, ['--options'] + partition.mountopts) +class ChmodMountDirs(Task): + description = 'Chmod mount dirs' + phase = phases.volume_mounting + predecessors = [MountAdditional] + + @classmethod + def run(cls, info): + import os + from bootstrapvz.base.fs.partitions.unformatted import UnformattedPartition + from bootstrapvz.base.fs.partitions.single import SinglePartition + + def has_mode(partition): + return (not isinstance(partition, (UnformattedPartition, SinglePartition)) and + 'mode' in info.manifest.volume['partitions'][partition.name] and + info.manifest.volume['partitions'][partition.name]['mode'] is not None) + + p_map = info.volume.partition_map + partitions = p_map.partitions + for partition in list( + filter(has_mode, partitions)): + partition = getattr(p_map, partition.name) + mode_str = info.manifest.volume['partitions'][partition.name]['mode'] + mode = int(mode_str, 8) + os.chmod(os.path.join(info.root, partition.name), mode) + + class MountSpecials(Task): description = 'Mounting special block devices' phase = phases.os_installation diff --git a/manifests/README.rst b/manifests/README.rst index 3970508..07de8ad 100644 --- a/manifests/README.rst +++ b/manifests/README.rst @@ -297,6 +297,7 @@ boot, root and swap. - ``size``: The size of the partition. Valid values: Any datasize specification up to TB (e.g. 5KiB, 1MB, 6TB). ``required`` + - ``mode``: Set the mode bits of the mount point, e.g. '1777' for /tmp - ``filesystem``: The filesystem of the partition. When choosing ``xfs``, the ``xfsprogs`` package will need to be installed. Valid values: ``ext2``, ``ext3``, ``ext4``, ``xfs`` diff --git a/manifests/examples/kvm/stretch-virtio-partitions.yml b/manifests/examples/kvm/stretch-virtio-partitions.yml index 49330cf..7d8205e 100644 --- a/manifests/examples/kvm/stretch-virtio-partitions.yml +++ b/manifests/examples/kvm/stretch-virtio-partitions.yml @@ -34,6 +34,7 @@ volume: - journal_ioprio=3 filesystem: ext4 size: 1GiB + mode: '1777' var: filesystem: ext4 size: 1GiB