rootfs-postcommands: Add a few debug tweaks for systemd
PATCH 1/1 rootfs-postcommands: Add a few debug tweaks for systemd
Configure the systemd emergency service to not ask for a password when the debug-tweaks or empty-root-password image feature are enabled. Also enable all the sysrq commands when debug-tweaks is set as systemd only allow the sync command per default.
To avoid the need for over complex expressions when adding systemd specific tweak a new variable called SYSTEMD_ROOTFS_POSTPROCESS_COMMAND, is introduced to collect the systemd specific post commands.
--- meta/classes/rootfs-postcommands.bbclass | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
meta/classes/rootfs-postcommands.bbclass +31 -0
@@ -17,6 +17,15 @@ ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp; " # Tweak the mount options for rootfs in /etc/fstab if read-only-rootfs is enabled ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_rootfs_hook; ", "",d)}' +# Disable password in systemd emergency mode if debug-tweaks or empty-root-password is enabled +SYSTEMD_ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'empty-root-password' ], "systemd_emergency_no_password; ", "",d)}' + +# Enable sysrq on systemd distro if debug-tweaks is enabled +SYSTEMD_ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", 'debug-tweaks', "systemd_enable_sysrq; ", "",d)}' + +# Add the systemd specific post process commands +ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd", "${SYSTEMD_ROOTFS_POSTPROCESS_COMMAND}", "",d)}' + # We also need to do the same for the kernel boot parameters, # otherwise kernel or initramfs end up mounting the rootfs read/write # (the default) if supported by the underlying storage.
@@ -153,6 +162,17 @@ zap_empty_root_password () { fi } +# +# Add a systemd config fragment to disable password for the emergency mode +# +systemd_emergency_no_password () { + mkdir -p ${IMAGE_ROOTFS}${systemd_unitdir}/system/emergency.service.d + cat > ${IMAGE_ROOTFS}${systemd_unitdir}/system/emergency.service.d/no-password.conf <<EOF +[Service] +Environment=SYSTEMD_SULOGIN_FORCE=1 +EOF +} + # # allow dropbear/openssh to accept logins from accounts with an empty password string #
@@ -221,6 +241,17 @@ set_systemd_default_target () { fi } +# +# Enable sysrq on systemd distro +# +systemd_enable_sysrq () { + mkdir -p ${IMAGE_ROOTFS}${libdir}/sysctl.d + cat > ${IMAGE_ROOTFS}${libdir}/sysctl.d/90-enable-sysrq.conf <<EOF +# Allow all sysrq when debugging is enabled +kernel.sysrq = 1 +EOF +} + # If /var/volatile is not empty, we have seen problems where programs such as the # journal make assumptions based on the contents of /var/volatile. The journal # would then write to /var/volatile before it was mounted, thus hiding the
Signature · 1 line
2.25.1
Quoted 5 lines · Alban Bedel
Configure the systemd emergency service to not ask for a password when the debug-tweaks or empty-root-password image feature are enabled. Also enable all the sysrq commands when debug-tweaks is set as systemd only allow the sync command per default.
Quoted 8 lines
To avoid the need for over complex expressions when adding systemd specific tweak a new variable called
SYSTEMD_ROOTFS_POSTPROCESS_COMMAND, is introduced to collect the systemd specific post commands.Signed-off-by Alban Bedel <[email protected]>--- meta/classes/rootfs-postcommands.bbclass | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
I think the idea here is good but to merge there are a couple of tweaks needed.
Firstly, our plan is to move away from debug-tweaks to more specifically named options. "systemd-debug-insecure" might be a better name. We want a slightly scary name to remind people that this is not something to enable on production images. Our plan is to split debug- tweaks into similarly named options.
Secondly, you can do:
${@bb.utils.contains("IMAGE_FEATURES", ['debug-tweaks', 'systemd'], "systemd_enable_sysrq; ", "",d)}
so I'd prefer to do that than have a specific systemd variable there.
Cheers,
Richard
Quoted 58 lines
meta/classes/rootfs-postcommands.bbclass +31
-0@@ -17,6 +17,15 @@ ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp; " # Tweak the mount options for rootfs in /etc/fstab if read-only-rootfs is enabled ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_rootfs_hook; ", "",d)}' +# Disable password in systemd emergency mode if debug-tweaks or empty-root-password is enabled +SYSTEMD_ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'empty-root-password' ], "systemd_emergency_no_password; ", "",d)}' + +# Enable sysrq on systemd distro if debug-tweaks is enabled +SYSTEMD_ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", 'debug-tweaks', "systemd_enable_sysrq; ", "",d)}' + +# Add the systemd specific post process commands +ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd", "${SYSTEMD_ROOTFS_POSTPROCESS_COMMAND}", "",d)}' + # We also need to do the same for the kernel boot parameters, # otherwise kernel or initramfs end up mounting the rootfs read/write # (the default) if supported by the underlying storage.@@ -153,6 +162,17 @@ zap_empty_root_password () { fi } +# +# Add a systemd config fragment to disable password for the emergency mode +# +systemd_emergency_no_password () { + mkdir -p ${IMAGE_ROOTFS}${systemd_unitdir}/system/emergency.service.d + cat > ${IMAGE_ROOTFS}${systemd_unitdir}/system/emergency.service.d/no-password.conf <<EOF +[Service] +Environment=SYSTEMD_SULOGIN_FORCE=1 +EOF +} + # # allow dropbear/openssh to accept logins from accounts with an empty password string #@@ -221,6 +241,17 @@ set_systemd_default_target () { fi } +# +# Enable sysrq on systemd distro +# +systemd_enable_sysrq () { + mkdir -p ${IMAGE_ROOTFS}${libdir}/sysctl.d + cat > ${IMAGE_ROOTFS}${libdir}/sysctl.d/90-enable-sysrq.conf <<EOF +# Allow all sysrq when debugging is enabled +kernel.sysrq = 1 +EOF +} + # If /var/volatile is not empty, we have seen problems where programs such as the # journal make assumptions based on the contents of /var/volatile. The journal # would then write to /var/volatile before it was mounted, thus hiding the