Skip to content

Commit a4943f0

Browse files
committed
SELinux: Label /usr and sysext image contents
So far we did not correctly label /usr because it broke certain things like Docker. With the sysext Docker and new policies we should try again. First generate the policy before branching off the base squashfs (which already misses a lot of things because they the most postprocessing is done late in finish_image!). Then label /usr and also the sysext contents in their folder - not in the overlay mount because this would operate on the whole image.
1 parent 71c9907 commit a4943f0

3 files changed

Lines changed: 8 additions & 9 deletions

File tree

build_library/build_image_util.sh

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,6 @@ EOF
715715
"${BUILD_DIR}/${image_kconfig}"
716716
fi
717717

718-
# Build the selinux policy
719-
if pkg_use_enabled coreos-base/coreos selinux; then
720-
sudo chroot "${root_fs_dir}" bash -c "cd /usr/share/selinux/mcs && semodule -s mcs -i *.pp"
721-
fi
722-
723718
# Run tmpfiles once to make sure that /etc has everything in place before
724719
# we freeze it in /usr/share/flatcar/etc as lowerdir in the overlayfs.
725720

@@ -752,10 +747,8 @@ EOF
752747
# The labeling has to be done before moving /etc to /usr/share/flatcar/etc to prevent wrong labels for these files and as
753748
# the relabeling on boot would cause upcopies in the overlay.
754749
if pkg_use_enabled coreos-base/coreos selinux; then
755-
# TODO: Breaks the system:
756-
# sudo setfiles -Dv -r "${root_fs_dir}" "${root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${root_fs_dir}"
757-
# sudo setfiles -Dv -r "${root_fs_dir}" "${root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${root_fs_dir}"/usr
758-
# For now we only try it with /etc
750+
sudo setfiles -Dv -r "${root_fs_dir}" "${root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${root_fs_dir}"
751+
sudo setfiles -Dv -r "${root_fs_dir}" "${root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${root_fs_dir}"/usr
759752
sudo setfiles -Dv -r "${root_fs_dir}" "${root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${root_fs_dir}"/etc
760753
fi
761754

build_library/prod_image_util.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ create_prod_image() {
9191
run_ldconfig "${root_fs_dir}"
9292
run_localedef "${root_fs_dir}"
9393

94+
# Build the selinux policy
95+
if pkg_use_enabled coreos-base/coreos selinux; then
96+
sudo chroot "${root_fs_dir}" bash -c "cd /usr/share/selinux/mcs && semodule -s mcs -i *.pp"
97+
fi
98+
9499
local root_with_everything="${root_fs_dir}"
95100

96101
# Call helper script for adding sysexts to the base OS.

build_sysext

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ done
219219

220220
# Unmount in order to get rid of the overlay
221221
umount "${BUILD_DIR}/install-root"
222+
sudo setfiles -Dv -r "${BUILD_DIR}/install-root" "${BUILD_DIR}/fs-root"/etc/selinux/mcs/contexts/files/file_contexts "${BUILD_DIR}/install-root"/usr
222223
umount "${BUILD_DIR}/fs-root"
223224

224225
if [[ "$FLAGS_generate_pkginfo" = "${FLAGS_TRUE}" ]] ; then

0 commit comments

Comments
 (0)