Repository navigation
Conversation
Keys shipped with a runtime's var_files can keep the build host's owner and mode, and sshd's StrictModes then refuses the key file or a group writable parent directory, which logs only "bad ownership or modes". Ship a tmpfiles.d entry that creates /var/lib/ssh/authorized_keys.d as root 0755 and resets its files to root 0644, and run it on merge so the fix applies without a reboot. The ~ in the Z line keeps files at 0644 instead of forcing the directory mode onto them. Signed-off-by: Javier Tia <javier@peridio.com>
mobileoverlord
left a comment
There was a problem hiding this comment.
The tmpfiles lines are right. d fixes the directory's owner and mode if it already exists. Z ~0755 masks per file, so a key that came in as 0664 or 0600 ends up root 0644, and the directory 0755. Running it from on_merge covers the current boot as well.
One gap, same failure mode: StrictModes checks every directory on the AuthorizedKeysFile path up to / (OpenSSH safe_path()), not just authorized_keys.d. If var_files brings var/lib/ssh/ along with the key, cp -a keeps the build host's owner on /var/lib/ssh too, and sshd still refuses the key. Please add a line for the parent, before the other two:
d /var/lib/ssh 0755 root root -
With that line added, approve from me. Nothing here was run on a device, so I'd still like the shipped-key case proven once on a board before 0.1.1 is tagged.
sshd's StrictModes checks every directory on the AuthorizedKeysFile path up to the user's home or /, and root's home is /root, so the walk covers /var/lib/ssh as well as authorized_keys.d. If var_files ships var/lib/ssh/ with the key, cp -a keeps the build host's owner on it and sshd refuses the key even though authorized_keys.d is reset. Add a d line for /var/lib/ssh before the authorized_keys.d entries, so a directory that already exists with the wrong owner or mode is fixed too. Signed-off-by: Javier Tia <javier@peridio.com>
|
Added in 4b58777: |
@nicksinas pointed out on #3 that sshd's StrictModes will refuse keys shipped with a runtime's var_files: avocado-cli copies them with cp -a and packs the var image with mkfs.btrfs -r, which keep the host file's owner and mode, so a key owned by the developer or a group-writable directory is rejected with only "bad ownership or modes" in the journal.
This applies his suggested fix: a tmpfiles.d entry that creates /var/lib/ssh/authorized_keys.d as root 0755 and resets its files to root 0644, and a systemd-tmpfiles call in on_merge so it takes effect without a reboot. I stacked it on #3 and changed nothing else.
Checked: avocado config validate on the manifest. Not checked: nothing was built, provisioned or booted, and I did not reproduce the original problem on a device. Nick's comment cites avocado-cli line numbers that no longer match main, so the cp -a behavior is as he described it, not confirmed here.
@mobileoverlord, merge this into #3 or close it, as you prefer.