diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index 2db0c0250e2..927562dbba6 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -518,6 +518,18 @@ start_image() { --board="${BOARD}" } +# Actions common to the dev container and the image +# but which should be run before the image branches off +# the base squashfs (used for systemd-sysext image building) +finish_image_common() { + local root_fs_dir="$1" + + # Build the selinux policy + if pkg_use_enabled coreos-base/coreos selinux; then + sudo semodule -n -s mcs -p "${root_fs_dir}" -i "${root_fs_dir}"/usr/share/selinux/mcs/*.pp + fi +} + finish_image() { local image_name="$1" local disk_layout="$2" @@ -634,11 +646,6 @@ EOF "${BUILD_DIR}/${image_kconfig}" fi - # Build the selinux policy - if pkg_use_enabled coreos-base/coreos selinux; then - sudo semodule -n -s mcs -p "${root_fs_dir}" -i "${root_fs_dir}"/usr/share/selinux/mcs/*.pp - fi - # Run tmpfiles once to make sure that /etc has everything in place before # we freeze it in /usr/share/flatcar/etc as lowerdir in the overlayfs. @@ -674,11 +681,7 @@ EOF # setfiles from version 3.11 requires the passed path to have no symlinks local real_root_fs_dir real_root_fs_dir=$(realpath "${root_fs_dir}") - # TODO: Breaks the system: - # sudo setfiles -Dv -r "${real_root_fs_dir}" -c "${real_root_fs_dir}"/etc/selinux/mcs/policy/policy.* "${real_root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${real_root_fs_dir}" - # sudo setfiles -Dv -r "${real_root_fs_dir}" -c "${real_root_fs_dir}"/etc/selinux/mcs/policy/policy.* "${real_root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${real_root_fs_dir}"/usr - # For now we only try it with /etc - sudo setfiles -Dv -r "${real_root_fs_dir}" -c "${real_root_fs_dir}"/etc/selinux/mcs/policy/policy.* "${real_root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${real_root_fs_dir}"/etc + sudo setfiles -Dv -r "${real_root_fs_dir}" -c "${real_root_fs_dir}"/etc/selinux/mcs/policy/policy.* "${real_root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${real_root_fs_dir}"{,/usr,/etc} fi # Temporary hack: set group ownership of /etc/{g,}shadow to the diff --git a/build_library/dev_container_util.sh b/build_library/dev_container_util.sh index 5bee2889e55..c885e269572 100755 --- a/build_library/dev_container_util.sh +++ b/build_library/dev_container_util.sh @@ -99,6 +99,9 @@ create_dev_container() { # The remount services are provided by coreos-base/coreos-init systemd_enable "${root_fs_dir}" "multi-user.target" "remount-usr.service" + finish_image_common \ + "${root_fs_dir}" + finish_image "${image_name}" "${disk_layout}" "${root_fs_dir}" "${image_contents}" "${image_contents_wtd}" declare -a files_to_evaluate diff --git a/build_library/prod_image_util.sh b/build_library/prod_image_util.sh index 0ea886b9a00..0a392fd94c2 100755 --- a/build_library/prod_image_util.sh +++ b/build_library/prod_image_util.sh @@ -101,6 +101,9 @@ create_prod_image() { ROOT="${root_fs_dir}" PORTAGE_CONFIGROOT="${BUILD_DIR}"/configroot \ test_image_content "${root_fs_dir}" + finish_image_common \ + "${root_fs_dir}" + local root_with_everything="${root_fs_dir}" # Call helper script for adding sysexts to the base OS.