diff mbox series

shadow: split the subordinate id tools into shadow-uidmap and libsubid

Message ID 20261127081625.2560320-2-alex.kiernan@gmail.com
State New
Headers show
Series shadow: split the subordinate id tools into shadow-uidmap and libsubid | expand

Commit Message

Alex Kiernan Nov. 27, 2026, 8:16 a.m. UTC
An image that needs unprivileged user namespaces - a container runtime,
a sandbox - needs only newuidmap and newgidmap with /etc/subuid and
/etc/subgid. Installing shadow for them also installs passwd, chsh,
chfn, chage and gpasswd, all setuid root, and on a read-only rootfs it
means taking shadow off ROOTFS_RO_UNNEEDED, which keeps all of them.

Package them as Debian does: newuidmap, newgidmap, getsubids and the
id-range files as shadow-uidmap, and libsubid, which only getsubids
links, as a library package of its own. libsubid keeps its name rather
than taking the soname-versioned one, so that ROOTFS_RO_UNNEEDED can
name it. shadow RDEPENDS on shadow-uidmap, so installing shadow is
unchanged.

A read-only rootfs removes packages without their dependencies, so both
join ROOTFS_RO_UNNEEDED; without that they would outlive shadow there
and leave two setuid binaries in images that have none today. An image
that wants them on a read-only rootfs installs shadow-uidmap and takes
both off that list.

AI-Generated: Claude Opus 5.5 (Claude Code)
Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---
 meta/classes-recipe/image.bbclass             |  2 +-
 meta/recipes-extended/shadow/shadow_4.20.3.bb | 17 ++++++++++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-recipe/image.bbclass b/meta/classes-recipe/image.bbclass
index 1e3c784ec930..12c0478f1cc5 100644
--- a/meta/classes-recipe/image.bbclass
+++ b/meta/classes-recipe/image.bbclass
@@ -50,7 +50,7 @@  IMAGE_INSTALL_DEBUGFS ?= ""
 
 # These packages will be removed from a read-only rootfs after all other
 # packages have been installed
-ROOTFS_RO_UNNEEDED ??= "update-rc.d base-passwd shadow ${VIRTUAL-RUNTIME_update-alternatives} ${ROOTFS_BOOTSTRAP_INSTALL}"
+ROOTFS_RO_UNNEEDED ??= "update-rc.d base-passwd shadow shadow-uidmap libsubid ${VIRTUAL-RUNTIME_update-alternatives} ${ROOTFS_BOOTSTRAP_INSTALL}"
 
 # packages to install from features
 FEATURE_INSTALL = "${@' '.join(oe.packagegroup.required_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
diff --git a/meta/recipes-extended/shadow/shadow_4.20.3.bb b/meta/recipes-extended/shadow/shadow_4.20.3.bb
index 683a284aad13..c1e621288ac3 100644
--- a/meta/recipes-extended/shadow/shadow_4.20.3.bb
+++ b/meta/recipes-extended/shadow/shadow_4.20.3.bb
@@ -174,7 +174,7 @@  do_install:append:class-target() {
 	oe_runmake -C ${B}/man DESTDIR="${D}" sbindir="${base_sbindir}" usbindir="${sbindir}" install-man
 }
 
-PACKAGES =+ "${PN}-base"
+PACKAGES =+ "${PN}-base ${PN}-uidmap libsubid"
 FILES:${PN}-base = "\
     ${base_bindir}/login.shadow \
     ${base_bindir}/su.shadow \
@@ -186,6 +186,21 @@  FILES:${PN}-base = "\
 "
 RDEPENDS:${PN} += "${PN}-base"
 
+# The subordinate id tools, on their own for images that need user namespaces
+# without the rest of shadow's setuid tools - Debian's uidmap and libsubid.
+FILES:${PN}-uidmap = "\
+    ${bindir}/newuidmap \
+    ${bindir}/newgidmap \
+    ${bindir}/getsubids \
+    ${sysconfdir}/subuid \
+    ${sysconfdir}/subgid \
+"
+RDEPENDS:${PN} += "${PN}-uidmap"
+
+FILES:libsubid = "${libdir}/libsubid.so.*"
+# A stable name, so ROOTFS_RO_UNNEEDED can list it across soname bumps.
+DEBIAN_NOAUTONAME:libsubid = "1"
+
 inherit update-alternatives
 
 ALTERNATIVE_PRIORITY = "200"