From patchwork Fri Sep 22 12:54:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 54157 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 445EF27BBEC; Fri, 22 Sep 2023 13:56:29 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham 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 5356327BBEA for ; Fri, 22 Sep 2023 13:56:22 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjfhJ-0001Nx-CO; Fri, 22 Sep 2023 08:55:53 -0400 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 1qjfhI-0001NW-9U for guix-patches@gnu.org; Fri, 22 Sep 2023 08:55:52 -0400 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 1qjfhI-0008B1-1I for guix-patches@gnu.org; Fri, 22 Sep 2023 08:55:52 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qjfhS-0005j1-Ji for guix-patches@gnu.org; Fri, 22 Sep 2023 08:56:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#66156] [PATCH 07/12] services: childhurd: Authorize the =?utf-8?q?childhurd=E2=80=99s?= key on the host. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 22 Sep 2023 12:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66156 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66156@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 66156-submit@debbugs.gnu.org id=B66156.169538731221901 (code B ref 66156); Fri, 22 Sep 2023 12:56:02 +0000 Received: (at 66156) by debbugs.gnu.org; 22 Sep 2023 12:55:12 +0000 Received: from localhost ([127.0.0.1]:35591 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjfgd-0005h3-L4 for submit@debbugs.gnu.org; Fri, 22 Sep 2023 08:55:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41108) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjfgM-0005eI-5A for 66156@debbugs.gnu.org; Fri, 22 Sep 2023 08:54:54 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qjfg6-0007nH-8U; Fri, 22 Sep 2023 08:54:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=F8/ITNybdKENRcRhPNVo7d37tSrUe4l7QUIGWPatBPc=; b=Sq+6AsE2Lj+i33o1BBfm m0l5bSfMIeDGm5U0veBnWCoNljRyxFDvK18vGExQqd2Ii44Ui1C/uXlvKyuq3Pn2sIjSrivJmLiWd jOZIdj8K46Ro3RHtF4Aj6hoxI2tadvDrbO2wARkP2nd/aJIJB9YmAVriO+RhRvDDVCZ/lNSFJtJyF sTzm+uaKCWW8mIyvvEPbe5aNaeFM21XM0HFSxXJTGEJ9pruWYYF90RBitr/WWHLxAxFPIFEMTEB/J h9qD1z7UxcPrtaofgyXdskpRvxABg8Jn3CaVAF4DM1qnDEnW9ldDm3dAX3hM6lmkgNPLPFgvf43Yt +99g+tux90P8rg==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Fri, 22 Sep 2023 14:54:08 +0200 Message-ID: <0f2ebabd36558e2f660e4f1037a3c0a7f77f53d5.1695386493.git.ludo@gnu.org> 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 This partly automates setting up a childhurd for offloading purposes. * gnu/services/virtualization.scm (authorize-guest-substitutes-on-host): New procedure. (hurd-vm-activation): Use it. --- gnu/services/virtualization.scm | 51 ++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/gnu/services/virtualization.scm b/gnu/services/virtualization.scm index fd153dd051..ca000f5d28 100644 --- a/gnu/services/virtualization.scm +++ b/gnu/services/virtualization.scm @@ -28,6 +28,7 @@ (define-module (gnu services virtualization) #:use-module (gnu image) #:use-module (gnu packages admin) #:use-module (gnu packages gdb) + #:autoload (gnu packages gnupg) (guile-gcrypt) #:use-module (gnu packages package-management) #:use-module (gnu packages ssh) #:use-module (gnu packages virtualization) @@ -50,6 +51,7 @@ (define-module (gnu services virtualization) #:use-module (guix records) #:use-module (guix store) #:use-module (guix utils) + #:autoload (guix self) (make-config.scm) #:use-module (srfi srfi-9) #:use-module (srfi srfi-26) @@ -1271,6 +1273,50 @@ (define (initialize-hurd-vm-substitutes) (program-file "initialize-hurd-vm-substitutes" run)) +(define (authorize-guest-substitutes-on-host) + "Return a program that authorizes the guest's archive signing key (passed as +an argument) on the host." + (define not-config? + (match-lambda + ('(guix config) #f) + (('guix _ ...) #t) + (('gnu _ ...) #t) + (_ #f))) + + (define run + (with-extensions (list guile-gcrypt) + (with-imported-modules `(((guix config) => ,(make-config.scm)) + ,@(source-module-closure + '((guix pki) + (guix build utils)) + #:select? not-config?)) + #~(begin + (use-modules (ice-9 match) + (ice-9 textual-ports) + (gcrypt pk-crypto) + (guix pki) + (guix build utils)) + + (match (command-line) + ((_ guest-config-directory) + (let ((guest-key (string-append guest-config-directory + "/signing-key.pub"))) + (if (file-exists? guest-key) + ;; Add guest key to the host's ACL. + (let* ((key (string->canonical-sexp + (call-with-input-file guest-key + get-string-all))) + (acl (public-keys->acl + (cons key (acl->public-keys (current-acl)))))) + (with-atomic-file-replacement %acl-file + (lambda (_ port) + (write-acl acl port)))) + (format (current-error-port) + "warning: guest key missing from '~a'~%" + guest-key))))))))) + + (program-file "authorize-guest-substitutes-on-host" run)) + (define (hurd-vm-activation config) "Return a gexp to activate the Hurd VM according to CONFIG." (with-imported-modules '((guix build utils)) @@ -1294,7 +1340,10 @@ (define (hurd-vm-activation config) (unless (file-exists? guix-directory) (invoke #$(initialize-hurd-vm-substitutes) - guix-directory))))) + guix-directory)) + + ;; Authorize the archive signing key from GUIX-DIRECTORY in the host. + (invoke #$(authorize-guest-substitutes-on-host) guix-directory)))) (define hurd-vm-service-type (service-type