summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe/rootfs-postcommands.bbclass
diff options
context:
space:
mode:
authorPeter Bergin <peter@berginkonsult.se>2022-09-05 20:40:40 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-09-08 14:59:39 +0100
commitb8dd4aaf223852d74b3fbaa4550eb3cc22ba324b (patch)
treed28b46181e0b0d9d1f526bdd7ddc820e7c20dbf7 /meta/classes-recipe/rootfs-postcommands.bbclass
parent912b35e6e6df1e904cf9f4296d242a07943cf7b3 (diff)
downloadpoky-b8dd4aaf223852d74b3fbaa4550eb3cc22ba324b.tar.gz
rootfs-postcommands.bbclass: avoid moving ssh host keys if etc is writable
When using IMAGE_FEATURE read-only-rootfs ssh host keys are moved to volatile storage. If the feature overlayfs-etc is used in addition to read-only-rootfs /etc is writable and the move is not wanted. But in the case also the IMAGE_FEATURE stateless-rootfs is used the keys will be moved as storage of keys should not be wanted in a stateless-rootfs. This change only takes effect in the case IMAGE_FEATURE contains read-only-rootfs. In adddition the following cases are handled: IMAGE_FEATURES = "read-only-rootfs" --> ssh keys/config handled as ro root IMAGE_FEATURES = "read-only-rootfs overlayfs-etc" --> ssh keys/config handled as rw root IMAGE_FEATURES = "read-only-rootfs stateless-rootfs" --> ssh keys/config handled as ro root IMAGE_FEATURES = "read-only-rootfs overlayfs-etc stateless-rootfs" --> ssh keys/config handled as ro root (From OE-Core rev: d2ad7aa1f2153955adc044ea4eb11c48086a01d1) Signed-off-by: Peter Bergin <peter@berginkonsult.se> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-recipe/rootfs-postcommands.bbclass')
-rw-r--r--meta/classes-recipe/rootfs-postcommands.bbclass30
1 files changed, 17 insertions, 13 deletions
diff --git a/meta/classes-recipe/rootfs-postcommands.bbclass b/meta/classes-recipe/rootfs-postcommands.bbclass
index 215e38e33d..74601f0829 100644
--- a/meta/classes-recipe/rootfs-postcommands.bbclass
+++ b/meta/classes-recipe/rootfs-postcommands.bbclass
@@ -22,7 +22,7 @@ ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'deb
22# Create /etc/timestamp during image construction to give a reasonably sane default time setting 22# Create /etc/timestamp during image construction to give a reasonably sane default time setting
23ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp; " 23ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp; "
24 24
25# Tweak the mount options for rootfs in /etc/fstab if read-only-rootfs is enabled 25# Tweak files in /etc if read-only-rootfs is enabled
26ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_rootfs_hook; ", "",d)}' 26ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_rootfs_hook; ", "",d)}'
27 27
28# We also need to do the same for the kernel boot parameters, 28# We also need to do the same for the kernel boot parameters,
@@ -111,20 +111,24 @@ read_only_rootfs_hook () {
111 # If we're using openssh and the /etc/ssh directory has no pre-generated keys, 111 # If we're using openssh and the /etc/ssh directory has no pre-generated keys,
112 # we should configure openssh to use the configuration file /etc/ssh/sshd_config_readonly 112 # we should configure openssh to use the configuration file /etc/ssh/sshd_config_readonly
113 # and the keys under /var/run/ssh. 113 # and the keys under /var/run/ssh.
114 if [ -d ${IMAGE_ROOTFS}/etc/ssh ]; then 114 # If overlayfs-etc is used this is not done as /etc is treated as writable
115 if [ -e ${IMAGE_ROOTFS}/etc/ssh/ssh_host_rsa_key ]; then 115 # If stateless-rootfs is enabled this is always done as we don't want to save keys then
116 echo "SYSCONFDIR=\${SYSCONFDIR:-/etc/ssh}" >> ${IMAGE_ROOTFS}/etc/default/ssh 116 if ${@ 'true' if not bb.utils.contains('IMAGE_FEATURES', 'overlayfs-etc', True, False, d) or bb.utils.contains('IMAGE_FEATURES', 'stateless-rootfs', True, False, d) else 'false'}; then
117 echo "SSHD_OPTS=" >> ${IMAGE_ROOTFS}/etc/default/ssh 117 if [ -d ${IMAGE_ROOTFS}/etc/ssh ]; then
118 else 118 if [ -e ${IMAGE_ROOTFS}/etc/ssh/ssh_host_rsa_key ]; then
119 echo "SYSCONFDIR=\${SYSCONFDIR:-/var/run/ssh}" >> ${IMAGE_ROOTFS}/etc/default/ssh 119 echo "SYSCONFDIR=\${SYSCONFDIR:-/etc/ssh}" >> ${IMAGE_ROOTFS}/etc/default/ssh
120 echo "SSHD_OPTS='-f /etc/ssh/sshd_config_readonly'" >> ${IMAGE_ROOTFS}/etc/default/ssh 120 echo "SSHD_OPTS=" >> ${IMAGE_ROOTFS}/etc/default/ssh
121 else
122 echo "SYSCONFDIR=\${SYSCONFDIR:-/var/run/ssh}" >> ${IMAGE_ROOTFS}/etc/default/ssh
123 echo "SSHD_OPTS='-f /etc/ssh/sshd_config_readonly'" >> ${IMAGE_ROOTFS}/etc/default/ssh
124 fi
121 fi 125 fi
122 fi
123 126
124 # Also tweak the key location for dropbear in the same way. 127 # Also tweak the key location for dropbear in the same way.
125 if [ -d ${IMAGE_ROOTFS}/etc/dropbear ]; then 128 if [ -d ${IMAGE_ROOTFS}/etc/dropbear ]; then
126 if [ ! -e ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key ]; then 129 if [ ! -e ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key ]; then
127 echo "DROPBEAR_RSAKEY_DIR=/var/lib/dropbear" >> ${IMAGE_ROOTFS}/etc/default/dropbear 130 echo "DROPBEAR_RSAKEY_DIR=/var/lib/dropbear" >> ${IMAGE_ROOTFS}/etc/default/dropbear
131 fi
128 fi 132 fi
129 fi 133 fi
130 134