Skip to contentSkip to conversation

chrony: Fix privdrop packageconfig

PATCH New [email protected] 1 participant 1 message Aug 25, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 chrony: Fix privdrop packageconfig

From: Easwar Hariharan <[email protected]>

To drop root privileges on Linux-based systems, chrony requires a standard user to switch to and the use of capabilities. Fix up the privdrop packageconfig to account for this.

---
 meta-networking/recipes-support/chrony/chrony_4.1.bb | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
meta-networking/recipes-support/chrony/chrony_4.1.bb +10 -1
index 6a450c3..f009bae 100644
@@ -47,6 +47,11 @@ DEPENDS = "pps-tools"
 #       chrony does not use GNU Autotools.
 inherit update-rc.d systemd
 
+# Add chronyd user if privdrop packageconfig is selected
+inherit ${@bb.utils.contains('PACKAGECONFIG', 'privdrop', 'useradd', '', d)}
+USERADD_PACKAGES = "${@bb.utils.contains('PACKAGECONFIG', 'privdrop', '${PN}', '', d)}"
+USERADD_PARAM_${PN} += "${@bb.utils.contains('PACKAGECONFIG', 'privdrop', '--system -d / -M --shell /bin/nologin chronyd;', '', d)}"
+
 # Configuration options:
 # - For command line editing support in chronyc, you may specify either
 #   'editline' or 'readline' but not both.  editline is smaller, but
@@ -68,7 +73,7 @@ PACKAGECONFIG ??= "editline \
 PACKAGECONFIG[readline] = "--without-editline,--without-readline,readline"
 PACKAGECONFIG[editline] = ",--without-editline,libedit"
 PACKAGECONFIG[sechash] = "--without-tomcrypt,--disable-sechash,nss"
-PACKAGECONFIG[privdrop] = ",--disable-privdrop,libcap"
+PACKAGECONFIG[privdrop] = "--with-libcap,--disable-privdrop --without-libcap,libcap"
 PACKAGECONFIG[scfilter] = "--enable-scfilter,--without-seccomp,libseccomp"
 PACKAGECONFIG[ipv6] = ",--disable-ipv6,"
 PACKAGECONFIG[nss] = "--with-nss,--without-nss,nss"
@@ -97,6 +102,10 @@ do_install() {
     # Config file
     install -d ${D}${sysconfdir}
     install -m 644 ${WORKDIR}/chrony.conf ${D}${sysconfdir}
+    if ${@bb.utils.contains('PACKAGECONFIG', 'privdrop', 'true', 'false', d)}; then
+        echo "# Define user to drop to after dropping root privileges" >> ${D}${sysconfdir}/chrony.conf
+        echo "user chronyd" >> ${D}${sysconfdir}/chrony.conf
+    fi
 
     # System V init script
     install -d ${D}${sysconfdir}/init.d
Signature · 1 line
1.8.3.1