anatol / booster

Fast and secure initramfs generator
MIT License
505 stars 45 forks source link

Add support for encrypted ZFS datasets. #259

Closed mikispag closed 6 months ago

mikispag commented 7 months ago

Here is a minimal implementation of support for encrypted ZFS datasets, calling zfs load-key for each encrypted root.

mikispag commented 7 months ago

I have tested this on multiple machines. Are you interested in merging? Thanks!

anatol commented 7 months ago

Yes I am very much interested in it. I was thinking about writing an integration test for it here https://github.com/anatol/booster/blob/master/tests/zfs_test.go, but I guess the test can be added later.

mikispag commented 7 months ago

Thank you!

Hmm, can you simulate input in those tests?

anatol commented 7 months ago

can you simulate input in those tests?

Yes. It can be done in the test with vm.ConsoleWrite("$YOURPASSWORD"), see https://github.com/anatol/booster/blob/master/tests/luks_test.go for more examples.

Integration tests is the least friendliest part of the project. But if you want to play with it check zfs and luks generators https://github.com/anatol/booster/blob/master/tests/generators/zfs.sh https://github.com/anatol/booster/blob/master/tests/generators/luks.sh

then

https://github.com/anatol/booster/blob/master/tests/zfs_test.go (here need to be something like TestUnlockZfsPartition) https://github.com/anatol/booster/blob/master/tests/luks_test.go

mikispag commented 7 months ago

Here is my attempt at tests. While the logic works, the test does not work on my machine, but I am not sure why. It really should.

It fails with:

[    2.457273] booster: importing zfs pool testpool
[    5.502629] booster: exit status 1: 
[    5.502962] booster: Press ENTER to reboot

Maybe can you please take a look?

anatol commented 7 months ago

Thank you for the feature implementation and for the tests.

The test is failing with this error message:

2024/04/27 10:45:58 Create booster.img with /tmp/1821066339/generator build --force --init-binary /tmp/1821066339/init --kernel-version 6.8.7-arch1-2 --config /tmp/TestUnlockEncryptedZfs196337958/001/config.yaml /tmp/TestUnlockEncryptedZfs196337958/001/booster.img
2024/04/27 10:45:58 module zfs does not exist
    util.go:347: 
            Error Trace:    /home/anatol/sources/golang/booster/tests/util.go:347
                                        /home/anatol/sources/golang/booster/tests/zfs_test.go:23
            Error:          Received unexpected error:
                            Cannot generate booster.img: exit status 1: 
            Test:           TestUnlockEncryptedZfs
--- FAIL: TestUnlockEncryptedZfs (154.80s)
FAIL
exit status 1

The reason of the failure is that booster tests use linux package (at least at Arch) and zfs currently does not support 6.8.

Switching zfs tests to linux-lts makes the tests pass. Please review the test output attached to make sure the zfs functionality behaves as expected. TestUnlockEncryptedZfs.log

mikispag commented 7 months ago

Thank you for investigating the cause of the test failure. The test output LGTM.

On Sat, Apr 27, 2024, 19:59 Anatol Pomozov @.***> wrote:

Thank you for the feature implementation and for the tests.

The test is failing with this error message:

2024/04/27 10:45:58 Create booster.img with /tmp/1821066339/generator build --force --init-binary /tmp/1821066339/init --kernel-version 6.8.7-arch1-2 --config /tmp/TestUnlockEncryptedZfs196337958/001/config.yaml /tmp/TestUnlockEncryptedZfs196337958/001/booster.img 2024/04/27 10:45:58 module zfs does not exist util.go:347: Error Trace: /home/anatol/sources/golang/booster/tests/util.go:347 /home/anatol/sources/golang/booster/tests/zfs_test.go:23 Error: Received unexpected error: Cannot generate booster.img: exit status 1: Test: TestUnlockEncryptedZfs --- FAIL: TestUnlockEncryptedZfs (154.80s) FAIL exit status 1

The reason of the failure is that booster tests use linux package (at least at Arch) and zfs currently does not support 6.8.

Switching zfs tests to linux-lts makes the tests pass. Please review the test output attached to make sure the zfs functionality behaves as expected. TestUnlockEncryptedZfs.log https://github.com/anatol/booster/files/15139202/TestUnlockEncryptedZfs.log

— Reply to this email directly, view it on GitHub https://github.com/anatol/booster/pull/259#issuecomment-2081114980, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHSDFPW3XCUH24CLQ3XVQDY7PROLAVCNFSM6AAAAABFP2IAOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBRGEYTIOJYGA . You are receiving this because you authored the thread.Message ID: @.***>

anatol commented 7 months ago

Merged as https://github.com/anatol/booster/commit/925b37c0609e5188c5b73f58209cbc8ad5307fc3

Thank you for your work @mikispag !

anatol commented 6 months ago

A small fix for your PR https://github.com/anatol/booster/commit/4609bba982af95ba839f7faf94001d9bba06dab1