Bug 8365 - sshd key generation fails when both systemd and read-only-rootfs are enabled
Summary: sshd key generation fails when both systemd and read-only-rootfs are enabled
Status: VERIFIED FIXED
Alias: None
Product: OE-Core
Classification: Build System, Metadata & Runtime
Component: connectivity (show other bugs)
Version: 1.8
Hardware: All Multiple
: Medium+ normal
Target Milestone: 2.0
Assignee: Alexander Kanavin
QA Contact: Bogdan Alexandru Voiculescu
URL:
Whiteboard:
Depends on: 8680
Blocks:
  Show dependency tree
 
Reported: 2015-09-21 12:18 UTC by Winfried
Modified: 2015-11-16 14:32 UTC (History)
6 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Winfried 2015-09-21 12:18:38 UTC
When read-only-rootfs is added to (EXTRA_)IMAGE_FEATURES, directory /etc/ssh in the target rootfs becomes readonly and as a consequence ssh key generation in that directory fails. This has been fixed for SysV init, but not for systemd.

There is already a sshd config file /etc/ssh/sshd_config_readonly that relocates the ssh keys to /var/run/ssh (which is mounted on a tmpfs). Probably sshd should be started with this config file.
Comment 1 Bruce Ashfield 2015-09-22 01:49:47 UTC
Ross: I'm not the right person for this .. do you know who is ?
Comment 2 Alexander Kanavin 2015-09-25 14:23:04 UTC
I think it's better to move this ssh key location tweaking out of image.bbclass altogether, and have it in init.d/sshd where it'll be together with the rest of ssh stuff. Dropbear already does it.

http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/classes/image.bbclass#n238

http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/recipes-core/dropbear/dropbear/init#n30

http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/recipes-connectivity/openssh/openssh/init
Comment 3 Alexander Kanavin 2015-09-28 16:12:46 UTC
Okay, I misunderstood how sysvinit/systemd works. Those init scripts aren't used at all, systemd actually runs sshd only when someone connects to port 22:

http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/recipes-connectivity/openssh/openssh/sshd.socket

http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/recipes-connectivity/openssh/openssh/sshd@.service

http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/recipes-connectivity/openssh/openssh/sshdgenkeys.service

The last file hardcodes the keys location to /etc/ssh/. Dropbear has a similar problem and needs to be fixed too.
Comment 4 Alexander Kanavin 2015-09-30 12:53:51 UTC
Patches submitted to oe-core mailing list. I've also included a bonus fix for dropbear :)
Comment 5 Alexander Kanavin 2015-10-01 11:43:48 UTC
Patches are now in master.
Comment 6 Bogdan Alexandru Voiculescu 2015-11-16 14:31:30 UTC
Verified on master: fc45deac89ef63ca1c44e763c38ced7dfd72cbe1"

I used a core-image-sato with 
EXTRA_IMAGE_FEATURES += "ssh-server-openssh"
EXTRA_IMAGE_INSTALL += "ssh-server-openssh"
DISTRO_FEATURES_append = " systemd"
IMAGE_FEATURES_REPLACES_ssh-server-openssh = " ssh-server-dropbear"
VIRTUAL-RUNTIME_init_manager = "systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
VIRTUAL-RUNTIME_initscripts = ""
IMAGE_FEATURES[validitems] += " read-only-rootfs empty-root-password allow-empty-password post-install-logging"
Comment 7 Bogdan Alexandru Voiculescu 2015-11-16 14:32:35 UTC
using empty-root-password allow-empty-password you can work around the dependency of Bug 8680