Backport patches to
cover Backport patches to
This series backports two patches for meta-selinux scarthgap:
The first patch adds support for a configurable policy store root via the POLICY_STORE_ROOT variable, which, by default, are stored under /var.
The second patch ensures SELinux file contexts are preserved in tarball images by appending '--selinux' to IMAGE_CMD_TAR.
This second patch had a conflict between policy version 35 (master) vs 33 (scarthgap), so I preserved version 33.
Sasi Kumar Maddineni (2):
selinux-image: Preserve SELinux contexts in tarballs
refpolicy: Add support to configure policy store root
classes/selinux-image.bbclass | 2 ++ .../refpolicy/refpolicy-minimum_git.bb | 2 +- .../refpolicy/refpolicy_common.inc | 9 ++++++--- recipes-security/selinux/libsemanage_3.7.bb | 20 ++++++++++++++++--- 4 files changed, 26 insertions(+), 7 deletions(-)
Signature · 1 line
2.47.3
PATCH 1/2 selinux-image: Preserve SELinux contexts in tarballs
From: Sasi Kumar Maddineni <[email protected]>
Tarball images were created without SELinux context information, causing loss of security labels during extraction while working with features like:ostree. This breaks SELinux policy enforcement and requires relabeling after deployment, adding runtime overhead.
Append "--selinux" to IMAGE_CMD_TAR to include SELinux file contexts when generating tarball images. This ensures security labels are preserved across image creation and deployment.
--- classes/selinux-image.bbclass | 2 ++ 1 file changed, 2 insertions(+)
classes/selinux-image.bbclass +2 -0
@@ -26,4 +26,6 @@ python selinux_setlabels_handler() { addhandler selinux_setlabels_handler selinux_setlabels_handler[eventmask] = "bb.event.RecipePreFinalise" +IMAGE_CMD_TAR:append = " --selinux" + inherit core-image
Signature · 1 line
2.47.3
PATCH 2/2 refpolicy: Add support to configure policy store root
In reply to Hiago De FrancoFrom: Sasi Kumar Maddineni <[email protected]>
By default, policy modules(*.pp) are stored in /var directory. Features like: ostree remove files in folders like /var variable data directory while build time.
Added support for custom policy store. We can now configure path to custom policy store to variable POLICY_STORE_ROOT.
--- .../refpolicy/refpolicy-minimum_git.bb | 2 +- .../refpolicy/refpolicy_common.inc | 9 ++++++--- recipes-security/selinux/libsemanage_3.7.bb | 20 ++++++++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-)
recipes-security/refpolicy/refpolicy-minimum_git.bb +1 -1
@@ -65,7 +65,7 @@ prepare_policy_store() { oe_runmake 'DESTDIR=${D}' 'prefix=${D}${prefix}' install POL_PRIORITY=100 POL_SRC=${D}${datadir}/selinux/${POLICY_NAME} - POL_STORE=${D}${localstatedir}/lib/selinux/${POLICY_NAME} + POL_STORE=${D}${POLICY_STORE_ROOT}/${POLICY_NAME} POL_ACTIVE_MODS=${POL_STORE}/active/modules/${POL_PRIORITY} # Prepare to create policy store
recipes-security/refpolicy/refpolicy_common.inc +6 -3
@@ -98,10 +98,12 @@ SRC_URI += " \ S = "${WORKDIR}/refpolicy" CONFFILES:${PN} = "${sysconfdir}/selinux/config" + +POLICY_STORE_ROOT ?= "${localstatedir}/lib/selinux" FILES:${PN} += " \ ${sysconfdir}/selinux/${POLICY_NAME}/ \ ${datadir}/selinux/${POLICY_NAME}/*.pp \ - ${localstatedir}/lib/selinux/${POLICY_NAME}/ \ + ${POLICY_STORE_ROOT}/${POLICY_NAME}/ \ " FILES:${PN}-dev =+ " \ ${datadir}/selinux/${POLICY_NAME}/include/ \
@@ -184,7 +186,7 @@ prepare_policy_store() { oe_runmake 'DESTDIR=${D}' 'prefix=${D}${prefix}' install POL_PRIORITY=100 POL_SRC=${D}${datadir}/selinux/${POLICY_NAME} - POL_STORE=${D}${localstatedir}/lib/selinux/${POLICY_NAME} + POL_STORE=${D}${POLICY_STORE_ROOT}/${POLICY_NAME} POL_ACTIVE_MODS=${POL_STORE}/active/modules/${POL_PRIORITY} # Prepare to create policy store
@@ -225,13 +227,14 @@ args = \$@ [end] policy-version = 33 +store-root = "${POLICY_STORE_ROOT}" EOF # Create policy store and build the policy semodule -p ${D} -s ${POLICY_NAME} -n -B rm -f ${D}${sysconfdir}/selinux/semanage.conf # No need to leave final dir created by semanage laying around - rm -rf ${D}${localstatedir}/lib/selinux/final + rm -rf ${D}${POLICY_STORE_ROOT}/final } install_misc_files() {
recipes-security/selinux/libsemanage_3.7.bb +17 -3
@@ -34,6 +34,8 @@ FILES:${PN}-python = "${PYTHON_SITEPACKAGES_DIR}/* \ FILES:${PN}-dbg += "${PYTHON_SITEPACKAGES_DIR}/.debug/*" FILES:${PN} += "${libexecdir}" +POLICY_STORE_ROOT ?= "${localstatedir}/lib/selinux" + do_compile:append() { oe_runmake pywrap \ PYLIBVER='python${PYTHON_BASEVERSION}' \
@@ -48,9 +50,21 @@ do_install:append() { PYLIBVER='python${PYTHON_BASEVERSION}' \ PYTHONLIBDIR='${PYTHON_SITEPACKAGES_DIR}' - # Update "policy-version" for semanage.conf - sed -i 's/^#\s*\(policy-version\s*=\).*$/\1 33/' \ - ${D}/etc/selinux/semanage.conf + conf_file="${D}/etc/selinux/semanage.conf" + + if [ -f "${conf_file}" ]; then + # Update "policy-version" for semanage.conf + sed -i 's/^#\s*\(policy-version\s*=\).*$/\1 33/' \ + ${D}/etc/selinux/semanage.conf + + # Update "store-root" for semanage.conf + if grep -q '^store-root=' "${conf_file}"; then + sed -i "s|^store-root=.*$|store-root=${POLICY_STORE_ROOT}|" "${conf_file}" + else + printf 'store-root=%s\n' "${POLICY_STORE_ROOT}" >> "${conf_file}" + fi + fi + } BBCLASSEXTEND = "native"
Signature · 1 line
2.47.3