From patchwork Wed Aug 7 12:45:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jakob L. Kreuze" X-Patchwork-Id: 14887 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 CC0BA17274; Wed, 7 Aug 2019 13:49:15 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 6CB6D17252 for ; Wed, 7 Aug 2019 13:49:15 +0100 (BST) Received: from localhost ([::1]:40672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvLNT-0001iV-4P for patchwork@mira.cbaines.net; Wed, 07 Aug 2019 08:49:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49251) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvLNI-0001hj-Vu for guix-patches@gnu.org; Wed, 07 Aug 2019 08:49:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvLNH-0006LM-GM for guix-patches@gnu.org; Wed, 07 Aug 2019 08:49:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57588) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hvLNG-0006L6-PV for guix-patches@gnu.org; Wed, 07 Aug 2019 08:49:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hvLNG-0000Rv-Mq for guix-patches@gnu.org; Wed, 07 Aug 2019 08:49:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#36956] [PATCH] machine: Automatically authorize the coordinator's signing key. Resent-From: zerodaysfordays@sdf.lonestar.org (Jakob L. Kreuze) Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 07 Aug 2019 12:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 36956 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 36956@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.15651821081671 (code B ref -1); Wed, 07 Aug 2019 12:49:02 +0000 Received: (at submit) by debbugs.gnu.org; 7 Aug 2019 12:48:28 +0000 Received: from localhost ([127.0.0.1]:38176 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hvLMi-0000Qs-1l for submit@debbugs.gnu.org; Wed, 07 Aug 2019 08:48:28 -0400 Received: from lists.gnu.org ([209.51.188.17]:37546) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hvLMg-0000Qj-Gs for submit@debbugs.gnu.org; Wed, 07 Aug 2019 08:48:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49094) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvLMf-0001Qh-48 for guix-patches@gnu.org; Wed, 07 Aug 2019 08:48:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvLMd-0005m1-T7 for guix-patches@gnu.org; Wed, 07 Aug 2019 08:48:25 -0400 Received: from mx.sdf.org ([205.166.94.20]:64903) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hvLMd-0005lI-LL for guix-patches@gnu.org; Wed, 07 Aug 2019 08:48:23 -0400 Received: from Epsilon (pool-173-76-53-40.bstnma.fios.verizon.net [173.76.53.40]) (authenticated (0 bits)) by mx.sdf.org (8.15.2/8.14.5) with ESMTPSA id x77CmLU8020701 (using TLSv1.2 with cipher AES256-GCM-SHA384 (256 bits) verified NO) for ; Wed, 7 Aug 2019 12:48:22 GMT From: zerodaysfordays@sdf.lonestar.org (Jakob L. Kreuze) Date: Wed, 07 Aug 2019 08:45:10 -0400 Message-ID: <87ef1x4015.fsf@sdf.lonestar.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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" X-getmail-retrieved-from-mailbox: Patches * guix/ssh.scm (remote-authorize-signing-key): New variable. * gnu/machine/ssh.scm (deploy-managed-host): Authorize coordinator's signing key before any invocations of 'remote-eval'. * guix/scripts/deploy.scm (guix-deploy): Display an error if a signing key does not exist. * doc/guix.texi (Invoking guix deploy): Remove section describing manual signing key authorization. --- doc/guix.texi | 16 ---------------- gnu/machine/ssh.scm | 7 +++++++ guix/scripts/deploy.scm | 7 +++++++ guix/ssh.scm | 23 +++++++++++++++++++++++ 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 734206a4b2..64ca44d494 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -25530,22 +25530,6 @@ complex deployment may involve, for example, starting virtual machines through a Virtual Private Server (VPS) provider. In such a case, a different @var{environment} type would be used. -Do note that you first need to generate a key pair on the coordinator machine -to allow the daemon to export signed archives of files from the store -(@pxref{Invoking guix archive}). - -@example -# guix archive --generate-key -@end example - -@noindent -Each target machine must authorize the key of the master machine so that it -accepts store items it receives from the coordinator: - -@example -# guix archive --authorize < coordinator-public-key.txt -@end example - @deftp {Data Type} machine This is the data type representing a single machine in a heterogeneous Guix deployment. diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm index 1f16d9a5ea..90deff19a8 100644 --- a/gnu/machine/ssh.scm +++ b/gnu/machine/ssh.scm @@ -28,13 +28,16 @@ #:use-module (guix i18n) #:use-module (guix modules) #:use-module (guix monads) + #:use-module (guix pki) #:use-module (guix records) #:use-module (guix remote) #:use-module (guix scripts system reconfigure) #:use-module (guix ssh) #:use-module (guix store) #:use-module (guix utils) + #:use-module (gcrypt pk-crypto) #:use-module (ice-9 match) + #:use-module (ice-9 textual-ports) #:use-module (srfi srfi-1) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) @@ -329,6 +332,10 @@ the 'should-roll-back' field set to SHOULD-ROLL-BACK?" "Internal implementation of 'deploy-machine' for MACHINE instances with an environment type of 'managed-host." (maybe-raise-unsupported-configuration-error machine) + (remote-authorize-signing-key (call-with-input-file %public-key-file + (lambda (port) + (string->canonical-sexp (get-string-all port)))) + (machine-ssh-session machine)) (mlet %store-monad ((_ (check-deployment-sanity machine)) (boot-parameters (machine-boot-parameters machine))) (let* ((os (machine-operating-system machine)) diff --git a/guix/scripts/deploy.scm b/guix/scripts/deploy.scm index 6a67985c8b..075c74d395 100644 --- a/guix/scripts/deploy.scm +++ b/guix/scripts/deploy.scm @@ -20,6 +20,7 @@ (define-module (guix scripts deploy) #:use-module (gnu machine) #:use-module (guix discovery) + #:use-module (guix pki) #:use-module (guix scripts) #:use-module (guix scripts build) #:use-module (guix store) @@ -83,6 +84,12 @@ Perform the deployment specified by FILE.\n")) (define (guix-deploy . args) (define (handle-argument arg result) (alist-cons 'file arg result)) + + (unless (file-exists? %public-key-file) + (leave (G_ "no signing key '~a' +have you run 'guix archive --generate-key?'~%") + %public-key-file)) + (let* ((opts (parse-command-line args %options (list %default-options) #:argument-handler handle-argument)) (file (assq-ref opts 'file)) diff --git a/guix/ssh.scm b/guix/ssh.scm index 9b5ca68894..5186c646ca 100644 --- a/guix/ssh.scm +++ b/guix/ssh.scm @@ -21,6 +21,7 @@ #:use-module (guix inferior) #:use-module (guix i18n) #:use-module ((guix utils) #:select (&fix-hint)) + #:use-module (gcrypt pk-crypto) #:use-module (ssh session) #:use-module (ssh auth) #:use-module (ssh key) @@ -40,6 +41,7 @@ remote-daemon-channel connect-to-remote-daemon remote-system + remote-authorize-signing-key send-files retrieve-files retrieve-files* @@ -289,6 +291,27 @@ the machine on the other end of SESSION." (inferior-remote-eval '(begin (use-modules (guix utils)) (%current-system)) session)) +(define (remote-authorize-signing-key key session) + "Send KEY, a canonical sexp containing a public key, over SESSION and add it +to the system ACL file if it has not yet been authorized." + (inferior-remote-eval + `(begin + (use-modules (guix build utils) + (guix pki) + (guix utils) + (gcrypt pk-crypto) + (srfi srfi-26)) + + (define acl (current-acl)) + (define key (string->canonical-sexp ,(canonical-sexp->string key))) + + (unless (authorized-key? key) + (let ((acl (public-keys->acl (cons key (acl->public-keys acl))))) + (mkdir-p (dirname %acl-file)) + (with-atomic-file-output %acl-file + (cut write-acl acl <>))))) + session)) + (define* (send-files local files remote #:key recursive?