Skip to content

Commit 1e5adbd

Browse files
committed
build_sysext: Add --selinux flag and use it to build policies
For built-in sysext, we may not have yet any policies built, so the relabeling won't work. To fix the situation, so we need to temporarily build them ourselves. Signed-off-by: Krzesimir Nowak <knowak@microsoft.com>
1 parent 40e3b86 commit 1e5adbd

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

build_sysext

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ DEFINE_string install_root_basename "${default_install_root_basename}" \
4545
"Name of a root directory where packages will be installed. ${default_install_root_basename@Q} by default."
4646
DEFINE_string forbidden_packages "" \
4747
"Comma-separated list of pairs describing packages that are forbidden in the sysext. Every pair consist of regexp and message, separated with semicolon. The regexp is for matching a package name (<category>/<name>-<version>::<repo>), and message is printed if the regexp matched a package name. Be careful to not include commas in the regexp or message."
48+
DEFINE_boolean selinux "${FLAGS_FALSE}" \
49+
"Relabel the files in sysext using policies installed in the base squashfs image."
4850

4951
FLAGS_HELP="USAGE: build_sysext [flags] <sysext_name> <binary_package> [<binary_package> ...]
5052
@@ -155,6 +157,8 @@ cleanup() {
155157
"${BUILD_DIR}/workdir"
156158
"${BUILD_DIR}/img-rootfs"
157159
"${BUILD_DIR}/install-root"
160+
"${BUILD_DIR}/selinux-root"
161+
"${BUILD_DIR}/selinux-root-workdir"
158162
)
159163
umount "${dirs[@]}" 2>/dev/null || true
160164
rm -rf "${dirs[@]}" || true
@@ -254,6 +258,13 @@ export SOURCE_DATE_EPOCH=$(stat -c '%Y' "${BUILD_DIR}/fs-root/usr/lib/os-release
254258
# Unmount in order to get rid of the overlay, but keep fs-root for
255259
# now, so we can use selinux file contexts.
256260
umount "${THE_INSTALL_ROOT}"
261+
if [[ ${FLAGS_selinux} = "${FLAGS_TRUE}" ]]; then
262+
mkdir "${BUILD_DIR}/selinux-root"
263+
mkdir "${BUILD_DIR}/selinux-root-workdir"
264+
mount -t overlay overlay -o lowerdir="${BUILD_DIR}/fs-root${pkginfo_lowerdirs}",upperdir="${BUILD_DIR}/selinux-root",workdir="${BUILD_DIR}/selinux-root-workdir" "${BUILD_DIR}/selinux-root"
265+
else
266+
umount "${BUILD_DIR}/fs-root"
267+
fi
257268

258269
if [[ "$FLAGS_generate_pkginfo" = "${FLAGS_TRUE}" ]] ; then
259270
info " Creating pkginfo squashfs '${BUILD_DIR}/${SYSEXTNAME}_pkginfo.raw'"
@@ -340,9 +351,21 @@ if [[ -n "${invalid_files}" ]]; then
340351
die "Invalid file ownership: ${invalid_files}"
341352
fi
342353

343-
info "Relabeling sysext contents"
344-
setfiles -D -E -F -r "${THE_INSTALL_ROOT}" -v -T 0 "${BUILD_DIR}/fs-root/usr/share/flatcar/etc/selinux/mcs/contexts/files/file_contexts" "${THE_INSTALL_ROOT}"
345-
umount "${BUILD_DIR}/fs-root"
354+
if [[ ${FLAGS_selinux} = "${FLAGS_TRUE}" ]]; then
355+
info "Build temporary selinux modules"
356+
chroot "${BUILD_DIR}/selinux-root" bash -s <<'EOF'
357+
cd /usr/share/selinux/mcs
358+
set -x
359+
semodule -s mcs -n -i *.pp
360+
EOF
361+
362+
info "Relabeling sysext contents"
363+
spec_file="${BUILD_DIR}/selinux-root/etc/selinux/mcs/contexts/files/file_contexts"
364+
setfiles -D -E -F -r "${THE_INSTALL_ROOT}" -v -T 0 "${spec_file}" "${THE_INSTALL_ROOT}"
365+
ls -laRZ "${THE_INSTALL_ROOT}"
366+
umount "${BUILD_DIR}/selinux-root"
367+
umount "${BUILD_DIR}/fs-root"
368+
fi
346369

347370
info "Creating squashfs image"
348371
mksquashfs "${THE_INSTALL_ROOT}" "${BUILD_DIR}/${SYSEXTNAME}.raw" \

0 commit comments

Comments
 (0)