Bug 8365

Summary: sshd key generation fails when both systemd and read-only-rootfs are enabled
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Winfried <winfried_mb2>
Component: connectivityAssignee: Alexander Kanavin <alex.kanavin>
Status: VERIFIED FIXED QA Contact: Bogdan Alexandru Voiculescu <bogdanx.a.voiculescu>
Severity: normal    
Priority: Medium+ CC: bogdanx.a.voiculescu, meta.mr.watcher, meta.watcher, ross.burton, yp.bsp.watcher, yp.watcher
Version: 1.8   
Target Milestone: 2.0   
Hardware: All   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)
Bug Depends on: 8680    
Bug Blocks:    

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