From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 29 18:40:40 2019 Received: (at submit) by debbugs.gnu.org; 29 Jul 2019 22:40:40 +0000 Received: from localhost ([127.0.0.1]:49277 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsEJr-0000HU-GY for submit@debbugs.gnu.org; Mon, 29 Jul 2019 18:40:39 -0400 Received: from lists.gnu.org ([209.51.188.17]:46256) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsEJo-0000HJ-OM for submit@debbugs.gnu.org; Mon, 29 Jul 2019 18:40:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42506) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsEJn-0004z1-Bc for guix-patches@gnu.org; Mon, 29 Jul 2019 18:40:36 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,RCVD_IN_DNSWL_NONE autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsEJm-0006MH-24 for guix-patches@gnu.org; Mon, 29 Jul 2019 18:40:35 -0400 Received: from mx.sdf.org ([205.166.94.20]:51313) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hsEJl-0006LA-PJ for guix-patches@gnu.org; Mon, 29 Jul 2019 18:40:34 -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 x6TMeVPj029909 (using TLSv1.2 with cipher AES256-GCM-SHA384 (256 bits) verified NO) for ; Mon, 29 Jul 2019 22:40:32 GMT From: zerodaysfordays@sdf.lonestar.org (Jakob L. Kreuze) To: guix-patches@gnu.org Subject: [PATCH] machine: Implement safety checks. Date: Mon, 29 Jul 2019 18:37:43 -0400 Message-ID: <87lfwgii14.fsf@sdf.lonestar.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 205.166.94.20 X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable * gnu/machine/ssh.scm (machine-check-file-system-availability) (machine-check-initrd-modules, check-deployment-sanity): New variable. (deploy-managed-host): Perform safety checks before deploying. =2D-- gnu/machine/ssh.scm | 128 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 1 deletion(-) diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm index 552eafa9de..1f44783a6c 100644 =2D-- a/gnu/machine/ssh.scm +++ b/gnu/machine/ssh.scm @@ -20,6 +20,9 @@ #:use-module (gnu machine) #:autoload (gnu packages gnupg) (guile-gcrypt) #:use-module (gnu system) + #:use-module (gnu system file-systems) + #:use-module (gnu system uuid) + #:use-module (guix diagnostics) #:use-module (guix gexp) #:use-module (guix i18n) #:use-module (guix modules) @@ -29,6 +32,7 @@ #:use-module (guix scripts system reconfigure) #:use-module (guix ssh) #:use-module (guix store) + #:use-module (guix utils) #:use-module (ice-9 match) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) @@ -98,6 +102,127 @@ an environment type of 'managed-host." (maybe-raise-unsupported-configuration-error machine) (remote-eval exp (machine-ssh-session machine))) =20 + +;;; +;;; Safety checks. +;;; + +(define (machine-check-file-system-availability machine) + "Raise a '&message' error condition if any of the file-systems specified= in +MACHINE's 'system' declaration do not exist on the machine." + (define file-systems + (filter (lambda (fs) + (and (file-system-mount? fs) + (not (member (file-system-type fs) + %pseudo-file-system-types)) + (not (memq 'bind-mount (file-system-flags fs))))) + (operating-system-file-systems (machine-system machine)))) + + (define (check-literal-file-system fs) + (define remote-exp + #~(catch 'system-error + (lambda () + (stat #$(file-system-device fs)) + #t) + (lambda args + (system-error-errno args)))) + + (mlet %store-monad ((errno (machine-remote-eval machine remote-exp))) + (when (number? errno) + (raise (condition + (&message (message (format #f (G_ "device '~a' not found: = ~a") + (file-system-device fs) + (strerror errno))))))) + (return #t))) + + (define (check-labeled-file-system fs) + (define remote-exp + (with-imported-modules '((gnu build file-systems)) + #~(begin + (use-modules (gnu build file-systems)) + (find-partition-by-label #$(file-system-label->string + (file-system-device fs)))))) + + (mlet %store-monad ((result (machine-remote-eval machine remote-exp))) + (unless result + (raise (condition (&message + (message (format #f (G_ "no file system with la= bel '~a'") + (file-system-label->string + (file-system-device fs)))))))) + (return #t))) + + (define (check-uuid-file-system fs) + (define remote-exp + (with-imported-modules '((gnu build file-systems)) + #~(begin + (use-modules (gnu build file-systems)) + (find-partition-by-uuid #$(file-system-device fs))))) + + (mlet %store-monad ((result (machine-remote-eval machine remote-exp))) + (unless result + (raise (condition (&message + (message (format #f (G_ "no file system with UU= ID '~a'") + (uuid->string (file-system-dev= ice fs)))))))) + (return #t))) + + (mbegin %store-monad + (mapm %store-monad check-literal-file-system + (filter (lambda (fs) + (string? (file-system-device fs))) + file-systems)) + (mapm %store-monad check-labeled-file-system + (filter (lambda (fs) + (file-system-label? (file-system-device fs))) + file-systems)) + (mapm %store-monad check-uuid-file-system + (filter (lambda (fs) + (uuid? (file-system-device fs))) + file-systems)))) + +(define (machine-check-initrd-modules machine) + "Raise a '&message' error condition if any of the modules needed by +'needed-for-boot' file systems in MACHINE are not available in the initrd." + (define file-systems + (filter file-system-needed-for-boot? + (operating-system-file-systems (machine-system machine)))) + + (define (missing-modules fs) + (define remote-exp + (let ((device (file-system-device fs))) + (with-imported-modules (source-module-closure + '((gnu build linux-modules))) + #~(begin + (use-modules (gnu build linux-modules)) + + (define dev + #$(cond ((string? device) device) + ((uuid? device) #~(find-partition-by-uuid #$device= )) + ((file-system-label? device) + #~(find-partition-by-label + (file-system-label->string #$device))))) + + (missing-modules dev '#$(operating-system-initrd-modules + (machine-system machine))))))) + (mlet %store-monad ((missing (machine-remote-eval machine remote-exp))) + (return (list fs missing)))) + + (mlet %store-monad ((missing (mapm %store-monad missing-modules file-sys= tems))) + (for-each (match-lambda + ((fs missing) + (unless (null? missing) + (raise (condition (&message + (message (format #f (G_ "~a missing = modules ~{ ~a~}~%") + (file-system-device= fs) missing)))))))) + missing) + (return #t))) + +(define (check-deployment-sanity machine) + "Raise a '&message' error condition if it is clear that deploying MACHIN= E's +'system' declaration would fail." + (mbegin %store-monad + (machine-check-file-system-availability machine) + (machine-check-initrd-modules machine))) + ;;; ;;; System deployment. @@ -165,7 +290,8 @@ of MACHINE's system profile, ordered from most recent t= o oldest." "Internal implementation of 'deploy-machine' for MACHINE instances with = an environment type of 'managed-host." (maybe-raise-unsupported-configuration-error machine) =2D (mlet %store-monad ((boot-parameters (machine-boot-parameters machine)= )) + (mlet %store-monad ((_ (check-deployment-sanity machine)) + (boot-parameters (machine-boot-parameters machine))) (let* ((os (machine-system machine)) (eval (cut machine-remote-eval machine <>)) (menu-entries (map boot-parameters->menu-entry boot-parameters)) =2D-=20 2.22.0 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEa1VJLOiXAjQ2BGSm9Qb9Fp2P2VoFAl0/dTcACgkQ9Qb9Fp2P 2VpbgRAAky4VpnG49tsm5PHKrONjoKg+EQUXcQkeyfjOb+i8tGIn80+7qJkYvPqo pZU+zHSpHVoYAWVTqWCsWjVnx27aBgmvcDdr9/euUwqRqmpuP5eb3vI6HaVmD33e gfV6IYURgNIEjI76tM/fUpOp7hy6U0yvhfBl2vTcUa+b540TXM77y76dSa4TcYWC ITr5HkSzN+b+eValzovibaR3gFUvlIw19/esl62AKOgD7L3MqEyanpfP5qSA6IK0 VJp5lskrgR3mEty/Jp7zg12smBbe7fxsrXFO+PpuQz8L1Np2/TDI24hoguWDmuA8 apfAKVBxcBrnbP3rF5dv6io4dt8TeDR9allzDa3T8G9DuIbK0X0yk2LDY2lXPPK0 tEFepYVciD6losT+wG42V0XrkTYV0pDFEkiBLLI8c3rcdG073fq94Yb0Wj2eDWR6 NyamAWYlz9jn4R7LoD96lB/3T6NJiAAb8fifEo22YrEg+HwKMJlYOt4UoR0oZB27 GCmChoMVdTLF4zIG6S2Oqbg25YXiQ3bgXTvESBQYPvOUNkT3ySrMJSFmZE+kwFY4 Byg9AmtSVCOKxOixQRBdN0HGqoEfa/+updJGPVgcAHT8s4mLb9KobdcEXWg3ZGK4 +qqdUKKJy+1QHr/3wL7QRxK0loToCA1OaH9HjKsa5xDhKL99WGc= =A5lG -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 30 13:52:09 2019 Received: (at submit) by debbugs.gnu.org; 30 Jul 2019 17:52:09 +0000 Received: from localhost ([127.0.0.1]:51134 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsWIC-0006MI-Pw for submit@debbugs.gnu.org; Tue, 30 Jul 2019 13:52:09 -0400 Received: from lists.gnu.org ([209.51.188.17]:59376) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsWIB-0006MB-HE for submit@debbugs.gnu.org; Tue, 30 Jul 2019 13:52:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38951) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsWIA-0006YJ-4u for guix-patches@gnu.org; Tue, 30 Jul 2019 13:52:07 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,RCVD_IN_DNSWL_NONE autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsWI8-0008Jf-Os for guix-patches@gnu.org; Tue, 30 Jul 2019 13:52:06 -0400 Received: from ol.sdf.org ([205.166.94.20]:55678 helo=mx.sdf.org) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hsWI8-0008J1-FC for guix-patches@gnu.org; Tue, 30 Jul 2019 13:52:04 -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 x6UHq2ua023279 (using TLSv1.2 with cipher AES256-GCM-SHA384 (256 bits) verified NO) for ; Tue, 30 Jul 2019 17:52:03 GMT From: zerodaysfordays@sdf.lonestar.org (Jakob L. Kreuze) To: guix-patches@gnu.org Subject: [PATCH v2] machine: Implement safety checks. References: <87lfwgii14.fsf@sdf.lonestar.org> Date: Tue, 30 Jul 2019 13:49:12 -0400 In-Reply-To: <87lfwgii14.fsf@sdf.lonestar.org> (Jakob L. Kreuze's message of "Mon, 29 Jul 2019 18:37:43 -0400") Message-ID: <87mugvv2ef.fsf@sdf.lonestar.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 205.166.94.20 X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) * gnu/machine/ssh.scm (machine-check-file-system-availability) (machine-check-initrd-modules, check-deployment-sanity): New variable. (deploy-managed-host): Perform safety checks before deploying. --- gnu/machine/ssh.scm | 130 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 2 deletions(-) diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm index 552eafa9de..5773ce8e37 100644 --- a/gnu/machine/ssh.scm +++ b/gnu/machine/ssh.scm @@ -20,6 +20,9 @@ #:use-module (gnu machine) #:autoload (gnu packages gnupg) (guile-gcrypt) #:use-module (gnu system) + #:use-module (gnu system file-systems) + #:use-module (gnu system uuid) + #:use-module (guix diagnostics) #:use-module (guix gexp) #:use-module (guix i18n) #:use-module (guix modules) @@ -29,6 +32,7 @@ #:use-module (guix scripts system reconfigure) #:use-module (guix ssh) #:use-module (guix store) + #:use-module (guix utils) #:use-module (ice-9 match) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) @@ -98,6 +102,127 @@ an environment type of 'managed-host." (maybe-raise-unsupported-configuration-error machine) (remote-eval exp (machine-ssh-session machine))) + +;;; +;;; Safety checks. +;;; + +(define (machine-check-file-system-availability machine) + "Raise a '&message' error condition if any of the file-systems specified in +MACHINE's 'system' declaration do not exist on the machine." + (define file-systems + (filter (lambda (fs) + (and (file-system-mount? fs) + (not (member (file-system-type fs) + %pseudo-file-system-types)) + (not (memq 'bind-mount (file-system-flags fs))))) + (operating-system-file-systems (machine-system machine)))) + + (define (check-literal-file-system fs) + (define remote-exp + #~(catch 'system-error + (lambda () + (stat #$(file-system-device fs)) + #t) + (lambda args + (system-error-errno args)))) + + (mlet %store-monad ((errno (machine-remote-eval machine remote-exp))) + (when (number? errno) + (raise (condition + (&message (message (format #f (G_ "device '~a' not found: ~a") + (file-system-device fs) + (strerror errno))))))) + (return #t))) + + (define (check-labeled-file-system fs) + (define remote-exp + (with-imported-modules '((gnu build file-systems)) + #~(begin + (use-modules (gnu build file-systems)) + (find-partition-by-label #$(file-system-label->string + (file-system-device fs)))))) + + (mlet %store-monad ((result (machine-remote-eval machine remote-exp))) + (unless result + (raise (condition (&message + (message (format #f (G_ "no file system with label '~a'") + (file-system-label->string + (file-system-device fs)))))))) + (return #t))) + + (define (check-uuid-file-system fs) + (define remote-exp + (with-imported-modules '((gnu build file-systems)) + #~(begin + (use-modules (gnu build file-systems)) + (find-partition-by-uuid #$(file-system-device fs))))) + + (mlet %store-monad ((result (machine-remote-eval machine remote-exp))) + (unless result + (raise (condition (&message + (message (format #f (G_ "no file system with UUID '~a'") + (uuid->string (file-system-device fs)))))))) + (return #t))) + + (mbegin %store-monad + (mapm %store-monad check-literal-file-system + (filter (lambda (fs) + (string? (file-system-device fs))) + file-systems)) + (mapm %store-monad check-labeled-file-system + (filter (lambda (fs) + (file-system-label? (file-system-device fs))) + file-systems)) + (mapm %store-monad check-uuid-file-system + (filter (lambda (fs) + (uuid? (file-system-device fs))) + file-systems)))) + +(define (machine-check-initrd-modules machine) + "Raise a '&message' error condition if any of the modules needed by +'needed-for-boot' file systems in MACHINE are not available in the initrd." + (define file-systems + (filter file-system-needed-for-boot? + (operating-system-file-systems (machine-system machine)))) + + (define (missing-modules fs) + (define remote-exp + (let ((device (file-system-device fs))) + (with-imported-modules (source-module-closure + '((gnu build linux-modules))) + #~(begin + (use-modules (gnu build linux-modules)) + + (define dev + #$(cond ((string? device) device) + ((uuid? device) #~(find-partition-by-uuid #$device)) + ((file-system-label? device) + #~(find-partition-by-label + (file-system-label->string #$device))))) + + (missing-modules dev '#$(operating-system-initrd-modules + (machine-system machine))))))) + (mlet %store-monad ((missing (machine-remote-eval machine remote-exp))) + (return (list fs missing)))) + + (mlet %store-monad ((missing (mapm %store-monad missing-modules file-systems))) + (for-each (match-lambda + ((fs missing) + (unless (null? missing) + (raise (condition (&message + (message (format #f (G_ "~a missing modules ~{ ~a~}~%") + (file-system-device fs) missing)))))))) + missing) + (return #t))) + +(define (check-deployment-sanity machine) + "Raise a '&message' error condition if it is clear that deploying MACHINE's +'system' declaration would fail." + (mbegin %store-monad + (machine-check-file-system-availability machine) + (machine-check-initrd-modules machine))) + ;;; ;;; System deployment. @@ -165,8 +290,9 @@ of MACHINE's system profile, ordered from most recent to oldest." "Internal implementation of 'deploy-machine' for MACHINE instances with an environment type of 'managed-host." (maybe-raise-unsupported-configuration-error machine) - (mlet %store-monad ((boot-parameters (machine-boot-parameters machine))) - (let* ((os (machine-system machine)) + (mlet %store-monad ((_ (check-deployment-sanity machine)) + (boot-parameters (machine-boot-parameters machine))) + (let* ((os (machine-operating-system machine)) (eval (cut machine-remote-eval machine <>)) (menu-entries (map boot-parameters->menu-entry boot-parameters)) (bootloader-configuration (operating-system-bootloader os)) -- 2.22.0 From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 30 14:01:57 2019 Received: (at 36846) by debbugs.gnu.org; 30 Jul 2019 18:01:58 +0000 Received: from localhost ([127.0.0.1]:51142 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsWRg-0006cn-F1 for submit@debbugs.gnu.org; Tue, 30 Jul 2019 14:01:57 -0400 Received: from mx.sdf.org ([205.166.94.20]:53897) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hsWRc-0006cb-A6 for 36846@debbugs.gnu.org; Tue, 30 Jul 2019 14:01:53 -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 x6UI1ogi000343 (using TLSv1.2 with cipher AES256-GCM-SHA384 (256 bits) verified NO) for <36846@debbugs.gnu.org>; Tue, 30 Jul 2019 18:01:51 GMT From: zerodaysfordays@sdf.lonestar.org (Jakob L. Kreuze) To: 36846@debbugs.gnu.org Subject: [PATCH v3] machine: Implement safety checks. References: <87lfwgii14.fsf@sdf.lonestar.org> <87mugvv2ef.fsf@sdf.lonestar.org> Date: Tue, 30 Jul 2019 13:58:59 -0400 In-Reply-To: <87mugvv2ef.fsf@sdf.lonestar.org> (Jakob L. Kreuze's message of "Tue, 30 Jul 2019 13:49:12 -0400") Message-ID: <87imrjv1y4.fsf_-_@sdf.lonestar.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 36846 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable * gnu/machine/ssh.scm (machine-check-file-system-availability) (machine-check-initrd-modules, check-deployment-sanity): New variable. (deploy-managed-host): Perform safety checks before deploying. =2D-- gnu/machine/ssh.scm | 127 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 1 deletion(-) diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm index 552eafa9de..d60adccf67 100644 =2D-- a/gnu/machine/ssh.scm +++ b/gnu/machine/ssh.scm @@ -20,6 +20,9 @@ #:use-module (gnu machine) #:autoload (gnu packages gnupg) (guile-gcrypt) #:use-module (gnu system) + #:use-module (gnu system file-systems) + #:use-module (gnu system uuid) + #:use-module (guix diagnostics) #:use-module (guix gexp) #:use-module (guix i18n) #:use-module (guix modules) @@ -29,6 +32,7 @@ #:use-module (guix scripts system reconfigure) #:use-module (guix ssh) #:use-module (guix store) + #:use-module (guix utils) #:use-module (ice-9 match) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) @@ -98,6 +102,127 @@ an environment type of 'managed-host." (maybe-raise-unsupported-configuration-error machine) (remote-eval exp (machine-ssh-session machine))) =20 + +;;; +;;; Safety checks. +;;; + +(define (machine-check-file-system-availability machine) + "Raise a '&message' error condition if any of the file-systems specified= in +MACHINE's 'system' declaration do not exist on the machine." + (define file-systems + (filter (lambda (fs) + (and (file-system-mount? fs) + (not (member (file-system-type fs) + %pseudo-file-system-types)) + (not (memq 'bind-mount (file-system-flags fs))))) + (operating-system-file-systems (machine-operating-system machi= ne)))) + + (define (check-literal-file-system fs) + (define remote-exp + #~(catch 'system-error + (lambda () + (stat #$(file-system-device fs)) + #t) + (lambda args + (system-error-errno args)))) + + (mlet %store-monad ((errno (machine-remote-eval machine remote-exp))) + (when (number? errno) + (raise (condition + (&message (message (format #f (G_ "device '~a' not found: = ~a") + (file-system-device fs) + (strerror errno))))))) + (return #t))) + + (define (check-labeled-file-system fs) + (define remote-exp + (with-imported-modules '((gnu build file-systems)) + #~(begin + (use-modules (gnu build file-systems)) + (find-partition-by-label #$(file-system-label->string + (file-system-device fs)))))) + + (mlet %store-monad ((result (machine-remote-eval machine remote-exp))) + (unless result + (raise (condition (&message + (message (format #f (G_ "no file system with la= bel '~a'") + (file-system-label->string + (file-system-device fs)))))))) + (return #t))) + + (define (check-uuid-file-system fs) + (define remote-exp + (with-imported-modules '((gnu build file-systems)) + #~(begin + (use-modules (gnu build file-systems)) + (find-partition-by-uuid #$(file-system-device fs))))) + + (mlet %store-monad ((result (machine-remote-eval machine remote-exp))) + (unless result + (raise (condition (&message + (message (format #f (G_ "no file system with UU= ID '~a'") + (uuid->string (file-system-dev= ice fs)))))))) + (return #t))) + + (mbegin %store-monad + (mapm %store-monad check-literal-file-system + (filter (lambda (fs) + (string? (file-system-device fs))) + file-systems)) + (mapm %store-monad check-labeled-file-system + (filter (lambda (fs) + (file-system-label? (file-system-device fs))) + file-systems)) + (mapm %store-monad check-uuid-file-system + (filter (lambda (fs) + (uuid? (file-system-device fs))) + file-systems)))) + +(define (machine-check-initrd-modules machine) + "Raise a '&message' error condition if any of the modules needed by +'needed-for-boot' file systems in MACHINE are not available in the initrd." + (define file-systems + (filter file-system-needed-for-boot? + (operating-system-file-systems (machine-operating-system machi= ne)))) + + (define (missing-modules fs) + (define remote-exp + (let ((device (file-system-device fs))) + (with-imported-modules (source-module-closure + '((gnu build linux-modules))) + #~(begin + (use-modules (gnu build linux-modules)) + + (define dev + #$(cond ((string? device) device) + ((uuid? device) #~(find-partition-by-uuid #$device= )) + ((file-system-label? device) + #~(find-partition-by-label + (file-system-label->string #$device))))) + + (missing-modules dev '#$(operating-system-initrd-modules + (machine-operating-system machine))= ))))) + (mlet %store-monad ((missing (machine-remote-eval machine remote-exp))) + (return (list fs missing)))) + + (mlet %store-monad ((missing (mapm %store-monad missing-modules file-sys= tems))) + (for-each (match-lambda + ((fs missing) + (unless (null? missing) + (raise (condition (&message + (message (format #f (G_ "~a missing = modules ~{ ~a~}~%") + (file-system-device= fs) missing)))))))) + missing) + (return #t))) + +(define (check-deployment-sanity machine) + "Raise a '&message' error condition if it is clear that deploying MACHIN= E's +'system' declaration would fail." + (mbegin %store-monad + (machine-check-file-system-availability machine) + (machine-check-initrd-modules machine))) + ;;; ;;; System deployment. @@ -166,7 +291,7 @@ of MACHINE's system profile, ordered from most recent t= o oldest." environment type of 'managed-host." (maybe-raise-unsupported-configuration-error machine) (mlet %store-monad ((boot-parameters (machine-boot-parameters machine))) =2D (let* ((os (machine-system machine)) + (let* ((os (machine-operating-system machine)) (eval (cut machine-remote-eval machine <>)) (menu-entries (map boot-parameters->menu-entry boot-parameters)) (bootloader-configuration (operating-system-bootloader os)) =2D-=20 2.22.0 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEa1VJLOiXAjQ2BGSm9Qb9Fp2P2VoFAl1AhWMACgkQ9Qb9Fp2P 2Vpuww/+IY3YfjoecPDX1TAk3/JSQDRKX3JdOq0RWTwoBz/uAQZ9wgw+sJrU6G0y DYnqw5EqI76KCGRzDMojyhDEoB87ufYA7B67NB3yLdMq7GVnJQVk0Urw6LpW08ow wG/Bw06CMWiUqcL0AG6CL0hbKny4+AOqajyX2b40RHEJ/oNVFI/MiXqVe0zkOz2W qHvnG8ObzDOoC0TXstTy+jJnyNgxlxkrcX0i8d5pw9MJV8vAu5f/xZABziPdAt9l OtPOYzBlnvY8SYTdhVl4pCgGD2NUlTDJ2SEjjlnYVugRHB/kEdIzicfTdpd0bCZc n6Tz0zxoGjbOLPaCVuTQS1gNHFcms1XJeZ1dyjCRHoslaFIgKGsCqPnbgxagLgyr x+Y4aBDNhXxGrUtiNvWy7qKp2z229z3HePY4VQMTSo0vZB6bMHR2AlEpjTAuM8Fy GsvbrZuLARDt26hxahIba8mmM4S/KLrnPEtGRdJqBbuHHxeRKGBYQANNQBNa5VxU 9/WHJh+kktTYivYVShdAHevW8g/FLCZcsTeYpx/5NGAW1D7w3D00mcxApBFT2LDS cadN7dI1kb1jq4VXAys1ubNMQ6hGLsXtMuj6QiJyL9/8MxQORc+8zyalf4zZc2Wa vzlPK8zN8hjax+u4Ps+emcjOAOhlpZU52UDFGYta4PjPyiWi8ig= =/dfV -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 31 10:41:28 2019 Received: (at 36846) by debbugs.gnu.org; 31 Jul 2019 14:41:28 +0000 Received: from localhost ([127.0.0.1]:52865 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hspnE-0001Sh-BV for submit@debbugs.gnu.org; Wed, 31 Jul 2019 10:41:28 -0400 Received: from mx.sdf.org ([205.166.94.20]:63865) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hspnB-0001SY-Op for 36846@debbugs.gnu.org; Wed, 31 Jul 2019 10:41:26 -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 x6VEfNAu010186 (using TLSv1.2 with cipher AES256-GCM-SHA384 (256 bits) verified NO) for <36846@debbugs.gnu.org>; Wed, 31 Jul 2019 14:41:24 GMT From: zerodaysfordays@sdf.lonestar.org (Jakob L. Kreuze) To: 36846@debbugs.gnu.org Subject: [PATCH v4] machine: Implement safety checks. References: <87lfwgii14.fsf@sdf.lonestar.org> <87mugvv2ef.fsf@sdf.lonestar.org> <87imrjv1y4.fsf_-_@sdf.lonestar.org> Date: Wed, 31 Jul 2019 10:38:29 -0400 In-Reply-To: <87imrjv1y4.fsf_-_@sdf.lonestar.org> (Jakob L. Kreuze's message of "Tue, 30 Jul 2019 13:58:59 -0400") Message-ID: <875znie0be.fsf_-_@sdf.lonestar.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 36846 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable * gnu/machine/ssh.scm (machine-check-file-system-availability) (machine-check-initrd-modules, check-deployment-sanity): New variable. (deploy-managed-host): Perform safety checks before deploying. =2D-- gnu/machine/ssh.scm | 148 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 146 insertions(+), 2 deletions(-) diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm index 552eafa9de..274d56db26 100644 =2D-- a/gnu/machine/ssh.scm +++ b/gnu/machine/ssh.scm @@ -20,6 +20,9 @@ #:use-module (gnu machine) #:autoload (gnu packages gnupg) (guile-gcrypt) #:use-module (gnu system) + #:use-module (gnu system file-systems) + #:use-module (gnu system uuid) + #:use-module (guix diagnostics) #:use-module (guix gexp) #:use-module (guix i18n) #:use-module (guix modules) @@ -29,6 +32,7 @@ #:use-module (guix scripts system reconfigure) #:use-module (guix ssh) #:use-module (guix store) + #:use-module (guix utils) #:use-module (ice-9 match) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) @@ -98,6 +102,145 @@ an environment type of 'managed-host." (maybe-raise-unsupported-configuration-error machine) (remote-eval exp (machine-ssh-session machine))) =20 + +;;; +;;; Safety checks. +;;; + +(define (machine-check-file-system-availability machine) + "Raise a '&message' error condition if any of the file-systems specified= in +MACHINE's 'system' declaration do not exist on the machine." + (define file-systems + (filter (lambda (fs) + (and (file-system-mount? fs) + (not (member (file-system-type fs) + %pseudo-file-system-types)) + (not (memq 'bind-mount (file-system-flags fs))))) + (operating-system-file-systems (machine-operating-system machi= ne)))) + + (define (check-literal-file-system fs) + (define remote-exp + #~(catch 'system-error + (lambda () + (stat #$(file-system-device fs)) + #t) + (lambda args + (system-error-errno args)))) + + (mlet %store-monad ((errno (machine-remote-eval machine remote-exp))) + (when (number? errno) + (raise (condition + (&message + (message (format #f (G_ "device '~a' not found: ~a") + (file-system-device fs) + (strerror errno))))))) + (return #t))) + + (define (check-labeled-file-system fs) + (define remote-exp + (with-imported-modules '((gnu build file-systems)) + #~(begin + (use-modules (gnu build file-systems)) + (find-partition-by-label #$(file-system-label->string + (file-system-device fs)))))) + + (mlet %store-monad ((result (machine-remote-eval machine remote-exp))) + (unless result + (raise (condition + (&message + (message (format #f (G_ "no file system with label '~a'") + (file-system-label->string + (file-system-device fs)))))))) + (return #t))) + + (define (check-uuid-file-system fs) + (define remote-exp + (with-imported-modules (source-module-closure + '((gnu build file-systems) + (gnu system uuid))) + #~(begin + (use-modules (gnu build file-systems) + (gnu system uuid)) + + (define uuid + (string->uuid #$(uuid->string (file-system-device fs)))) + + (find-partition-by-uuid uuid)))) + + (mlet %store-monad ((result (machine-remote-eval machine remote-exp))) + (unless result + (raise (condition + (&message + (message (format #f (G_ "no file system with UUID '~a'") + (uuid->string (file-system-device fs))))= )))) + (return #t))) + + (mbegin %store-monad + (mapm %store-monad check-literal-file-system + (filter (lambda (fs) + (string? (file-system-device fs))) + file-systems)) + (mapm %store-monad check-labeled-file-system + (filter (lambda (fs) + (file-system-label? (file-system-device fs))) + file-systems)) + (mapm %store-monad check-uuid-file-system + (filter (lambda (fs) + (uuid? (file-system-device fs))) + file-systems)))) + +(define (machine-check-initrd-modules machine) + "Raise a '&message' error condition if any of the modules needed by +'needed-for-boot' file systems in MACHINE are not available in the initrd." + (define file-systems + (filter file-system-needed-for-boot? + (operating-system-file-systems (machine-operating-system machi= ne)))) + + (define (missing-modules fs) + (define remote-exp + (let ((device (file-system-device fs))) + (with-imported-modules (source-module-closure + '((gnu build file-systems) + (gnu build linux-modules) + (gnu system uuid))) + #~(begin + (use-modules (gnu build file-systems) + (gnu build linux-modules) + (gnu system uuid)) + + (define dev + #$(cond ((string? device) device) + ((uuid? device) #~(find-partition-by-uuid + (string->uuid + #$(uuid->string device)))) + ((file-system-label? device) + #~(find-partition-by-label + (file-system-label->string #$device))))) + + (missing-modules dev '#$(operating-system-initrd-modules + (machine-operating-system machine))= ))))) + (mlet %store-monad ((missing (machine-remote-eval machine remote-exp))) + (return (list fs missing)))) + + (mlet %store-monad ((device (mapm %store-monad missing-modules file-syst= ems))) + (for-each (match-lambda + ((fs missing) + (unless (null? missing) + (raise (condition + (&message + (message (format #f (G_ "~a missing modules ~{= ~a~}~%") + (file-system-device fs) + missing)))))))) + device) + (return #t))) + +(define (check-deployment-sanity machine) + "Raise a '&message' error condition if it is clear that deploying MACHIN= E's +'system' declaration would fail." + (mbegin %store-monad + (machine-check-file-system-availability machine) + (machine-check-initrd-modules machine))) + ;;; ;;; System deployment. @@ -165,8 +308,9 @@ of MACHINE's system profile, ordered from most recent t= o oldest." "Internal implementation of 'deploy-machine' for MACHINE instances with = an environment type of 'managed-host." (maybe-raise-unsupported-configuration-error machine) =2D (mlet %store-monad ((boot-parameters (machine-boot-parameters machine)= )) =2D (let* ((os (machine-system machine)) + (mlet %store-monad ((_ (check-deployment-sanity machine)) + (boot-parameters (machine-boot-parameters machine))) + (let* ((os (machine-operating-system machine)) (eval (cut machine-remote-eval machine <>)) (menu-entries (map boot-parameters->menu-entry boot-parameters)) (bootloader-configuration (operating-system-bootloader os)) =2D-=20 2.22.0 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEa1VJLOiXAjQ2BGSm9Qb9Fp2P2VoFAl1Bp+UACgkQ9Qb9Fp2P 2VqReA/9H3OrOnjRb7lwnN69h0RHcox1BlAB7kI/mVGfG/SAcBKn/plJRxacysDn mJfpUhWfwnpzQlZjIu+qXgPnVthXGPy2bsj7d1Jv3SAMoNpDJYb9znbrVBicNxWr GS+UmN44BNakbRKyrcACMCmHB14gd//n5H4IvEbcKQ+/AK00GHFOztWRYAUJA2rK mT+0t6PHDOGSVhCm5pQulho9yRUPX9TcrwHp3eCu2CoAYnmgyBkd0/kIwz9BDJA4 0sigJ/8lq8LhpvQjWxjdEYYXRtvSMetSTMUaN7qHl3MVpKoa0mtBUY2YpwF8ZP0w bZXUHz5Lemz8CffsfLsnmjKloXkN7GzOCm5i/Sa2hXpWhQt1tnh+/VcJhr0lIhRC neqbBOPSFdKIjV8P1vkCkNNRJmTMcT6ei/LhQE9ZhuPwNnC8DiXMgKH929/dCNXc gviKEqj8MmW+JeCjsP0Om2ZwRCkuA9CMDg+fYlDCsie1/6lj9GztGIsUaCkWhF3b ebElK4mV95K7ab17GIkChwU7OpeA2bXHrb65fGQVyXM3V/BFheLrmZigSpH/edoM zso2xF77pKXRxvwkzqckNXfl5OA3rZC2pM0W/2Fsjkhfa0x8G5RfvTn57ry2l2k4 yMbvy0zr3VdSNqFylvP4dcTCjxv4AOMkdKTe7KmHcOYvuCSJl9A= =iXvS -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 06 16:41:20 2019 Received: (at submit) by debbugs.gnu.org; 6 Aug 2019 20:41:20 +0000 Received: from localhost ([127.0.0.1]:37873 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hv6Gm-0005qV-GS for submit@debbugs.gnu.org; Tue, 06 Aug 2019 16:41:20 -0400 Received: from lists.gnu.org ([209.51.188.17]:58634) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hv6Gk-0005qN-Hh for submit@debbugs.gnu.org; Tue, 06 Aug 2019 16:41:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36453) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hv6Gj-0007m1-Nc for guix-patches@gnu.org; Tue, 06 Aug 2019 16:41:18 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hv6Gi-0005ni-U0 for guix-patches@gnu.org; Tue, 06 Aug 2019 16:41:17 -0400 Received: from dustycloud.org ([50.116.34.160]:38330) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hv6Gi-0005nT-Q7 for guix-patches@gnu.org; Tue, 06 Aug 2019 16:41:16 -0400 Received: from twig (localhost [127.0.0.1]) by dustycloud.org (Postfix) with ESMTPS id B546626618; Tue, 6 Aug 2019 16:41:15 -0400 (EDT) References: <87lfwgii14.fsf@sdf.lonestar.org> User-agent: mu4e 1.2.0; emacs 26.2 From: Christopher Lemmer Webber To: guix-patches@gnu.org Subject: Re: [bug#36846] [PATCH] machine: Implement safety checks. In-reply-to: <87lfwgii14.fsf@sdf.lonestar.org> Date: Tue, 06 Aug 2019 16:41:15 -0400 Message-ID: <87ftmeowlw.fsf@dustycloud.org> MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 50.116.34.160 X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit Cc: 36846-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) Merged and pushed! From unknown Tue Jun 24 17:28:15 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 04 Sep 2019 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator