Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 705032 - sys-kernel/genkernel initramfs encrypted zfs root unlock via dropbear ssh
Summary: sys-kernel/genkernel initramfs encrypted zfs root unlock via dropbear ssh
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: genkernel (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Genkernel Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-09 14:37 UTC by anatol.rosch
Modified: 2020-01-12 14:59 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
replace the zfs load-key exit status with an actual zfs key status (genkernel-ssh-zfs-load-key.patch,716 bytes, patch)
2020-01-09 14:40 UTC, anatol.rosch
Details | Diff
Check ZFS keystatus instead of return value (genkernel-4.0.1-check-zfs-keystatus.patch,723 bytes, patch)
2020-01-09 21:23 UTC, Thomas Deutschmann (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description anatol.rosch 2020-01-09 14:37:55 UTC
case: ZFS root with native encryption. initramfs built using 

    genkernel initramfs --zfs --ssh

the current linuxrc only allows key entry in the local console. if i reboot the machine remotely, unlock the data set remotely, and kill the zfs load-key process, boot will fail despite the fact that the ZFS key has been loaded via SSH:

    zfs load-key -a
    pkill zfs
    resume-boot

... initramfs fails.

 This is caused by the following condition check:

    if [ ${retval} -ne 0 ]
    ...
       got_good_root=0

instead of checking the exit code of the local zfs load-key command, we can check that the key has been loaded; this allows us to log into ssh, run the above commands, and have the machine boot successfully.

the suggested condition change is in the attached patch.

Reproducible: Always
Comment 1 anatol.rosch 2020-01-09 14:40:28 UTC
Created attachment 602820 [details, diff]
replace the zfs load-key exit status with an actual zfs key status
Comment 2 Thomas Deutschmann (RETIRED) gentoo-dev 2020-01-09 20:36:21 UTC
Well, I hope that we will get something like unlock-luks for ZFS, too.

But this looks like an interesting workaround for the meanwhile. Thanks.

Waiting for feedback from ZFS maintainer(s).
Comment 3 Thomas Deutschmann (RETIRED) gentoo-dev 2020-01-09 21:23:18 UTC
Created attachment 602832 [details, diff]
Check ZFS keystatus instead of return value

Please test the attached patch. Based on your idea but slightly adjusted code. Please also confirm if local unlock still works and also test with invalid passphrase.
Comment 4 Georgy Yakovlev archtester gentoo-dev 2020-01-10 04:54:46 UTC
indeed, zfs returns 255 if key already loaded.


# zfs load-key zreaper
Key load error: Key already loaded for 'zreaper'.
echo $?
255


looking at how dracut module implements it (shipped by zfs) approach looks sane to me, but I haven't tested.


https://github.com/zfsonlinux/zfs/commit/6c7023a5326cc999cfaced931ee2498642d5e63f
Comment 5 Larry the Git Cow gentoo-dev 2020-01-12 14:59:27 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=9e7b41cda3df648b509a0f8a2af29a683100a46f

commit 9e7b41cda3df648b509a0f8a2af29a683100a46f
Author:     Thomas Deutschmann <whissi@gentoo.org>
AuthorDate: 2020-01-10 16:07:20 +0000
Commit:     Thomas Deutschmann <whissi@gentoo.org>
CommitDate: 2020-01-11 19:54:40 +0000

    Rework ZFS unlock
    
    - Prompt for key when key is unavailable, not when key is available.
    
    - Check ZFS' keystatus property instead of return value to allow
      remote unlock.
    
    - Add unlock-zfs command to remote rescue shell.
    
    Closes: https://bugs.gentoo.org/705032
    Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>

 defaults/initrd.defaults |  3 ++
 defaults/initrd.scripts  | 38 +++++++++++++++-----
 defaults/linuxrc         | 42 +++++++++++++++-------
 defaults/login-remote.sh |  5 +++
 defaults/unlock-zfs.sh   | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 gen_initramfs.sh         |  6 ++++
 6 files changed, 165 insertions(+), 20 deletions(-)