From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id +PcWCArgkmHSIgAAgWs5BA (envelope-from ) for ; Mon, 15 Nov 2021 23:32:42 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 6PPAAwrgkmGIBgAAB5/wlQ (envelope-from ) for ; Mon, 15 Nov 2021 22:32:42 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A103535CCA for ; Mon, 15 Nov 2021 23:32:41 +0100 (CET) Received: from localhost ([::1]:57734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmkWm-0001Yh-QD for larch@yhetil.org; Mon, 15 Nov 2021 17:32:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmkWG-0000AF-OJ for guix-patches@gnu.org; Mon, 15 Nov 2021 17:32:08 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:44916) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmkWD-0002BT-S8 for guix-patches@gnu.org; Mon, 15 Nov 2021 17:32:08 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mmkWD-0003mF-PB for guix-patches@gnu.org; Mon, 15 Nov 2021 17:32:05 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51440] [PATCH v2 06/10] services: secret-service: Turn into a Shepherd service. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 15 Nov 2021 22:32:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51440 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51440@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 51440-submit@debbugs.gnu.org id=B51440.163701549514405 (code B ref 51440); Mon, 15 Nov 2021 22:32:05 +0000 Received: (at 51440) by debbugs.gnu.org; 15 Nov 2021 22:31:35 +0000 Received: from localhost ([127.0.0.1]:56452 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmkVj-0003k9-6E for submit@debbugs.gnu.org; Mon, 15 Nov 2021 17:31:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52534) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmkVD-0003h0-RE for 51440@debbugs.gnu.org; Mon, 15 Nov 2021 17:31:19 -0500 Received: from [2001:470:142:3::e] (port=52028 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmkV8-00020I-KM; Mon, 15 Nov 2021 17:30:58 -0500 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=bcmo7xmK+6SxMv3uGAmGe4imHaZ1c5Pp8ko/UcmS2CM=; b=m6DhNfVqhClrWJyQSIWE b/f5S+EeYV/voc2ua+f7o79HVQy/W2Le4n3t6gI7DJiNfCrmAmszZwapeukQ/N3nRGS3TecN9T3nX 1SYDlUf8ZGzgPaApUghYx6vpKSzi3vuAfqQJ2hSjplMVtQ+ShvrMiD4SJ8MaUDG0e0P7kKBwelmOr qcl710LN0thv0EqZ+vByXEw0LX9DSJkhWD1iB6wOIxN9Dh2ZdEo7JkYpt+m5ALAZE19txqXKqAQQC H6zdXXFr7QSOZR0pAviieEltclqjrG6Ov41EhOkyHODsP6wwsjZgMG/xFAG3UrKLOe/sQbVTQ9gu9 DilnKFL4ZTqzsA==; Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=44414 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmkV8-0001jO-Cg; Mon, 15 Nov 2021 17:30:58 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Mon, 15 Nov 2021 23:30:40 +0100 Message-Id: <20211115223044.10943-7-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211115223044.10943-1-ludo@gnu.org> References: <20211027135918.18833-1-ludo@gnu.org> <20211115223044.10943-1-ludo@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1637015561; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=bcmo7xmK+6SxMv3uGAmGe4imHaZ1c5Pp8ko/UcmS2CM=; b=ptuEmkOvsRW5f+4Dp4eUOuvxqFCwAiacbWIuJ8mbOiOZwmS1vS5mYTiqtcpix/Qbt6e8se E+Fw69MrpIbCl03EP3QYj6TH3kgxkWRjLLCl5sIwBis9orG2M0rVBcZEAhRys/qQ1R2/0i FeC0fknyn5RaU8Tm4UTBH70N4YuFSgZLo1jLUfmldLSi/8+az6UPIYbn9Lo8sMrz5vZUv2 DEu06JIHkBw8QBWi5AH6hndmI3rRoYycxu4z2NzUQuorceydvhiZ+I3ABi4ABn+qih6s9O bqruRoZbRaTN+BbUawklxlsbnKdyJ+vhCvtYfrBrTtV8EfTcgTp7jUKL55MLpA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1637015561; a=rsa-sha256; cv=none; b=lGPYpAtuaGx4tz4hMbvgOYTTZTp1Akf+K1A0Wr8ie4RTNWz0F50tGrBf0vMHxDAEH7Vz+Y J6xv/qEIKNHO+czxROX2p5FUhf1mbYqqN1cHGDSfVv/6ngEug5YsMTyiwB3TjlZBy3QT9W lSbwm5sHdOBME8b1pUV1r4/HXx9xo57hs/w1Mn28okXObKN8HLGXmrSf4PO3osCz5319Zm k6+b6oCjPFLPcteDtOAbGiP4brvLVXCaypE9sv1kneFqrI2leF8o00KtfDnqtx1hIdQ5kj dCbFOT+TWlsv8Vohv2s9hYBhxuyPwuhXHGF3iPp/vTDZjE5qfoU//7GFAfHmNQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=m6DhNfVq; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.04 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=m6DhNfVq; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: A103535CCA X-Spam-Score: -1.04 X-Migadu-Scanner: scn0.migadu.com X-TUID: yCRbIhLL4Lx/ * gnu/services/virtualization.scm (secret-service-activation): Remove. (secret-service-shepherd-services): New procedure. (secret-service-type)[extensions]: Remove ACTIVATION-SERVICE-TYPE extension. Add SHEPHERD-ROOT-SERVICE-TYPE and USER-PROCESSES-SERVICE-TYPE extensions. * gnu/build/secret-service.scm (delete-file*): New procedure. (secret-service-receive-secrets): Use it. --- gnu/build/secret-service.scm | 17 ++++++++++++- gnu/services/virtualization.scm | 45 ++++++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/gnu/build/secret-service.scm b/gnu/build/secret-service.scm index 46dcf1b9c3..4e183e11e8 100644 --- a/gnu/build/secret-service.scm +++ b/gnu/build/secret-service.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2020 Ludovic Courtès +;;; Copyright © 2020, 2021 Ludovic Courtès ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen ;;; ;;; This file is part of GNU Guix. @@ -111,6 +111,15 @@ (define (send-files sock) (close-port sock) #f)))) +(define (delete-file* file) + "Ensure FILE does not exist." + (catch 'system-error + (lambda () + (delete-file file)) + (lambda args + (unless (= ENOENT (system-error-errno args)) + (apply throw args))))) + (define (secret-service-receive-secrets port) "Listen to local PORT and wait for a secret service client to send secrets. Write them to the file system. Return the list of files installed on success, @@ -170,6 +179,12 @@ (define (read-secrets port) (log "installing file '~a' (~a bytes)...~%" file size) (mkdir-p (dirname file)) + + ;; It could be that FILE already exists, for instance + ;; because it has been created by a service's activation + ;; snippet (e.g., SSH host keys). Delete it. + (delete-file* file) + (call-with-output-file file (lambda (output) (dump port output size) diff --git a/gnu/services/virtualization.scm b/gnu/services/virtualization.scm index 1a5744ffbf..b1b10afed6 100644 --- a/gnu/services/virtualization.scm +++ b/gnu/services/virtualization.scm @@ -898,23 +898,44 @@ (define qemu-guest-agent-service-type ;;; Secrets for guest VMs. ;;; -(define (secret-service-activation port) - "Return an activation snippet that fetches sensitive material at local PORT, +(define (secret-service-shepherd-services port) + "Return a Shepherd service that fetches sensitive material at local PORT, over TCP. Reboot upon failure." - (with-imported-modules '((gnu build secret-service) - (guix build utils)) - #~(begin - (use-modules (gnu build secret-service)) - (let ((sent (secret-service-receive-secrets #$port))) - (unless sent - (sleep 3) - (reboot)))))) + ;; This is a Shepherd service, rather than an activation snippet, to make + ;; sure it is started once 'networking' is up so it can accept incoming + ;; connections. + (list + (shepherd-service + (documentation "Fetch secrets from the host at startup time.") + (provision '(secret-service-client)) + (requirement '(loopback networking)) + (modules '((gnu build secret-service) + (guix build utils))) + (start (with-imported-modules '((gnu build secret-service) + (guix build utils)) + #~(lambda () + ;; Since shepherd's output port goes to /dev/log, write this + ;; message to stderr so it's visible on the Mach console. + (format (current-error-port) + "receiving secrets from the host...~%") + (force-output (current-error-port)) + + (let ((sent (secret-service-receive-secrets #$port))) + (unless sent + (sleep 3) + (reboot)))))) + (stop #~(const #f))))) (define secret-service-type (service-type (name 'secret-service) - (extensions (list (service-extension activation-service-type - secret-service-activation))) + (extensions (list (service-extension shepherd-root-service-type + secret-service-shepherd-services) + + ;; Make every Shepherd service depend on + ;; 'secret-service-client'. + (service-extension user-processes-service-type + (const '(secret-service-client))))) (description "This service fetches secret key and other sensitive material over TCP at boot time. This service is meant to be used by virtual machines (VMs) that -- 2.33.0