openssh: Atomically generate host keys
PATCH 1/1 openssh: Atomically generate host keys
Generating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
--- meta/recipes-connectivity/openssh/openssh/init | 21 ++++------------ .../openssh/openssh/sshd-check-key | 28 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 16 ++++--------- meta/recipes-connectivity/openssh/openssh_7.4p1.bb | 8 +++++++ 4 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-key
meta/recipes-connectivity/openssh/openssh/init +4 -17
@@ -45,23 +45,10 @@ check_config() { } check_keys() { - # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +28 -0
@@ -0,0 +1,28 @@ +#! /bin/sh +set -e + +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1; +fi + +if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Sync to ensure data is written to temp file before renaming + sync + + # Move (Atomically rename) files + # Rename the .pub file first, since the check that triggers a + # key generation is based on the private file. + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + sync + + mv -f "${NAME}.tmp" "${NAME}" + sync +fi +
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +4 -12
@@ -1,22 +1,14 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 Type=oneshot RemainAfterExit=yes
meta/recipes-connectivity/openssh/openssh_7.4p1.bb +8 -0
@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"
@@ -124,7 +125,14 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -d 644 ${D}${libexecdir}/${BPN} + install -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN} } do_install_ptest () {
Signature · 1 line
2.9.3
(No subject)
No need to create a directory name "644"
PATCH v2 1/1 openssh: Atomically generate host keys
Generating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
--- meta/recipes-connectivity/openssh/openssh/init | 21 ++++------------ .../openssh/openssh/sshd-check-key | 28 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 16 ++++--------- meta/recipes-connectivity/openssh/openssh_7.4p1.bb | 8 +++++++ 4 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-key
meta/recipes-connectivity/openssh/openssh/init +4 -17
@@ -45,23 +45,10 @@ check_config() { } check_keys() { - # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +28 -0
@@ -0,0 +1,28 @@ +#! /bin/sh +set -e + +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1; +fi + +if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Sync to ensure data is written to temp file before renaming + sync + + # Move (Atomically rename) files + # Rename the .pub file first, since the check that triggers a + # key generation is based on the private file. + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + sync + + mv -f "${NAME}.tmp" "${NAME}" + sync +fi +
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +4 -12
@@ -1,22 +1,14 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 Type=oneshot RemainAfterExit=yes
meta/recipes-connectivity/openssh/openssh_7.4p1.bb +8 -0
@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"
@@ -124,7 +125,14 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -d ${D}${libexecdir}/${BPN} + install -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN} } do_install_ptest () {
Signature · 1 line
2.9.3
Could I get a review of this? I'm somewhat new to submitting patches, so if I'm missing something I probably don't realize it, any feedback is appreciated.
Thanks,
Joshua Watt
Quoted 140 lines · Joshua Watt
Generating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
Signed-off-by Joshua Watt <[email protected]>--- meta/recipes-connectivity/openssh/openssh/init | 21 ++++------------ .../openssh/openssh/sshd-check-key | 28 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 16 ++++--------- meta/recipes-connectivity/openssh/openssh_7.4p1.bb | 8 +++++++ 4 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-keymeta/recipes-connectivity/openssh/openssh/init +4
-17@@ -45,23 +45,10 @@ check_config() { } check_keys() { - # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +28
-0@@ -0,0 +1,28 @@ +#! /bin/sh +set -e + +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1; +fi + +if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Sync to ensure data is written to temp file before renaming + sync + + # Move (Atomically rename) files + # Rename the .pub file first, since the check that triggers a + # key generation is based on the private file. + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + sync + + mv -f "${NAME}.tmp" "${NAME}" + sync +fi +meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +4
-12@@ -1,22 +1,14 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 Type=oneshot RemainAfterExit=yesmeta/recipes-connectivity/openssh/openssh_7.4p1.bb +8
-1@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"@@ -124,7 +125,14 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -d 644 ${D}${libexecdir}/${BPN} + install -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN} } do_install_ptest () { --2.9.3
Quoted 8 lines · Joshua Watt
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +6
-0+if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Sync to ensure data is written to temp file before renaming + sync
meta/recipes-connectivity/openssh/openssh/sshd-check-key line 27
Quoted 10 lines
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +10
-0+ + # Move (Atomically rename) files + # Rename the .pub file first, since the check that triggers a + # key generation is based on the private file. + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + sync + + mv -f "${NAME}.tmp" "${NAME}" + sync +fi
All of these syncs seem quite enthusiastic, are they really needed? Writing the file to a temporary name and then mving it to the real name should result in either no file or a complete file in the event of power loss, surely?
Quoted 8 lines
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-0@@ -1,22 +1,14 @@ [Unit] Description=OpenSSH Key Generation
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service line 4
Quoted 10 lines
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-8RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key
Can you not continue to use ConditionPathExists to only run this unit if it needs to run? You can prepend the argument with | to make them logical OR instead of logical AND, if I'm reading this documentation correctly.
Ross
Quoted 17 lines · Ross
Quoted 15 lines · Joshua Watt
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +14
-0+if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Sync to ensure data is written to temp file before renaming + sync + + # Move (Atomically rename) files + # Rename the .pub file first, since the check that triggers a + # key generation is based on the private file. + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + sync + + mv -f "${NAME}.tmp" "${NAME}"
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ sync +fiAll of these syncs seem quite enthusiastic, are they really needed? Writing the file to a temporary name and then mving it to the real name should result in either no file or a complete file in the event of power loss, surely?
My understanding (and observation) of most journal file systems is that only metadata (i.e. directory entries and such) are journaled in typical usage. The first sync is necessary in this case to ensure that the actual file data gets put on the disk before we rename the files, otherwise in the event of interruption journaled rename might get replayed but have garbage data. The second one is more of a "force operation order" sync to make sure the public file is written before the private one, as a reordering would cause problems. The last sync is the most optional, but I've seen it take minutes for disk to sync contents if no one calls "sync", so it is very possible that all our work of regenerating keys would be for naught if power is interrupted in the meantime.
I think some of these syncs can be removed. Namely, the first and third one. The second one needs to be there, but can server double duty of syncing data to disk and enforcing the order between the public and private rename. It does mean we could get a state where the public key exists but is garbage, but this should be OK because the private key won't exist and it would be regenerated.
The third sync can be removed and I can put one final sync at the end after all keys are generated to ensure we won't go through all the effort of regenerating the (last) key again in the event of interruption shortly after, unless you would prefer I didn't.
Quoted 16 lines
Quoted 16 lines
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-5@@ -1,22 +1,14 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key
Quoted 8 lines
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service line 11
Quoted 3 lines
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-3-ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_keyCan you not continue to use ConditionPathExists to only run this unit if it needs to run? You can prepend the argument with | to make them logical OR instead of logical AND, if I'm reading this documentation correctly.
I will try that. I wasn't aware that was an option since systemd conf files are somewhat new to me.
Quoted 2 lines
Ross
Quoted 47 lines · Joshua Watt
Quoted 17 lines · Ross
Quoted 15 lines · Joshua Watt
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +14
-0+if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Sync to ensure data is written to temp file before renaming + sync + + # Move (Atomically rename) files + # Rename the .pub file first, since the check that triggers a + # key generation is based on the private file. + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + sync + + mv -f "${NAME}.tmp" "${NAME}"Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ sync +fiAll of these syncs seem quite enthusiastic, are they really needed? Writing the file to a temporary name and then mving it to the real name should result in either no file or a complete file in the event of power loss, surely?
My understanding (and observation) of most journal file systems is that only metadata (i.e. directory entries and such) are journaled in typical usage. The first sync is necessary in this case to ensure that the actual file data gets put on the disk before we rename the files, otherwise in the event of interruption journaled rename might get replayed but have garbage data. The second one is more of a "force operation order" sync to make sure the public file is written before the private one, as a reordering would cause problems. The last sync is the most optional, but I've seen it take minutes for disk to sync contents if no one calls "sync", so it is very possible that all our work of regenerating keys would be for naught if power is interrupted in the meantime.
I think some of these syncs can be removed. Namely, the first and third one. The second one needs to be there, but can server double duty of syncing data to disk and enforcing the order between the public and private rename. It does mean we could get a state where the public key exists but is garbage, but this should be OK because the private key won't exist and it would be regenerated.
Quoted 5 lines
The third sync can be removed and I can put one final sync at the end after all keys are generated to ensure we won't go through all the effort of regenerating the (last) key again in the event of interruption shortly after, unless you would prefer I didn't.
The typical convention for this is,
1. Update file data.
2. sync file
3. sync containing directory
4. mv file to new location
5. sync directory containing new file (although I've seen this step left out before)
https://lwn.net/Articles/457672/ is a good example which is linked from https://lwn.net/Articles/457667/
But one of the important parts vs your code, is also that the example is only calling sync on the files/directory needed, vs calling "sync" with no arguments which is going to cause all data in all filesystem caches to be flushed.
Quoted 30 lines
Quoted 16 lines
Quoted 16 lines
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-5@@ -1,22 +1,14 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_keyQuoted 8 lines
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service line 11
Quoted 3 lines
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-3-ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_keyCan you not continue to use ConditionPathExists to only run this unit if it needs to run? You can prepend the argument with | to make them logical OR instead of logical AND, if I'm reading this documentation correctly.
I will try that. I wasn't aware that was an option since systemd conf files are somewhat new to me.
Quoted 2 lines
Ross
Quoted 69 lines · Randy Witt
Quoted 53 lines · Joshua Watt
Quoted 20 lines · Ross
Quoted 17 lines · Joshua Watt
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +15
-0+if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Sync to ensure data is written to temp file before renaming + sync + + # Move (Atomically rename) files + # Rename the .pub file first, since the check that triggers a + # key generation is based on the private file. + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + sync + + mv -f "${NAME}.tmp" "${NAME}" + syncQuoted 8 lines
Quoted 2 lines
+fi
All of these syncs seem quite enthusiastic, are they really needed? Writing
the file to a temporary name and then mving it to the real name should result in either no file or a complete file in the event of power loss, surely?My understanding (and observation) of most journal file systems is that only metadata (i.e. directory entries and such) are journaled in typical usage. The first sync is necessary in this case to ensure that the actual file data gets put on the disk before we rename the files, otherwise in the event of interruption journaled rename might get replayed but have garbage data. The second one is more of a "force operation order" sync to make sure the public file is written before the private one, as a reordering would cause problems. The last sync is the most optional, but I've seen it take minutes for disk to sync contents if no one calls "sync", so it is very possible that all our work of regenerating keys would be for naught if power is interrupted in the meantime.
I think some of these syncs can be removed. Namely, the first and third one. The second one needs to be there, but can server double duty of syncing data to disk and enforcing the order between the public and private rename. It does mean we could get a state where the public key exists but is garbage, but this should be OK because the private key won't exist and it would be regenerated.
Quoted 5 lines
The third sync can be removed and I can put one final sync at the end after all keys are generated to ensure we won't go through all the effort of regenerating the (last) key again in the event of interruption shortly after, unless you would prefer I didn't.
The typical convention for this is,
1. Update file data.
2. sync file
3. sync containing directory
4. mv file to new location
5. sync directory containing new file (although I've seen this step left out before)
Quoted 7 lines
https://lwn.net/Articles/457672/ is a good example which is linked from
https://lwn.net/Articles/457667/But one of the important parts vs your code, is also that the example is only calling sync on the files/directory needed, vs calling "sync" with no arguments which is going to cause all data in all filesystem caches to be flushed.
Ah, OK. That makes sense, I will update sync to specify the files/directory explicitly.
Quoted 39 lines
Quoted 37 lines
Quoted 25 lines
Quoted 12 lines
diff --git a/meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service b/meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service index 148e6ad..af56404 100644
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-0@@ -1,22 +1,14 @@ [Unit]meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service line 11
Quoted 10 lines
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-8Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_keyQuoted 5 lines
Can you not continue to use ConditionPathExists to only run this unit if it
needs to run? You can prepend the argument with | to make them logical OR
instead of logical AND, if I'm reading this documentation correctly.I will try that. I wasn't aware that was an option since systemd conf files are somewhat new to me.
Quoted 2 lines
Ross
Quoted 74 lines · Joshua Watt
Quoted 72 lines · Randy Witt
Quoted 53 lines · Joshua Watt
Quoted 20 lines · Ross
Quoted 17 lines · Joshua Watt
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +15
-0+if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Sync to ensure data is written to temp file before renaming + sync + + # Move (Atomically rename) files + # Rename the .pub file first, since the check that triggers a + # key generation is based on the private file. + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + sync + + mv -f "${NAME}.tmp" "${NAME}" + syncQuoted 8 lines
Quoted 2 lines
+fi
All of these syncs seem quite enthusiastic, are they really needed? Writing
the file to a temporary name and then mving it to the real name should result in either no file or a complete file in the event of power loss, surely?My understanding (and observation) of most journal file systems is that only metadata (i.e. directory entries and such) are journaled in typical usage. The first sync is necessary in this case to ensure that the actual file data gets put on the disk before we rename the files, otherwise in the event of interruption journaled rename might get replayed but have garbage data. The second one is more of a "force operation order" sync to make sure the public file is written before the private one, as a reordering would cause problems. The last sync is the most optional, but I've seen it take minutes for disk to sync contents if no one calls "sync", so it is very possible that all our work of regenerating keys would be for naught if power is interrupted in the meantime.
I think some of these syncs can be removed. Namely, the first and third one. The second one needs to be there, but can server double duty of syncing data to disk and enforcing the order between the public and private rename. It does mean we could get a state where the public key exists but is garbage, but this should be OK because the private key won't exist and it would be regenerated.
Quoted 5 lines
The third sync can be removed and I can put one final sync at the end after all keys are generated to ensure we won't go through all the effort of regenerating the (last) key again in the event of interruption shortly after, unless you would prefer I didn't.
The typical convention for this is,
1. Update file data.
2. sync file
3. sync containing directory
4. mv file to new location
5. sync directory containing new file (although I've seen this step left out before)https://lwn.net/Articles/457672/ is a good example which is linked from
https://lwn.net/Articles/457667/
Quoted 7 lines
Quoted 4 lines
But one of the important parts vs your code, is also that the example is only calling sync on the files/directory needed, vs calling "sync" with no arguments which is going to cause all data in all filesystem caches to be flushed.
Ah, OK. That makes sense, I will update sync to specify the files/directory explicitly.
FWIW, I did some tests on the sync behavior:
It appears that older versions of the sync command ignore any arguments and just call sync(). From Ubuntu 14.04:
$ strace sync foo ... write(2, "sync: ", 6sync: ) = 6 write(2, "ignoring all arguments", 22) = 22 write(2, "\n", 1) = 1 sync() = 0 ...
The same is true for the (default) busybox version of sync on master (again verified with strace), but it doesn't complain nosily about it.
I looked at the coreutils code, and sync was changed to respect arguments in January of 2015 (8b2bf5295f353016d4f5e6a2317d55b6a8e7fd00) and only call fsync() on the provided arguments (if any are provided).
Either way, adding the arguments to the sync call in my patch won't hurt because it is forward compatible, even though it won't be optimally efficient currently because the sync command currently simply calls sync()
Quoted 40 lines
Quoted 40 lines
Quoted 38 lines
Quoted 26 lines
Quoted 13 lines
diff --git a/meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service b/meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service index 148e6ad..af56404 100644
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-0@@ -1,22 +1,14 @@ [Unit]meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service line 11
Quoted 10 lines
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-8Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_keyQuoted 5 lines
Can you not continue to use ConditionPathExists to only run this unit if it
needs to run? You can prepend the argument with | to make them logical OR
instead of logical AND, if I'm reading this documentation correctly.I will try that. I wasn't aware that was an option since systemd conf files are somewhat new to me.
Quoted 2 lines
Ross
Quoted 126 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Joshua Watt
Sent: den 23 maj 2017 21:57
To: Randy Witt <[email protected]>
Cc: OE-core <[email protected]>
Subject: Re: [OE-core] [PATCH] openssh: Atomically generate host keysQuoted 5 lines · Joshua Watt
Quoted 3 lines · Randy Witt
Quoted 2 lines · Joshua Watt
On Tue, May 23, 2017 at 9:37 AM, Burton, Ross
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines · wrote:
meta/recipes-connectivity/openssh/openssh/sshd-check-key
Quoted 7 lines · Joshua Watt
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +5
-0+if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Sync to ensure data is written to temp file beforerenaming
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
meta/recipes-connectivity/openssh/openssh/sshd-check-key
Quoted 4 lines
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +4
-0+ sync + + # Move (Atomically rename) files + # Rename the .pub file first, since the check that triggersa
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
meta/recipes-connectivity/openssh/openssh/sshd-check-key line 27
Quoted 8 lines
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +7
-0+ # key generation is based on the private file. + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + sync + + mv -f "${NAME}.tmp" "${NAME}" + sync +fiAll of these syncs seem quite enthusiastic, are they really
needed?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Writing
the file to a temporary name and then mving it to the real nameshould
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
result in either no file or a complete file in the event of power
loss,
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
surely?
My understanding (and observation) of most journal file systems is that only metadata (i.e. directory entries and such) are journaled
in
Quoted 1 line
Quoted 1 line
Quoted 1 line
typical usage. The first sync is necessary in this case to ensure
that
Quoted 1 line
Quoted 1 line
Quoted 1 line
the actual file data gets put on the disk before we rename the
files,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
otherwise in the event of interruption journaled rename might get replayed but have garbage data. The second one is more of a "force operation order" sync to make sure the public file is written
before
Quoted 1 line
Quoted 1 line
Quoted 1 line
the private one, as a reordering would cause problems. The last
sync
Quoted 1 line
Quoted 1 line
Quoted 1 line
is the most optional, but I've seen it take minutes for disk to
sync
Quoted 1 line
Quoted 1 line
Quoted 1 line
contents if no one calls "sync", so it is very possible that all
our
Quoted 1 line
Quoted 1 line
Quoted 1 line
work of regenerating keys would be for naught if power is
interrupted
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
in the meantime.
I think some of these syncs can be removed. Namely, the first and third one. The second one needs to be there, but can server double duty of syncing data to disk and enforcing the order between the public and private rename. It does mean we could get a state where
the
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
public key exists but is garbage, but this should be OK because the private key won't exist and it would be regenerated.
The third sync can be removed and I can put one final sync at the
end
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
after all keys are generated to ensure we won't go through all the effort of regenerating the (last) key again in the event of interruption shortly after, unless you would prefer I didn't.
Quoted 7 lines
Quoted 7 lines
The typical convention for this is,
1. Update file data.
2. sync file
3. sync containing directory
4. mv file to new location
5. sync directory containing new file (although I've seen this stepleft out
Quoted 3 lines
Quoted 3 lines
before)
https://lwn.net/Articles/457672/ is a good example which is linked
from
Quoted 3 lines
Quoted 3 lines
https://lwn.net/Articles/457667/
But one of the important parts vs your code, is also that the
example is
Quoted 1 line
Quoted 1 line
only calling sync on the files/directory needed, vs calling "sync"
with no
Quoted 1 line
Quoted 1 line
arguments which is going to cause all data in all filesystem caches
to be
Quoted 4 lines
Quoted 1 line
flushed.
Ah, OK. That makes sense, I will update sync to specify the files/directory explicitly.
FWIW, I did some tests on the sync behavior:
It appears that older versions of the sync command ignore any arguments and just call
sync(). From Ubuntu 14.04:$ strace sync foo ... write(2, "sync: ", 6sync: ) = 6 write(2, "ignoring all arguments", 22) = 22 write(2, "\n", 1) = 1 sync() = 0 ...
Quoted 2 lines
The same is true for the (default) busybox version of sync on master (again verified with strace), but it doesn't complain nosily about it.
Busybox has a separate fsync applet to do file synchronization, but it is not enabled in the default OE-core configuration...
Quoted 9 lines
I looked at the coreutils code, and sync was changed to respect arguments in January of 2015 (
8b2bf5295f353016d4f5e6a2317d55b6a8e7fd00) and only callfsync()on the provided arguments (if any are provided).Either way, adding the arguments to the sync call in my patch won't hurt because it is forward compatible, even though it won't be optimally efficient currently because the sync command currently simply calls
sync()
//Peter
Quoted 126 lines · Peter Kjellerstedt
Quoted 126 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Joshua Watt
Sent: den 23 maj 2017 21:57
To: Randy Witt <[email protected]>
Cc: OE-core <[email protected]>
Subject: Re: [OE-core] [PATCH] openssh: Atomically generate host keysQuoted 5 lines · Joshua Watt
Quoted 3 lines · Randy Witt
Quoted 2 lines · Joshua Watt
On Tue, May 23, 2017 at 9:37 AM, Burton, Ross
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines · wrote:
Review
Quoted 7 lines · Joshua Watt
(quoted diff) +5
-0+if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Sync to ensure data is written to temp file beforerenaming
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ sync + + # Move (Atomically rename) files + # Rename the .pub file first, since the check that triggersa
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Review
Quoted 8 lines
(quoted diff) +7
-0+ # key generation is based on the private file. + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + sync + + mv -f "${NAME}.tmp" "${NAME}" + sync +fiAll of these syncs seem quite enthusiastic, are they really
needed?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Writing
the file to a temporary name and then mving it to the real nameshould
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
result in either no file or a complete file in the event of power
loss,
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
surely?
My understanding (and observation) of most journal file systems is that only metadata (i.e. directory entries and such) are journaled
in
Quoted 1 line
Quoted 1 line
Quoted 1 line
typical usage. The first sync is necessary in this case to ensure
that
Quoted 1 line
Quoted 1 line
Quoted 1 line
the actual file data gets put on the disk before we rename the
files,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
otherwise in the event of interruption journaled rename might get replayed but have garbage data. The second one is more of a "force operation order" sync to make sure the public file is written
before
Quoted 1 line
Quoted 1 line
Quoted 1 line
the private one, as a reordering would cause problems. The last
sync
Quoted 1 line
Quoted 1 line
Quoted 1 line
is the most optional, but I've seen it take minutes for disk to
sync
Quoted 1 line
Quoted 1 line
Quoted 1 line
contents if no one calls "sync", so it is very possible that all
our
Quoted 1 line
Quoted 1 line
Quoted 1 line
work of regenerating keys would be for naught if power is
interrupted
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
in the meantime.
I think some of these syncs can be removed. Namely, the first and third one. The second one needs to be there, but can server double duty of syncing data to disk and enforcing the order between the public and private rename. It does mean we could get a state where
the
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
public key exists but is garbage, but this should be OK because the private key won't exist and it would be regenerated.
The third sync can be removed and I can put one final sync at the
end
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
after all keys are generated to ensure we won't go through all the effort of regenerating the (last) key again in the event of interruption shortly after, unless you would prefer I didn't.
Quoted 7 lines
Quoted 7 lines
The typical convention for this is,
1. Update file data.
2. sync file
3. sync containing directory
4. mv file to new location
5. sync directory containing new file (although I've seen this stepleft out
Quoted 3 lines
Quoted 3 lines
before)
https://lwn.net/Articles/457672/ is a good example which is linked
from
Quoted 3 lines
Quoted 3 lines
https://lwn.net/Articles/457667/
But one of the important parts vs your code, is also that the
example is
Quoted 1 line
Quoted 1 line
only calling sync on the files/directory needed, vs calling "sync"
with no
Quoted 1 line
Quoted 1 line
arguments which is going to cause all data in all filesystem caches
to be
Quoted 4 lines
Quoted 1 line
flushed.
Ah, OK. That makes sense, I will update sync to specify the files/directory explicitly.
FWIW, I did some tests on the sync behavior:
It appears that older versions of the sync command ignore any arguments and just call
sync(). From Ubuntu 14.04:$ strace sync foo ... write(2, "sync: ", 6sync: ) = 6 write(2, "ignoring all arguments", 22) = 22 write(2, "\n", 1) = 1 sync() = 0 ...
Quoted 5 lines
Quoted 2 lines
The same is true for the (default) busybox version of sync on master (again verified with strace), but it doesn't complain nosily about it.
Busybox has a separate fsync applet to do file synchronization, but it is not enabled in the default OE-core configuration...
Ok. I think for best compatibility I'll just use "sync", as that will always be safe, just not always optimally efficient. I think this is OK, since key generation either only occurs once (r/w rootfs), or once per boot (r/o rootfs).
Quoted 13 lines
Quoted 10 lines
I looked at the coreutils code, and sync was changed to respect arguments in January of 2015 (
8b2bf5295f353016d4f5e6a2317d55b6a8e7fd00) and only callfsync()on the provided arguments (if any are provided).Either way, adding the arguments to the sync call in my patch won't hurt because it is forward compatible, even though it won't be optimally efficient currently because the sync command currently simply calls
sync()//Peter
PATCH v3 1/1 openssh: Atomically generate host keys
Generating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
--- meta/recipes-connectivity/openssh/openssh/init | 21 +++---------- .../openssh/openssh/sshd-check-key | 36 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 24 +++++++-------- meta/recipes-connectivity/openssh/openssh_7.5p1.bb | 8 +++++ 4 files changed, 60 insertions(+), 29 deletions(-) create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-key
meta/recipes-connectivity/openssh/openssh/init +4 -17
@@ -45,23 +45,10 @@ check_config() { } check_keys() { - # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +36 -0
@@ -0,0 +1,36 @@ +#! /bin/sh +set -e + +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1; +fi + +DIR="$(dirname "$NAME")" + +if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Move (Atomically rename) files + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + + # This sync does double duty: Ensuring that the data in the temporary + # private key file is on disk before the rename, and ensuring that the + # public key rename is completed before the private key rename, since we + # switch on the existence of the private key to trigger key generation. + # This does mean it is possible for the public key to exist, but be garbage + # but this is OK because in that case the private key won't exist and the + # keys will be regenerated. + # + # In the event that sync understands arguments that limit what it tries to + # fsync(), we provided them. If it does not, it will simply call sync() + # which is just as well + sync "${NAME}.pub" "$DIR" "${NAME}.tmp" + + mv -f "${NAME}.tmp" "${NAME}" +fi +
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +12 -12
@@ -1,22 +1,22 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/var/run/ssh/ssh_host_rsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_dsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 Type=oneshot RemainAfterExit=yes
meta/recipes-connectivity/openssh/openssh_7.5p1.bb +8 -0
@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"
@@ -124,7 +125,14 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -d ${D}${libexecdir}/${BPN} + install -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN} } do_install_ptest () {
Signature · 1 line
2.9.3
Quoted 73 lines · Joshua Watt
Generating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
--- meta/recipes-connectivity/openssh/openssh/init | 21 +++---------- .../openssh/openssh/sshd-check-key | 36 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 24 +++++++-------- meta/recipes-connectivity/openssh/openssh_7.5p1.bb | 8 +++++ 4 files changed, 60 insertions(+), 29 deletions(-)create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-key
meta/recipes-connectivity/openssh/openssh/init +4
-17@@ -45,23 +45,10 @@ check_config() { } check_keys() { - # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +24
-0@@ -0,0 +1,36 @@ +#! /bin/sh +set -e + +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1; +fi + +DIR="$(dirname "$NAME")" + +if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Move (Atomically rename) files + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + + # This sync does double duty: Ensuring that the data in the temporary + # private key file is on disk before the rename, and ensuring that the + # public key rename is completed before the private key rename, since we + # switch on the existence of the private key to trigger key generation.
meta/recipes-connectivity/openssh/openssh/sshd-check-key line 34
Quoted 10 lines
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +10
-0+ # This does mean it is possible for the public key to exist, but be garbage + # but this is OK because in that case the private key won't exist and the + # keys will be regenerated. + # + # In the event that sync understands arguments that limit what it tries to + # fsync(), we provided them. If it does not, it will simply call sync() + # which is just as well + sync "${NAME}.pub" "$DIR" "${NAME}.tmp" + + mv -f "${NAME}.tmp" "${NAME}"
You previously mentioned moving the third, most optional sync to a single sync at the end, but I don't see it at all now. Should there be another sync "$DIR" somewhere in the init script or service file?
Regards,
Ian
Quoted 69 lines
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +2
-0+fi +meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +12
-12@@ -1,22 +1,22 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/var/run/ssh/ssh_host_rsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_dsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 Type=oneshot RemainAfterExit=yesmeta/recipes-connectivity/openssh/openssh_7.5p1.bb +8
-0@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"@@ -124,7 +125,14 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -d ${D}${libexecdir}/${BPN} + install -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN} } do_install_ptest () {
PATCH v4 1/1 openssh: Atomically generate host keys
In reply to Joshua WattGenerating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
--- meta/recipes-connectivity/openssh/openssh/init | 22 +++---------- .../openssh/openssh/sshd-check-key | 36 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 25 +++++++-------- meta/recipes-connectivity/openssh/openssh_7.5p1.bb | 9 ++++++ 4 files changed, 63 insertions(+), 29 deletions(-) create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-key
meta/recipes-connectivity/openssh/openssh/init +5 -17
@@ -45,23 +45,11 @@ check_config() { } check_keys() { - # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 + @BASE_BINDIR@/sync } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +36 -0
@@ -0,0 +1,36 @@ +#! /bin/sh +set -e + +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1; +fi + +DIR="$(dirname "$NAME")" + +if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Move (Atomically rename) files + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + + # This sync does double duty: Ensuring that the data in the temporary + # private key file is on disk before the rename, and ensuring that the + # public key rename is completed before the private key rename, since we + # switch on the existence of the private key to trigger key generation. + # This does mean it is possible for the public key to exist, but be garbage + # but this is OK because in that case the private key won't exist and the + # keys will be regenerated. + # + # In the event that sync understands arguments that limit what it tries to + # fsync(), we provided them. If it does not, it will simply call sync() + # which is just as well + sync "${NAME}.pub" "$DIR" "${NAME}.tmp" + + mv -f "${NAME}.tmp" "${NAME}" +fi +
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +13 -12
@@ -1,22 +1,23 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/var/run/ssh/ssh_host_rsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_dsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 +ExecStart=@BASE_BINDIR@/sync Type=oneshot RemainAfterExit=yes
meta/recipes-connectivity/openssh/openssh_7.5p1.bb +9 -0
@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"
@@ -124,7 +125,15 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + -e 's,@BASE_BINDIR@,${base_bindir},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -d ${D}${libexecdir}/${BPN} + install -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN} } do_install_ptest () {
Signature · 1 line
2.9.3
Quoted 50 lines · Joshua Watt
Generating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
--- meta/recipes-connectivity/openssh/openssh/init | 22 +++---------- .../openssh/openssh/sshd-check-key | 36 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 25 +++++++-------- meta/recipes-connectivity/openssh/openssh_7.5p1.bb | 9 ++++++ 4 files changed, 63 insertions(+), 29 deletions(-) create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-keymeta/recipes-connectivity/openssh/openssh/init +5
-17@@ -45,23 +45,11 @@ check_config() { } check_keys() { - # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 + @BASE_BINDIR@/sync } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +0
-0
meta/recipes-connectivity/openssh/openssh/sshd-check-key line 2
Quoted 2 lines
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +2
-0@@ -0,0 +1,36 @@ +#! /bin/sh +set -e
Is this appropriate for an init script? Aborting on unforeseen errors may be worse than continuing.
meta/recipes-connectivity/openssh/openssh/sshd-check-key line 9
Quoted 6 lines
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +6
-0+NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1;
Remove the stray ";"
meta/recipes-connectivity/openssh/openssh/sshd-check-key line 12
Quoted 3 lines
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +3
-0+fi + +DIR="$(dirname "$NAME")"
This could be moved down so dirname is only called if DIR is going to be used.
Quoted 11 lines
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +11
-0+if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Move (Atomically rename) files + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + + # This sync does double duty: Ensuring that the data in the temporary + # private key file is on disk before the rename, and ensuring that the + # public key rename is completed before the private key rename, since we + # switch on the existence of the private key to trigger key generation.
meta/recipes-connectivity/openssh/openssh/sshd-check-key line 34
Quoted 10 lines
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +10
-0+ # This does mean it is possible for the public key to exist, but be garbage + # but this is OK because in that case the private key won't exist and the + # keys will be regenerated. + # + # In the event that sync understands arguments that limit what it tries to + # fsync(), we provided them. If it does not, it will simply call sync() + # which is just as well + sync "${NAME}.pub" "$DIR" "${NAME}.tmp" + + mv -f "${NAME}.tmp" "${NAME}"
No need for "-f" here as ${NAME} is known not to exist.
Quoted 78 lines
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +2
-0+fi +meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +13
-12@@ -1,22 +1,23 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/var/run/ssh/ssh_host_rsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_dsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 +ExecStart=@BASE_BINDIR@/sync Type=oneshot RemainAfterExit=yesmeta/recipes-connectivity/openssh/openssh_7.5p1.bb +9
-1@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"@@ -124,7 +125,15 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + -e 's,@BASE_BINDIR@,${base_bindir},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -d ${D}${libexecdir}/${BPN} + install -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN} } do_install_ptest () { --2.9.3
--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core
PATCH v5 1/1 openssh: Atomically generate host keys
In reply to Joshua WattGenerating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
--- meta/recipes-connectivity/openssh/openssh/init | 22 +++---------- .../openssh/openssh/sshd-check-key | 36 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 25 +++++++-------- meta/recipes-connectivity/openssh/openssh_7.5p1.bb | 9 ++++++ 4 files changed, 63 insertions(+), 29 deletions(-) create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-key
meta/recipes-connectivity/openssh/openssh/init +5 -17
@@ -45,23 +45,11 @@ check_config() { } check_keys() { - # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 + @BASE_BINDIR@/sync } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +36 -0
@@ -0,0 +1,36 @@ +#! /bin/sh +set -e + +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1; +fi + +DIR="$(dirname "$NAME")" + +if [ ! -f "$NAME" ]; then + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Move (Atomically rename) files + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + + # This sync does double duty: Ensuring that the data in the temporary + # private key file is on disk before the rename, and ensuring that the + # public key rename is completed before the private key rename, since we + # switch on the existence of the private key to trigger key generation. + # This does mean it is possible for the public key to exist, but be garbage + # but this is OK because in that case the private key won't exist and the + # keys will be regenerated. + # + # In the event that sync understands arguments that limit what it tries to + # fsync(), we provided them. If it does not, it will simply call sync() + # which is just as well + sync "${NAME}.pub" "$DIR" "${NAME}.tmp" + + mv -f "${NAME}.tmp" "${NAME}" +fi +
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +13 -12
@@ -1,22 +1,23 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/var/run/ssh/ssh_host_rsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_dsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 +ExecStart=@BASE_BINDIR@/sync Type=oneshot RemainAfterExit=yes
meta/recipes-connectivity/openssh/openssh_7.5p1.bb +9 -0
@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"
@@ -124,7 +125,15 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + -e 's,@BASE_BINDIR@,${base_bindir},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -d ${D}${libexecdir}/${BPN} + install -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN} } do_install_ptest () {
Signature · 1 line
2.9.3
Just a minor comment: there is no need to include any prefix besides [PATCH vN]. Also, patches either go to oe-core or meta-oe, so it makes no sense to send the patch to the oe-core and using the [meta-oe] as prefix.
Leo
Quoted 3 lines · Joshua Watt
Generating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
Quoted 4 lines · Leonardo Sandoval
Just a minor comment: there is no need to include any prefix besides [PATCH vN]. Also, patches either go to oe-core or meta-oe, so it makes no sense to send the patch to the oe-core and using the [meta-oe] as prefix.
Ya, sorry. I was following these directions and didn't read closely enough:
https://www.openembedded.org/wiki/How_to_submit_a_patch_to_OpenEmbedded
Quoted 12 lines
Leo
Quoted 3 lines · Joshua Watt
Generating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
PATCH v6 1/1 openssh: Atomically generate host keys
In reply to Joshua WattGenerating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
--- meta/recipes-connectivity/openssh/openssh/init | 22 ++++---------- .../openssh/openssh/sshd-check-key | 35 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 25 ++++++++-------- meta/recipes-connectivity/openssh/openssh_7.5p1.bb | 9 ++++++ 4 files changed, 62 insertions(+), 29 deletions(-) create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-key
meta/recipes-connectivity/openssh/openssh/init +5 -17
@@ -45,23 +45,11 @@ check_config() { } check_keys() { - # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 + @BASE_BINDIR@/sync } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +35 -0
@@ -0,0 +1,35 @@ +#! /bin/sh +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1 +fi + + +if [ ! -f "$NAME" ]; then + DIR="$(dirname "$NAME")" + + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Move (Atomically rename) files + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + + # This sync does double duty: Ensuring that the data in the temporary + # private key file is on disk before the rename, and ensuring that the + # public key rename is completed before the private key rename, since we + # switch on the existence of the private key to trigger key generation. + # This does mean it is possible for the public key to exist, but be garbage + # but this is OK because in that case the private key won't exist and the + # keys will be regenerated. + # + # In the event that sync understands arguments that limit what it tries to + # fsync(), we provided them. If it does not, it will simply call sync() + # which is just as well + sync "${NAME}.pub" "$DIR" "${NAME}.tmp" + + mv "${NAME}.tmp" "$NAME" +fi +
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +13 -12
@@ -1,22 +1,23 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/var/run/ssh/ssh_host_rsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_dsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 +ExecStart=@BASE_BINDIR@/sync Type=oneshot RemainAfterExit=yes
meta/recipes-connectivity/openssh/openssh_7.5p1.bb +9 -0
@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"
@@ -124,7 +125,15 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + -e 's,@BASE_BINDIR@,${base_bindir},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -d ${D}${libexecdir}/${BPN} + install -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN} } do_install_ptest () {
Signature · 1 line
2.9.4
Quoted 5 lines · Joshua Watt
Generating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
Signed-off-by Joshua Watt <[email protected]>
It does make a lot of sense. The only consideration I have is that this might be a simple rework on the recipe:
install -d ${D}${libexecdir}/${BPN}
install -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN}can be replaced with:
install -Dm 0755 ${WORKDIR}/sshd-check-key${D}${libexecdir}/${BPN}/sshd-check-key
Signature · 3 lines
Otavio Salvador O.S. Systems http://www.ossystems.com.br http://code.ossystems.com.br Mobile: +55 (53) 9981-7854 Mobile: +1 (347) 903-9750
PATCH v7 1/1 openssh: Atomically generate host keys
In reply to Joshua WattGenerating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
--- meta/recipes-connectivity/openssh/openssh/init | 22 ++++---------- .../openssh/openssh/sshd-check-key | 35 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 25 ++++++++-------- meta/recipes-connectivity/openssh/openssh_7.5p1.bb | 8 +++++ 4 files changed, 61 insertions(+), 29 deletions(-) create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-key
meta/recipes-connectivity/openssh/openssh/init +5 -17
@@ -45,23 +45,11 @@ check_config() { } check_keys() { - # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 + @BASE_BINDIR@/sync } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +35 -0
@@ -0,0 +1,35 @@ +#! /bin/sh +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1 +fi + + +if [ ! -f "$NAME" ]; then + DIR="$(dirname "$NAME")" + + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Move (Atomically rename) files + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + + # This sync does double duty: Ensuring that the data in the temporary + # private key file is on disk before the rename, and ensuring that the + # public key rename is completed before the private key rename, since we + # switch on the existence of the private key to trigger key generation. + # This does mean it is possible for the public key to exist, but be garbage + # but this is OK because in that case the private key won't exist and the + # keys will be regenerated. + # + # In the event that sync understands arguments that limit what it tries to + # fsync(), we provided them. If it does not, it will simply call sync() + # which is just as well + sync "${NAME}.pub" "$DIR" "${NAME}.tmp" + + mv "${NAME}.tmp" "$NAME" +fi +
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +13 -12
@@ -1,22 +1,23 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/var/run/ssh/ssh_host_rsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_dsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 +ExecStart=@BASE_BINDIR@/sync Type=oneshot RemainAfterExit=yes
meta/recipes-connectivity/openssh/openssh_7.5p1.bb +8 -0
@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"
@@ -124,7 +125,14 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + -e 's,@BASE_BINDIR@,${base_bindir},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -D -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN} } do_install_ptest () {
Signature · 1 line
2.9.4
Quoted 155 lines · Joshua Watt
Generating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
Signed-off-by Joshua Watt <[email protected]>--- meta/recipes-connectivity/openssh/openssh/init | 22 ++++---------- .../openssh/openssh/sshd-check-key | 35 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 25 ++++++++-------- meta/recipes-connectivity/openssh/openssh_7.5p1.bb | 8 +++++ 4 files changed, 61 insertions(+), 29 deletions(-) create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-keymeta/recipes-connectivity/openssh/openssh/init +5
-17@@ -45,23 +45,11 @@ check_config() { } check_keys() { - # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 + @BASE_BINDIR@/sync } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +35
-0@@ -0,0 +1,35 @@ +#! /bin/sh +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1 +fi + + +if [ ! -f "$NAME" ]; then + DIR="$(dirname "$NAME")" + + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Move (Atomically rename) files + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + + # This sync does double duty: Ensuring that the data in the temporary + # private key file is on disk before the rename, and ensuring that the + # public key rename is completed before the private key rename, since we + # switch on the existence of the private key to trigger key generation. + # This does mean it is possible for the public key to exist, but be garbage + # but this is OK because in that case the private key won't exist and the + # keys will be regenerated. + # + # In the event that sync understands arguments that limit what it tries to + # fsync(), we provided them. If it does not, it will simply call sync() + # which is just as well + sync "${NAME}.pub" "$DIR" "${NAME}.tmp" + + mv "${NAME}.tmp" "$NAME" +fi +meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +13
-12@@ -1,22 +1,23 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/var/run/ssh/ssh_host_rsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_dsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 +ExecStart=@BASE_BINDIR@/sync Type=oneshot RemainAfterExit=yesmeta/recipes-connectivity/openssh/openssh_7.5p1.bb +8
-1@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"@@ -124,7 +125,14 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + -e 's,@BASE_BINDIR@,${base_bindir},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -D -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN} } do_install_ptest () { --
Quoted 2 lines
2.9.4
Ping?
Quoted 193 lines · Joshua Watt
Quoted 185 lines · Joshua Watt
Generating the host keys atomically prevents power interruptions during
the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.Signed-off-by Joshua Watt <[email protected]>---
meta/recipes-connectivity/openssh/openssh/init | 22 ++++----
------
.../openssh/openssh/sshd-check-key | 35
++++++++++++++++++++++
.../openssh/openssh/sshdgenkeys.service | 25 ++++++++
--------
meta/recipes-connectivity/openssh/openssh_7.5p1.bb | 8 +++++4 files changed, 61 insertions(+), 29 deletions(-)create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd- check-key
meta/recipes-connectivity/openssh/openssh/init +5
-17@@ -45,23 +45,11 @@ check_config() { } check_keys() { - # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 + @BASE_BINDIR@/sync }export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
(quoted diff) +0
-0key b/meta/recipes-connectivity/openssh/openssh/sshd-check-key new file mode 100644
index 0000000..3afdb8bmeta/recipes-connectivity/openssh/openssh/sshd-check-key new file +20
-0@@ -0,0 +1,35 @@ +#! /bin/sh +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1 +fi + + +if [ ! -f "$NAME" ]; then + DIR="$(dirname "$NAME")" + + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Move (Atomically rename) files + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + + # This sync does double duty: Ensuring that the data in thetemporary
+ # private key file is on disk before the rename, and ensuring that the
+ # public key rename is completed before the private key rename, since we
+ # switch on the existence of the private key to trigger key generation.
+ # This does mean it is possible for the public key to exist, but be garbage
+ # but this is OK because in that case the private key won't exist and the
+ # keys will be regenerated.
+ #
+ # In the event that sync understands arguments that limit what it tries to
+ #fsync(), we provided them. If it does not, it will simply callsync()
+ # which is just as well
+ sync "${NAME}.pub" "$DIR" "${NAME}.tmp"meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +4
-0+ + mv "${NAME}.tmp" "$NAME" +fi +(quoted diff) +0
-0connectivity/openssh/openssh/sshdgenkeys.service b/meta/recipes- connectivity/openssh/openssh/sshdgenkeys.service
index 148e6ad..23fd351 100644meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-0@@ -1,22 +1,23 @@[Unit]
Description=OpenSSH Key Generation
RequiresMountsFor=/var /runmeta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +8
-8-ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/var/run/ssh/ssh_host_rsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_dsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key[Service]
Environment="SYSCONFDIR=/etc/ssh"
EnvironmentFile=-/etc/default/ssh
ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIRmeta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-5-ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 +ExecStart=@BASE_BINDIR@/sync
Type=oneshot
RemainAfterExit=yesmeta/recipes-connectivity/openssh/openssh_7.5p1.bb +0
-0@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in- cipher.patch \
file://openssh-7.1p1-conditional-compile-des-in- pkcs11.patch \
file://fix-potential-signed-overflow-in-pointer- arithmatic.patch \
+ file://sshd-check-key \
"PAM_SRC_URI = "file://sshd"
meta/recipes-connectivity/openssh/openssh_7.5p1.bb +1
-0@@ -124,7 +125,14 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service
meta/recipes-connectivity/openssh/openssh_7.5p1.bb +6
-0+ + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + -e 's,@BASE_BINDIR@,${base_bindir},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -D -m 0755 ${WORKDIR}/sshd-check-key${D}${libexecdir}/${BPN}
}Quoted 4 lines
do_install_ptest () {
--
2.9.4Ping?
Quoted 187 lines · Joshua Watt
Quoted 185 lines · Joshua Watt
Generating the host keys atomically prevents power interruptions during
the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.Signed-off-by Joshua Watt <[email protected]>---
meta/recipes-connectivity/openssh/openssh/init | 22 ++++----
------
.../openssh/openssh/sshd-check-key | 35
++++++++++++++++++++++
.../openssh/openssh/sshdgenkeys.service | 25 ++++++++
--------
meta/recipes-connectivity/openssh/openssh_7.5p1.bb | 8 +++++4 files changed, 61 insertions(+), 29 deletions(-)create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd- check-key
meta/recipes-connectivity/openssh/openssh/init +5
-17@@ -45,23 +45,11 @@ check_config() { } check_keys() { - # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 + @BASE_BINDIR@/sync }export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
(quoted diff) +0
-0key b/meta/recipes-connectivity/openssh/openssh/sshd-check-key new file mode 100644
index 0000000..3afdb8bmeta/recipes-connectivity/openssh/openssh/sshd-check-key new file +20
-0@@ -0,0 +1,35 @@ +#! /bin/sh +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1 +fi + + +if [ ! -f "$NAME" ]; then + DIR="$(dirname "$NAME")" + + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Move (Atomically rename) files + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + + # This sync does double duty: Ensuring that the data in thetemporary
+ # private key file is on disk before the rename, and ensuring that the
+ # public key rename is completed before the private key rename, since we
+ # switch on the existence of the private key to trigger key generation.
+ # This does mean it is possible for the public key to exist, but be garbage
+ # but this is OK because in that case the private key won't exist and the
+ # keys will be regenerated.
+ #
+ # In the event that sync understands arguments that limit what it tries to
+ #fsync(), we provided them. If it does not, it will simply callsync()
+ # which is just as well
+ sync "${NAME}.pub" "$DIR" "${NAME}.tmp"meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +4
-0+ + mv "${NAME}.tmp" "$NAME" +fi +(quoted diff) +0
-0connectivity/openssh/openssh/sshdgenkeys.service b/meta/recipes- connectivity/openssh/openssh/sshdgenkeys.service
index 148e6ad..23fd351 100644meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-0@@ -1,22 +1,23 @@[Unit]
Description=OpenSSH Key Generation
RequiresMountsFor=/var /runmeta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +8
-8-ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/var/run/ssh/ssh_host_rsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_dsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key[Service]
Environment="SYSCONFDIR=/etc/ssh"
EnvironmentFile=-/etc/default/ssh
ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIRmeta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-5-ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 +ExecStart=@BASE_BINDIR@/sync
Type=oneshot
RemainAfterExit=yesmeta/recipes-connectivity/openssh/openssh_7.5p1.bb +0
-0@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in- cipher.patch \
file://openssh-7.1p1-conditional-compile-des-in- pkcs11.patch \
file://fix-potential-signed-overflow-in-pointer- arithmatic.patch \
+ file://sshd-check-key \
"PAM_SRC_URI = "file://sshd"
meta/recipes-connectivity/openssh/openssh_7.5p1.bb +1
-0@@ -124,7 +125,14 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service
meta/recipes-connectivity/openssh/openssh_7.5p1.bb +6
-0+ + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + -e 's,@BASE_BINDIR@,${base_bindir},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -D -m 0755 ${WORKDIR}/sshd-check-key${D}${libexecdir}/${BPN}
}
Quoted 6 lines
Quoted 4 lines
do_install_ptest () {
--
2.9.4Ping?
Ping? Am I missing something to get this merged?
PATCH v8 1/1 openssh: Atomically generate host keys
In reply to Joshua WattGenerating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
--- meta/recipes-connectivity/openssh/openssh/init | 24 +++-------------- .../openssh/openssh/sshd-check-key | 30 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 16 +++--------- meta/recipes-connectivity/openssh/openssh_7.5p1.bb | 8 ++++++ 4 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-key
meta/recipes-connectivity/openssh/openssh/init +4 -20
@@ -80,26 +80,10 @@ check_keys() { [ -z "${HOST_KEY_ED25519}" ] && HOST_KEY_ED25519=$SYSCONFDIR/ssh_host_ed25519_key # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - mkdir -p $(dirname $HOST_KEY_RSA) - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - mkdir -p $(dirname $HOST_KEY_ECDSA) - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - mkdir -p $(dirname $HOST_KEY_DSA) - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - mkdir -p $(dirname $HOST_KEY_ED25519) - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +30 -0
@@ -0,0 +1,30 @@ +#! /bin/sh +set -e + +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1; +fi + +if [ ! -f "$NAME" ]; then + mkdir -p "$(dirname "$NAME")" + + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Sync to ensure data is written to temp file before renaming + sync + + # Move (Atomically rename) files + # Rename the .pub file first, since the check that triggers a + # key generation is based on the private file. + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + sync + + mv -f "${NAME}.tmp" "${NAME}" + sync +fi +
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +4 -12
@@ -1,22 +1,14 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 Type=oneshot RemainAfterExit=yes
meta/recipes-connectivity/openssh/openssh_7.5p1.bb +8 -0
@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"
@@ -124,7 +125,14 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -d ${D}${libexecdir}/${BPN} + install -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN} } do_install_ptest () {
Signature · 1 line
2.9.4
Quoted 143 lines · Joshua Watt
Generating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
Signed-off-by Joshua Watt <[email protected]>--- meta/recipes-connectivity/openssh/openssh/init | 24 +++-------------- .../openssh/openssh/sshd-check-key | 30 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 16 +++--------- meta/recipes-connectivity/openssh/openssh_7.5p1.bb | 8 ++++++ 4 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-keymeta/recipes-connectivity/openssh/openssh/init +4
-20@@ -80,26 +80,10 @@ check_keys() { [ -z "${HOST_KEY_ED25519}" ] && HOST_KEY_ED25519=$SYSCONFDIR/ssh_host_ed25519_key # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - mkdir -p $(dirname $HOST_KEY_RSA) - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - mkdir -p $(dirname $HOST_KEY_ECDSA) - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - mkdir -p $(dirname $HOST_KEY_DSA) - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - mkdir -p $(dirname $HOST_KEY_ED25519) - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +30
-0@@ -0,0 +1,30 @@ +#! /bin/sh +set -e + +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1; +fi + +if [ ! -f "$NAME" ]; then + mkdir -p "$(dirname "$NAME")" + + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Sync to ensure data is written to temp file before renaming + sync + + # Move (Atomically rename) files + # Rename the .pub file first, since the check that triggers a + # key generation is based on the private file. + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + sync + + mv -f "${NAME}.tmp" "${NAME}" + sync +fi +meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +4
-12@@ -1,22 +1,14 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 Type=oneshot RemainAfterExit=yesmeta/recipes-connectivity/openssh/openssh_7.5p1.bb +8
-1@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"@@ -124,7 +125,14 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -d ${D}${libexecdir}/${BPN} + install -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN} } do_install_ptest () { --
Quoted 2 lines
2.9.4
Argh. Nevermind. This was a rebase of the wrong patch version. I shouldn't be trying this so late.
PATCH v9 1/1 openssh: Atomically generate host keys
In reply to Joshua WattGenerating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
--- meta/recipes-connectivity/openssh/openssh/init | 25 +++------------ .../openssh/openssh/sshd-check-key | 37 ++++++++++++++++++++++ .../openssh/openssh/sshdgenkeys.service | 25 ++++++++------- meta/recipes-connectivity/openssh/openssh_7.5p1.bb | 8 +++++ 4 files changed, 63 insertions(+), 32 deletions(-) create mode 100644 meta/recipes-connectivity/openssh/openssh/sshd-check-key
meta/recipes-connectivity/openssh/openssh/init +5 -20
@@ -80,26 +80,11 @@ check_keys() { [ -z "${HOST_KEY_ED25519}" ] && HOST_KEY_ED25519=$SYSCONFDIR/ssh_host_ed25519_key # create keys if necessary - if [ ! -f $HOST_KEY_RSA ]; then - echo " generating ssh RSA key..." - mkdir -p $(dirname $HOST_KEY_RSA) - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa - fi - if [ ! -f $HOST_KEY_ECDSA ]; then - echo " generating ssh ECDSA key..." - mkdir -p $(dirname $HOST_KEY_ECDSA) - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa - fi - if [ ! -f $HOST_KEY_DSA ]; then - echo " generating ssh DSA key..." - mkdir -p $(dirname $HOST_KEY_DSA) - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa - fi - if [ ! -f $HOST_KEY_ED25519 ]; then - echo " generating ssh ED25519 key..." - mkdir -p $(dirname $HOST_KEY_ED25519) - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 - fi + @LIBEXECDIR@/sshd-check-key $HOST_KEY_RSA rsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ECDSA ecdsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_DSA dsa + @LIBEXECDIR@/sshd-check-key $HOST_KEY_ED25519 ed25519 + @BASE_BINDIR@/sync } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
meta/recipes-connectivity/openssh/openssh/sshd-check-key new file +37 -0
@@ -0,0 +1,37 @@ +#! /bin/sh +NAME="$1" +TYPE="$2" + +if [ -z "$NAME" ] || [ -z "$TYPE" ]; then + echo "Usage: $0 NAME TYPE" + exit 1 +fi + + +if [ ! -f "$NAME" ]; then + DIR="$(dirname "$NAME")" + + mkdir -p "$DIR" + + echo " generating ssh $TYPE key..." + ssh-keygen -q -f "${NAME}.tmp" -N '' -t $TYPE + + # Move (Atomically rename) files + mv -f "${NAME}.tmp.pub" "${NAME}.pub" + + # This sync does double duty: Ensuring that the data in the temporary + # private key file is on disk before the rename, and ensuring that the + # public key rename is completed before the private key rename, since we + # switch on the existence of the private key to trigger key generation. + # This does mean it is possible for the public key to exist, but be garbage + # but this is OK because in that case the private key won't exist and the + # keys will be regenerated. + # + # In the event that sync understands arguments that limit what it tries to + # fsync(), we provided them. If it does not, it will simply call sync() + # which is just as well + sync "${NAME}.pub" "$DIR" "${NAME}.tmp" + + mv "${NAME}.tmp" "$NAME" +fi +
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +13 -12
@@ -1,22 +1,23 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/var/run/ssh/ssh_host_rsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_dsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/var/run/ssh/ssh_host_ed25519_key +ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key +ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key [Service] Environment="SYSCONFDIR=/etc/ssh" EnvironmentFile=-/etc/default/ssh ExecStart=@BASE_BINDIR@/mkdir -p $SYSCONFDIR -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' -t rsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' -t dsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ecdsa_key -N '' -t ecdsa -ExecStart=@BINDIR@/ssh-keygen -q -f ${SYSCONFDIR}/ssh_host_ed25519_key -N '' -t ed25519 +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_rsa_key rsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_dsa_key dsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ecdsa_key ecdsa +ExecStart=@LIBEXECDIR@/sshd-check-key ${SYSCONFDIR}/ssh_host_ed25519_key ed25519 +ExecStart=@BASE_BINDIR@/sync Type=oneshot RemainAfterExit=yes
meta/recipes-connectivity/openssh/openssh_7.5p1.bb +8 -0
@@ -25,6 +25,7 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar file://openssh-7.1p1-conditional-compile-des-in-cipher.patch \ file://openssh-7.1p1-conditional-compile-des-in-pkcs11.patch \ file://fix-potential-signed-overflow-in-pointer-arithmatic.patch \ + file://sshd-check-key \ " PAM_SRC_URI = "file://sshd"
@@ -124,7 +125,14 @@ do_install_append () { sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ -e 's,@BINDIR@,${bindir},g' \ + -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ ${D}${systemd_unitdir}/system/sshd.socket ${D}${systemd_unitdir}/system/*.service + + sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \ + -e 's,@BASE_BINDIR@,${base_bindir},g' \ + ${D}${sysconfdir}/init.d/sshd + + install -D -m 0755 ${WORKDIR}/sshd-check-key ${D}${libexecdir}/${BPN}/sshd-check-key } do_install_ptest () {
Signature · 1 line
2.9.4
PATCH v10 1/1 openssh: Atomically generate host keys
In reply to Joshua WattGenerating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
[YOCTO #11671]
--- .../openssh/openssh/sshd_check_keys | 42 +++++++++++++++++----- 1 file changed, 34 insertions(+), 8 deletions(-)
meta/recipes-connectivity/openssh/openssh/sshd_check_keys +34 -8
@@ -1,5 +1,35 @@ #! /bin/sh +generate_key() { + local FILE=$1 + local TYPE=$2 + local DIR="$(dirname "$FILE")" + + mkdir -p "$DIR" + ssh-keygen -q -f "${FILE}.tmp" -N '' -t $TYPE + + # Atomically rename file public key + mv -f "${FILE}.tmp.pub" "${FILE}.pub" + + # This sync does double duty: Ensuring that the data in the temporary + # private key file is on disk before the rename, and ensuring that the + # public key rename is completed before the private key rename, since we + # switch on the existence of the private key to trigger key generation. + # This does mean it is possible for the public key to exist, but be garbage + # but this is OK because in that case the private key won't exist and the + # keys will be regenerated. + # + # In the event that sync understands arguments that limit what it tries to + # fsync(), we provided them. If it does not, it will simply call sync() + # which is just as well + sync "${FILE}.pub" "$DIR" "${FILE}.tmp" + + mv "${FILE}.tmp" "$FILE" + + # sync to ensure the atomic rename is committed + sync "$DIR" +} + # /etc/default/ssh may set SYSCONFDIR and SSHD_OPTS if test -f /etc/default/ssh; then . /etc/default/ssh
@@ -43,22 +73,18 @@ HOST_KEY_ED25519=$(grep ^HostKey "${sshd_config}" | grep _ed25519_ | tail -1 | a # create keys if necessary if [ ! -f $HOST_KEY_RSA ]; then echo " generating ssh RSA key..." - mkdir -p $(dirname $HOST_KEY_RSA) - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa + generate_key $HOST_KEY_RSA rsa fi if [ ! -f $HOST_KEY_ECDSA ]; then echo " generating ssh ECDSA key..." - mkdir -p $(dirname $HOST_KEY_ECDSA) - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa + generate_key $HOST_KEY_ECDSA ecdsa fi if [ ! -f $HOST_KEY_DSA ]; then echo " generating ssh DSA key..." - mkdir -p $(dirname $HOST_KEY_DSA) - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa + generate_key $HOST_KEY_DSA dsa fi if [ ! -f $HOST_KEY_ED25519 ]; then echo " generating ssh ED25519 key..." - mkdir -p $(dirname $HOST_KEY_ED25519) - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 + generate_key $HOST_KEY_ED25519 ed25519 fi
Signature · 1 line
2.9.4
PATCH v11 1/1 openssh: Atomically generate host keys
In reply to Joshua WattGenerating the host keys atomically prevents power interruptions during the first boot from leaving the key files incomplete, which often prevents users from being able to ssh into the device.
[YOCTO #11671]
--- .../openssh/openssh/sshd_check_keys | 42 +++++++++++++++++----- 1 file changed, 34 insertions(+), 8 deletions(-)
meta/recipes-connectivity/openssh/openssh/sshd_check_keys +34 -8
@@ -1,5 +1,35 @@ #! /bin/sh +generate_key() { + local FILE=$1 + local TYPE=$2 + local DIR="$(dirname "$FILE")" + + mkdir -p "$DIR" + ssh-keygen -q -f "${FILE}.tmp" -N '' -t $TYPE + + # Atomically rename file public key + mv -f "${FILE}.tmp.pub" "${FILE}.pub" + + # This sync does double duty: Ensuring that the data in the temporary + # private key file is on disk before the rename, and ensuring that the + # public key rename is completed before the private key rename, since we + # switch on the existence of the private key to trigger key generation. + # This does mean it is possible for the public key to exist, but be garbage + # but this is OK because in that case the private key won't exist and the + # keys will be regenerated. + # + # In the event that sync understands arguments that limit what it tries to + # fsync(), we provided them. If it does not, it will simply call sync() + # which is just as well + sync "${FILE}.pub" "$DIR" "${FILE}.tmp" + + mv "${FILE}.tmp" "$FILE" + + # sync to ensure the atomic rename is committed + sync "$DIR" +} + # /etc/default/ssh may set SYSCONFDIR and SSHD_OPTS if test -f /etc/default/ssh; then . /etc/default/ssh
@@ -43,22 +73,18 @@ HOST_KEY_ED25519=$(grep ^HostKey "${sshd_config}" | grep _ed25519_ | tail -1 | a # create keys if necessary if [ ! -f $HOST_KEY_RSA ]; then echo " generating ssh RSA key..." - mkdir -p $(dirname $HOST_KEY_RSA) - ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa + generate_key $HOST_KEY_RSA rsa fi if [ ! -f $HOST_KEY_ECDSA ]; then echo " generating ssh ECDSA key..." - mkdir -p $(dirname $HOST_KEY_ECDSA) - ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa + generate_key $HOST_KEY_ECDSA ecdsa fi if [ ! -f $HOST_KEY_DSA ]; then echo " generating ssh DSA key..." - mkdir -p $(dirname $HOST_KEY_DSA) - ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa + generate_key $HOST_KEY_DSA dsa fi if [ ! -f $HOST_KEY_ED25519 ]; then echo " generating ssh ED25519 key..." - mkdir -p $(dirname $HOST_KEY_ED25519) - ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 + generate_key $HOST_KEY_ED25519 ed25519 fi
Signature · 1 line
2.13.5
Quoted 15 lines · Ross
Quoted 14 lines · Joshua Watt
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-5@@ -1,22 +1,14 @@ [Unit] Description=OpenSSH Key Generation RequiresMountsFor=/var /run -ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key
Quoted 8 lines
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service line 4
Quoted 4 lines
meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-3-ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_keyCan you not continue to use ConditionPathExists to only run this unit if it needs to run? You can prepend the argument with | to make them logical OR instead of logical AND, if I'm reading this documentation correctly.
Am I right that if we have a read-write mounted root-FS with already existing keys in /etc/ssh the service unit will nevertheless be started on _every_ boot now as the files which are checked for existance in /var/run/ssh are missing?
Best regards
Ulrich
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 31 lines · Ulrich Ölmann
Quoted 21 lines · Ross
Quoted 20 lines · Joshua Watt
(quoted diff) +0
-0connectivity/openssh/openssh/sshdgenkeys.service b/meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service index 148e6ad..af56404 100644
--- a/meta/recipes- connectivity/openssh/openssh/sshdgenkeys.service
+++ b/meta/recipes- connectivity/openssh/openssh/sshdgenkeys.service(quoted diff) +0
-0@@ -1,22 +1,14 @@[Unit]
Description=OpenSSH Key Generation
RequiresMountsFor=/var /runmeta/recipes-connectivity/openssh/openssh/sshdgenkeys.service +0
-8-ConditionPathExists=!/var/run/ssh/ssh_host_rsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_dsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/var/run/ssh/ssh_host_ed25519_key -ConditionPathExists=!/etc/ssh/ssh_host_rsa_key -ConditionPathExists=!/etc/ssh/ssh_host_dsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ecdsa_key -ConditionPathExists=!/etc/ssh/ssh_host_ed25519_keyQuoted 8 lines
Quoted 1 line
Can you not continue to use ConditionPathExists to only run this unit if it
needs to run? You can prepend the argument with | to make them logical OR
instead of logical AND, if I'm reading this documentation correctly.
Quoted 6 lines
Am I right that if we have a read-write mounted root-FS with already existing
keys in/etc/sshthe service unit will nevertheless be started on _every_ boot
now as the files which are checked for existance in/var/run/sshare missing?
Yes. The service is actually run when the first ssh connection is made (not at boot time), but it will do so on the first connection every boot cycle. I don't know a way to do a complex conditional in systemd, so this does the superset and makes sshd-check-key figure out if the key actually needs generating or not. Perhaps there is a better way to do this with the systemd conditional syntax that I am not aware of? Ideally, the conditional checks in the systemd unit would be able to use the SYSCONFDIR from /etc/default/ssh, but I'm not sure if that is possible.
Quoted 12 lines
Best regards
Ulrich
--
Pengutronix
e.K. | | Industrial Linux Solutions | http://www.pengutronix.d
e/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917- 0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917- 5555 |
✗ patchtest: failure for openssh: Atomically generate host keys (rev3)
In reply to Joshua Watt== Series Details ==
Series: openssh: Atomically generate host keys (rev3)
Revision: 3
URL : https://patchwork.openembedded.org/series/6626/
State : failure
== Summary ==
Thank you for submitting this patch series to OpenEmbedded Core. This is an automated response. Several tests have been executed on the proposed series by patchtest resulting in the following failures:
* Patch [meta-oe,v3] openssh: Atomically generate host keys Issue Patch is missing Signed-off-by [test_signed_off_by_presence] Suggested fix Sign off the patch (either manually or with "git commit --amend -s")
If you believe any of these test results are incorrect, please reply to the mailing list ([email protected]) raising your concerns. Otherwise we would appreciate you correcting the issues and submitting a new version of the patchset if applicable. Please ensure you add/increment the version number when sending the new version (i.e. [PATCH] -> [PATCH v2] -> [PATCH v3] -> ...).
---
Test framework: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest Test suite: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest-oe
✗ patchtest: failure for openssh: Atomically generate host keys (rev4)
In reply to Joshua Watt== Series Details ==
Series: openssh: Atomically generate host keys (rev4)
Revision: 4
URL : https://patchwork.openembedded.org/series/6626/
State : failure
== Summary ==
Thank you for submitting this patch series to OpenEmbedded Core. This is an automated response. Several tests have been executed on the proposed series by patchtest resulting in the following failures:
* Patch [meta-oe,v4] openssh: Atomically generate host keys Issue Patch is missing Signed-off-by [test_signed_off_by_presence] Suggested fix Sign off the patch (either manually or with "git commit --amend -s")
If you believe any of these test results are incorrect, please reply to the mailing list ([email protected]) raising your concerns. Otherwise we would appreciate you correcting the issues and submitting a new version of the patchset if applicable. Please ensure you add/increment the version number when sending the new version (i.e. [PATCH] -> [PATCH v2] -> [PATCH v3] -> ...).
---
Test framework: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest Test suite: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest-oe
✗ patchtest: failure for openssh: Atomically generate host keys (rev10)
In reply to Joshua Watt== Series Details ==
Series: openssh: Atomically generate host keys (rev10)
Revision: 10
URL : https://patchwork.openembedded.org/series/6626/
State : failure
== Summary ==
Thank you for submitting this patch series to OpenEmbedded Core. This is an automated response. Several tests have been executed on the proposed series by patchtest resulting in the following failures:
* Issue Series does not apply on top of target branch [test_series_merge_on_head]
Suggested fix Rebase your series on top of targeted branch
Targeted branch master (currently at b1c4661742)
If you believe any of these test results are incorrect, please reply to the mailing list ([email protected]) raising your concerns. Otherwise we would appreciate you correcting the issues and submitting a new version of the patchset if applicable. Please ensure you add/increment the version number when sending the new version (i.e. [PATCH] -> [PATCH v2] -> [PATCH v3] -> ...).
---
Test framework: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest Test suite: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest-oe