From patchwork Thu Jan 11 17:32:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tomas Volf <~@wolfsden.cz> X-Patchwork-Id: 58792 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id C33B927BBE2; Thu, 11 Jan 2024 17:33:37 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id A784727BBE9 for ; Thu, 11 Jan 2024 17:33:36 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNyvU-00045B-21; Thu, 11 Jan 2024 12:33:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rNyvR-0003yD-Md for guix-patches@gnu.org; Thu, 11 Jan 2024 12:33:05 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNyvR-0001gQ-Cw for guix-patches@gnu.org; Thu, 11 Jan 2024 12:33:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rNyvO-0007hd-K8 for guix-patches@gnu.org; Thu, 11 Jan 2024 12:33:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#65002] [PATCH 2/6] gnu: bootloader: grub: Add support for loading an additional initrd. Resent-From: Tomas Volf <~@wolfsden.cz> Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 11 Jan 2024 17:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65002 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 65002@debbugs.gnu.org Cc: Tomas Volf Received: via spool by 65002-submit@debbugs.gnu.org id=B65002.170499435829543 (code B ref 65002); Thu, 11 Jan 2024 17:33:02 +0000 Received: (at 65002) by debbugs.gnu.org; 11 Jan 2024 17:32:38 +0000 Received: from localhost ([127.0.0.1]:33741 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rNyuy-0007g6-FS for submit@debbugs.gnu.org; Thu, 11 Jan 2024 12:32:37 -0500 Received: from wolfsden.cz ([37.205.8.62]:45632) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <~@wolfsden.cz>) id 1rNyuu-0007fj-Pk for 65002@debbugs.gnu.org; Thu, 11 Jan 2024 12:32:35 -0500 Received: by wolfsden.cz (Postfix, from userid 104) id A2AF02506C2; Thu, 11 Jan 2024 17:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1704994353; bh=qX7LRq03g5vzjHhWvoyWy4m3AVYPwBLXGMjLzM9WNqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Xbo2Whn5VS3vRLwTQUT9a06X1ZTqu0Bk0xKkG7X4w0xBwY43LqLoIZlf0N9plPB21 WCP+ykO5iaIRDl3kcodjbdqnki99NXTDirzNgq2+PNZ/hm9eiUB7zjx9jCf5snM5U5 XN/I6zkcYpvpZGQCEhan4nnbJpsyZkYQysieWqHniS1pl4/oBm0rVD4dVA7815UkOr WSKJgaj0vgufuabUTKtAJdszpnlTOel1uBPW/JWaeUj55BE4j8irEJygBEFoLbBExe rTXDXGsh92FB4LZTqtgsIIQN5niv5wPyfdpYq7BaULdTTxUTq9XB2c60TrIogDqqpp TpcQIdY9F0V7uGL9A52EbnpwXAFP/kUXPUiJfUmz2xJBbn2EsfuGn60A/cbVFD1+gA hoZFYQ/x4Tq0iIk4nbVfUejN8NBKB+7Oa+QYBhvyrcOYzdtr5amIXpXw/3pf8HCRot 1ZKHQ+IYdhh0mHemuBdknPUaHZ4VKOyzdyZN02B50lVM5SXXuK7IWleWFH+pZsrsNO l6TtlDHFc+egKbkrpt1NigNymX5DBmeCYfiCF7l+1VY3U+E8dlr9yxE8xSlpTlGWwc NqnyXBtb8nZSePlasrcmp23Rh2cM/X6NLbocjV7814fCFdIP58BzuLooooy7u6cW8m Ck5E/RSUmKCAGBtklYwl7rQE= Received: from localhost (unknown [193.32.127.158]) by wolfsden.cz (Postfix) with ESMTPSA id 20FA8250562; Thu, 11 Jan 2024 17:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1704994353; bh=qX7LRq03g5vzjHhWvoyWy4m3AVYPwBLXGMjLzM9WNqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Xbo2Whn5VS3vRLwTQUT9a06X1ZTqu0Bk0xKkG7X4w0xBwY43LqLoIZlf0N9plPB21 WCP+ykO5iaIRDl3kcodjbdqnki99NXTDirzNgq2+PNZ/hm9eiUB7zjx9jCf5snM5U5 XN/I6zkcYpvpZGQCEhan4nnbJpsyZkYQysieWqHniS1pl4/oBm0rVD4dVA7815UkOr WSKJgaj0vgufuabUTKtAJdszpnlTOel1uBPW/JWaeUj55BE4j8irEJygBEFoLbBExe rTXDXGsh92FB4LZTqtgsIIQN5niv5wPyfdpYq7BaULdTTxUTq9XB2c60TrIogDqqpp TpcQIdY9F0V7uGL9A52EbnpwXAFP/kUXPUiJfUmz2xJBbn2EsfuGn60A/cbVFD1+gA hoZFYQ/x4Tq0iIk4nbVfUejN8NBKB+7Oa+QYBhvyrcOYzdtr5amIXpXw/3pf8HCRot 1ZKHQ+IYdhh0mHemuBdknPUaHZ4VKOyzdyZN02B50lVM5SXXuK7IWleWFH+pZsrsNO l6TtlDHFc+egKbkrpt1NigNymX5DBmeCYfiCF7l+1VY3U+E8dlr9yxE8xSlpTlGWwc NqnyXBtb8nZSePlasrcmp23Rh2cM/X6NLbocjV7814fCFdIP58BzuLooooy7u6cW8m Ck5E/RSUmKCAGBtklYwl7rQE= From: Tomas Volf <~@wolfsden.cz> Date: Thu, 11 Jan 2024 18:32:12 +0100 Message-ID: <1f9c251cf379b579a0e04f5698da0bfdd62f2b90.1704994323.git.~@wolfsden.cz> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches From: Tomas Volf In order to be able to provide decryption keys for the LUKS device, they need to be available in the initial ram disk. However they cannot be stored inside the usual initrd, since it is stored in the store and being a world-readable (as files in the store are) is not a desired property for a initrd containing decryption keys. This commit adds an option to load additional initrd during the boot, one that is not stored inside the store and therefore can contain secrets. Since only grub supports encrypted /boot, only grub is modified to use the extra-initrd. There is no use case for the other bootloaders. * doc/guix.texi (Bootloader Configuration): Describe the new extra-initrd field. * gnu/bootloader.scm (): Add extra-initrd field. * gnu/bootloader/grub.scm (make-grub-configuration): Use the extra-initrd field. --- doc/guix.texi | 49 +++++++++++++++++++++++++++++++++++++++++ gnu/bootloader.scm | 6 ++++- gnu/bootloader/grub.scm | 7 ++++-- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index b1202f2182..87d41e0aae 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -41070,6 +41070,55 @@ Bootloader Configuration @code{u-boot} bootloader, where the device tree has already been loaded in RAM, it can be handy to disable the option by setting it to @code{#f}. + +@item @code{extra-initrd} (default: @code{#f}) +File name of an additional initrd to load during the boot. It may or +may not point to a file in the store, but the main use case is for +out-of-store files containing secrets. + +In order to be able to provide decryption keys for the LUKS device, they +need to be available in the initial ram disk. However they cannot be +stored inside the usual initrd, since it is stored in the store and +being a world-readable (as files in the store are) is not a desired +property for a initrd containing decryption keys. You can therefore use +this field to instruct GRUB to also load a manually created initrd not +stored in the store. + +For any use case not involving secrets, you should use regular initrd +(@pxref{operating-system Reference, @code{initrd}}) instead. + +Suitable image can be created for example like this: + +@example +echo /key-file.bin | cpio -oH newc >/key-file.cpio +chmod 0000 /key-file.cpio +@end example + +After it is created, you can use it in this manner: + +@lisp +;; Operating system with encrypted boot partition +(operating-system + ... + (bootloader (bootloader-configuration + (bootloader grub-efi-bootloader) + (targets '("/boot/efi")) + ;; Load the initrd with a key file + (extra-initrd "/key-file.cpio"))) + (mapped-devices + (list (mapped-device + (source (uuid "12345678-1234-1234-1234-123456789abc")) + (target "my-root") + (type (luks-device-mapping-with-options + ;; And use it to unlock the root device + #:key-file "/key-file.bin")))))) +@end lisp + +Be careful when using this option, since pointing to a file that is not +readable by the grub while booting will cause the boot to fail and +require a manual edit of the initrd line in the grub menu. + +Currently only supported by GRUB. @end table @end deftp diff --git a/gnu/bootloader.scm b/gnu/bootloader.scm index ba06de7618..f32e90e79d 100644 --- a/gnu/bootloader.scm +++ b/gnu/bootloader.scm @@ -6,6 +6,7 @@ ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen ;;; Copyright © 2022 Josselin Poiret ;;; Copyright © 2022 Reza Alizadeh Majd +;;; Copyright © 2024 Tomas Volf <~@wolfsden.cz> ;;; ;;; This file is part of GNU Guix. ;;; @@ -77,6 +78,7 @@ (define-module (gnu bootloader) bootloader-configuration-serial-unit bootloader-configuration-serial-speed bootloader-configuration-device-tree-support? + bootloader-configuration-extra-initrd %bootloaders lookup-bootloader-by-name @@ -279,7 +281,9 @@ (define-record-type* (serial-speed bootloader-configuration-serial-speed (default #f)) ;integer | #f (device-tree-support? bootloader-configuration-device-tree-support? - (default #t))) ;boolean + (default #t)) ;boolean + (extra-initrd bootloader-configuration-extra-initrd + (default #f))) ;string | #f (define-deprecated (bootloader-configuration-target config) bootloader-configuration-targets diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm index 5f3fcd7074..2723eda5f4 100644 --- a/gnu/bootloader/grub.scm +++ b/gnu/bootloader/grub.scm @@ -9,6 +9,7 @@ ;;; Copyright © 2020 Stefan ;;; Copyright © 2022 Karl Hallsby ;;; Copyright © 2022 Denis 'GNUtoo' Carikli +;;; Copyright © 2024 Tomas Volf <~@wolfsden.cz> ;;; ;;; This file is part of GNU Guix. ;;; @@ -386,7 +387,8 @@ (define* (make-grub-configuration grub config entries store-directory-prefix)) (initrd (normalize-file (menu-entry-initrd entry) device-mount-point - store-directory-prefix))) + store-directory-prefix)) + (extra-initrd (bootloader-configuration-extra-initrd config))) ;; Here DEVICE is the store and DEVICE-MOUNT-POINT is its mount point. ;; Use the right file names for LINUX and INITRD in case ;; DEVICE-MOUNT-POINT is not "/", meaning that the store is on a @@ -397,11 +399,12 @@ (define* (make-grub-configuration grub config entries #~(format port "menuentry ~s { ~a linux ~a ~a - initrd ~a + initrd ~a ~a }~%" #$label #$(grub-root-search device linux) #$linux (string-join (list #$@arguments)) + (or #$extra-initrd "") #$initrd))) (multiboot-kernel (let* ((kernel (menu-entry-multiboot-kernel entry))