ssh: add an ssh-dev feature and keep host keys on /var for wrynose - #275
ssh: add an ssh-dev feature and keep host keys on /var for wrynose#275jetm wants to merge 1 commit into
Conversation
|
Same note as on #276, since this branch has the identical gap. The host-key work here is necessary but not sufficient on its own — sshd still will not start, because there is no Confirmed on an i.MX 93 FRDM running a wrynose build: with the key work in place the console reported #304 adds it for scarthgap; this branch needs the equivalent. The two changes are independent, so merge order does not matter, but sshd will not come up until both have landed — worth knowing when validating this one on its own. |
sshd cannot start on any image that installs it. It listens on 22, then
every connection dies at kex_exchange_identification, and
journalctl -u sshd@ reports no entries at all - so the unit looks healthy
while nothing works.
There is no sshd account. oe-core's openssh creates one through the
useradd class, declaring USERADD_PARAM:${PN}-sshd = "--system
--no-create-home --home-dir /var/run/sshd --shell /bin/false
--user-group sshd". This recipe then installs a fixed /etc/passwd and
/etc/group over the top, which discards it along with any other
useradd-created system user. OpenSSH refuses to run without its
privilege-separation account and exits before writing a banner or a log
line, which is what makes this expensive to diagnose rather than merely
broken.
Add the account, mirroring that USERADD_PARAM's home directory and shell
so the two do not drift. uid and gid 992 are free here and stay in the
system range.
Confirmed on an i.MX 93 FRDM: with the host key already generated and
present under /var/lib/ssh, and the console reporting "Finished OpenSSH
Key Generation", every connection was still dropped. Adding the account
produced sshd:x:992:992 in the built rootfs and a server that starts.
Scoped to the account alone, because the rest of the ssh story on this
branch belongs to #275 and this does not duplicate or contradict it.
That PR installs openssh, carries persist_ssh_host_keys, and pairs it
with an openssh bbappend that rewrites sshd_config's HostKey to
/var/lib/ssh - which is what makes the empty SSHD_OPTS in that function
harmless, since the config it selects then points at a writable path.
This branch currently carries the function without that bbappend, having
front-ported half of #275, so its host keys still resolve under
${sysconfdir}. That half-port is left as it is rather than papered over
here: it resolves when #275 lands.
So this change does not by itself make ssh work on this branch. It
removes one of the two reasons it cannot, and #275 removes the other.
The clobber behind it is marked as debt - the real fix is to stop
shipping a whole passwd and let useradd own what this distro does not
need to pin, which changes how every image gets its users.
Signed-off-by: Javier Tia <javier@peridio.com>
sshd cannot start on any image that installs it. It listens on 22, then
every connection dies at kex_exchange_identification, and
journalctl -u sshd@ reports no entries at all - so the unit looks healthy
while nothing works.
There is no sshd account. oe-core's openssh creates one through the
useradd class, declaring USERADD_PARAM:${PN}-sshd = "--system
--no-create-home --home-dir /var/run/sshd --shell /bin/false
--user-group sshd". This recipe then installs a fixed /etc/passwd and
/etc/group over the top, which discards it along with any other
useradd-created system user. OpenSSH refuses to run without its
privilege-separation account and exits before writing a banner or a log
line, which is what makes this expensive to diagnose rather than merely
broken.
Add the account, mirroring that USERADD_PARAM's home directory and shell
so the two do not drift. uid and gid 992 are free here and stay in the
system range.
Confirmed on an i.MX 93 FRDM: with the host key already generated and
present under /var/lib/ssh, and the console reporting "Finished OpenSSH
Key Generation", every connection was still dropped. Adding the account
produced sshd:x:992:992 in the built rootfs and a server that starts.
Scoped to the account alone, because the rest of the ssh story on this
branch belongs to #275 and this does not duplicate or contradict it.
That PR installs openssh, carries persist_ssh_host_keys, and pairs it
with an openssh bbappend that rewrites sshd_config's HostKey to
/var/lib/ssh - which is what makes the empty SSHD_OPTS in that function
harmless, since the config it selects then points at a writable path.
This branch currently carries the function without that bbappend, having
front-ported half of #275, so its host keys still resolve under
${sysconfdir}. That half-port is left as it is rather than papered over
here: it resolves when #275 lands.
So this change does not by itself make ssh work on this branch. It
removes one of the two reasons it cannot, and #275 removes the other.
The clobber behind it is marked as debt - the real fix is to stop
shipping a whole passwd and let useradd own what this distro does not
need to pin, which changes how every image gets its users.
Signed-off-by: Javier Tia <javier@peridio.com>
|
Heads-up before rework: the host-key half of this is now superseded on wrynose. The secure-boot stack landed 6f321812d5, which deliberately removed the persist_ssh_host_keys image hook this PR re-adds and replaced it with OPENSSH_HOST_KEY_DIR_READONLY_CONFIG = "/var/lib/ssh" in avocado.conf — no image post-processing, no ordering dependence. What still stands here is the ssh-dev kas fragment and (if still needed against the new mechanism) the openssh HostKey rewrite. Worth rebasing onto current wrynose and re-scoping to just those. #276 on scarthgap is unaffected. |
A bench board needs a shell before any extension has been installed, and the base image is minimal by design: no sshd, and root carries `*` in /etc/shadow, which no password can match. Driving a board therefore means a serial console and nothing else, which is workable by hand and not workable from a script. This composes the four things that actually open that door - unlocking root, oe-core's allow-root-login and allow-empty-password postprocesses, suppressing the zap that would re-lock the account afterwards, and installing sshd into the base rootfs rather than the feed. They act at different stages and each one alone leaves the door shut, which is why they arrive together. It is a kas fragment rather than an AVOCADO_FEATURE_GROUPS entry on purpose. A feature group populates the FEED, so `networking` builds the openssh packages and stops; that is right for a product image gaining capability through extensions, and wrong here, where the whole point is to have access before any extension exists. Scoped down from the original two commits after review. The host-key half is gone because the tree solved it another way: OPENSSH_HOST_KEY_DIR_READONLY_CONFIG in avocado.conf now lands the keys on /var with no image post-processing. The openssh bbappend went with it, and that removal is not merely deduplication - the bbappend rewrote HostKey lines in sshd_config, while this image sets read-only-rootfs and so reads sshd_config_readonly, a file the bbappend never touched. It was rewriting a config nothing on this image loads. Signed-off-by: Javier Tia <javier@peridio.com>
|
Rebased and re-scoped to just the kas fragment. Confirmed the host-key half is superseded: On whether the openssh HostKey rewrite is still needed — it isn't, and for a reason worth recording. The bbappend rewrote HostKey lines in |
Problem
Getting a shell on a freshly flashed board took a bespoke sequence per board, and the image as built could not serve SSH at all even once openssh was installed.
Two independent gaps:
The host keys were unreachable. oe-core's
sshd_confignamesHostKeyunder${sysconfdir}/ssh, which on an Avocado image is the read-only rootfs.sshd_check_keyscannot create a key there, so the unit fails, sshd starts keyless, and every client is dropped at key exchange withkex_exchange_identification: Connection reset by peer- a symptom that reads like a network fault rather than a missing file.There was no way to ask for SSH at build time. Enabling the
networkingfeature group is not enough: a feature group populates the feed, so the openssh RPMs land indeploy/rpmand the rootfs still has no/usr/sbin/sshd. That is correct for a product - the base image is minimal by design and gains capability through extensions - and useless for a bench board, where the point is to have a shell before any extension has been installed.Solution
kas/feature/ssh-dev.yml, composable onto any machine:plus an
opensshbbappend that repointsHostKeyat/var/lib/ssh, which is writable and persistent.Key changes
openssh_%.bbappendrewritesHostKey ${sysconfdir}/ssh/to/var/lib/ssh/in the shippedsshd_configkas/feature/ssh-dev.ymlsetsAVOCADO_DEV_ROOT_LOGIN, oe-core'sallow-root-login/allow-empty-password/empty-root-password, and adds openssh toROOTFS_IMAGE_EXTRA_INSTALLReviewer notes
A bbappend rather than a drop-in, deliberately.
HostKeyaccumulates rather than replaces, so a drop-in insshd_config.dwould add the reachable path while leaving the unreachable ones in the list, andsshd_check_keyswould keep failing on them.Complementary to the existing
SYSCONFDIRappend, not a duplicate.avocado-image-rootfs.bbappendsSYSCONFDIR=/var/lib/sshto/etc/default/ssh, butSYSCONFDIRonly decides wheresshd_check_keysdoes itsmkdir -p- the key paths themselves come fromsshd -GreadingHostKey. That is why the append alone still wrote keys to the read-only path. The gap has been invisible because thesshd-devextension ships an entiresshd_configof its own with the right paths, so only an image carrying base-image openssh hits it.Console and SSH need separate switches.
AVOCADO_DEV_ROOT_LOGINrewrites/etc/shadow'sroot:*:toroot::at package build; oe-core'sallow-empty-passwordrewritesnullok_securetonullokacrosspam.dat rootfs assembly. Without the second, an empty password authenticates on the console and is refused over SSH, because Linux-PAM 1.7.2 droppednullok_securewhile oe-core still ships it.Dev only. This puts an sshd on the image that accepts root with an empty password. The feature file says so in its header; nothing enables it by default.
Verification
Built and booted on FRDM-IMX93 hardware (
avocado-imx93-frdm, wrynose BSP).Before:
sshdgenkeys.servicefailed withchmod: cannot access '/etc/ssh/ssh_host_ecdsa_key.tmp': Read-only file system,/var/lib/ssh/empty, SSH refused at kex.After:
sshdgenkeys.serviceactive,HostKey /var/lib/ssh/ssh_host_ecdsa_keyin the shipped config, key present, andssh root@<board>returns a shell.Reboot survival, which is the point of putting the key on
/var:48ee1bf4…b29048ee1bf4…b290boot_id95c47b29-…9d9a29bb-…The changed
boot_idconfirms a real reboot; the identical key confirms it persisted, so a client'sknown_hostsstays valid.