From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id KGClCWlreWHlIwAAgWs5BA (envelope-from ) for ; Wed, 27 Oct 2021 17:08:25 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id aEheBWlreWHXTAAAB5/wlQ (envelope-from ) for ; Wed, 27 Oct 2021 15:08:25 +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 BC9B237DFD for ; Wed, 27 Oct 2021 17:08:24 +0200 (CEST) Received: from localhost ([::1]:34056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfkXP-0000rw-T1 for larch@yhetil.org; Wed, 27 Oct 2021 11:08:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfjXA-0008Mz-DD for guix-patches@gnu.org; Wed, 27 Oct 2021 10:04:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:38545) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mfjXA-0005GP-2p for guix-patches@gnu.org; Wed, 27 Oct 2021 10:04:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mfjX9-0002ZN-VL for guix-patches@gnu.org; Wed, 27 Oct 2021 10:04:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51440] [PATCH 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: Wed, 27 Oct 2021 14:04:03 +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.16353433999740 (code B ref 51440); Wed, 27 Oct 2021 14:04:03 +0000 Received: (at 51440) by debbugs.gnu.org; 27 Oct 2021 14:03:19 +0000 Received: from localhost ([127.0.0.1]:50078 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfjWQ-0002Wv-Fe for submit@debbugs.gnu.org; Wed, 27 Oct 2021 10:03:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45564) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfjWJ-0002VZ-9G for 51440@debbugs.gnu.org; Wed, 27 Oct 2021 10:03:11 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:37974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfjWE-00058C-2T; Wed, 27 Oct 2021 10:03:06 -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=1jh4ueGONL6MEUTK8CSCWdtTCOUYwpUL8SHWIX5sYIA=; b=PTt0C10z1q0woPvL9CLf IoA/+VSsLLvLHsaTpPfpuWSwiz78LqoBcLWAjEq76uv6UCoKB7aWplMFChGJG3sN6xhF6jGtU8tjl CPWwT2HDFvlIqrA0/Y0fF7/xPr1ETIqYYDmuBU+6EvvQYehVQKBA0BS/7AFD1Cy48j7/c8hXiJM5x qecMtdy2H/BdCF/k4hIFTIS2nnyTTeefVRhB6HM7yAaVmqWy0nTDXD0bq3WG99vGZCOLHsOigoFdc MRmbTjRenzLL4paOukld5wOrHQunqtCvrGWMuFk7jGsj27+d0cLeLaTRYX2Brdhvknax5B9g4uq6p vJepM/SmvjC4qg==; Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=55004 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 1mfjWD-0002Tf-M4; Wed, 27 Oct 2021 10:03:05 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 27 Oct 2021 16:02:41 +0200 Message-Id: <20211027140245.18970-6-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211027140245.18970-1-ludo@gnu.org> References: <20211027140245.18970-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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1635347304; 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=1jh4ueGONL6MEUTK8CSCWdtTCOUYwpUL8SHWIX5sYIA=; b=WbcdX3rV+thxaPKPS2SGq24ISbKYHAwHpxSkxRXIA3TiPXJD49caPy9KwKHfVO12AxJL+W cCxYRnRfmiyRI3chMp3NtxgwmmqkYMLplIdRz0/fAlibnfcpexNo9Pbt+YdrswTxofLE94 gEnQ0QM4tAYOVR/+sXup9OogxW7qXE/pGgE+Rk7amlESiJEnCR680McwsM4MEc3TSV5EQN YduZglSZ6sTvB3Mf4CgQ4PkWlgoNPID1mtSIE+KShD6QUBsKXkaWv/sKPgCfi1RzQCT9/1 QX/50reFG2KlrpKGFJLscSiLeFwHEle8cjlzkvKGm+uTt7UmwBp4749iMU2B4A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1635347304; a=rsa-sha256; cv=none; b=epzqehaB+Fgs9pQlzM5hpeOt0FysHdCK0OrfMKmPMT9uiI6dYG/MTZElkXaxAtIOd+NGNx E23mV7RD5T+5U/ABuGc2bZRLrhncmdGL1a9RVvtnOC3p/Tu+x7ZKOLDT/oxWAFlWNXNj0X QHywjGI/X5pKU/Dp9uJjBgXRjfjnBkXHcpZRV0a08imxR6S6WQfmCioV9kywwdUrgImEha Rk6VLOGVHcVepi+7hVOSIku6UhccfKQnfIvmo8x+Z929NQpbDu11fYdJrKXMGE4FogBCko D6htUdKiT/wk/uVcdtbVJESX25O3x2wkmK4r7CI424UUFcigTvwFSvdVLSvyaw== 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=PTt0C10z; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -0.43 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=PTt0C10z; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: BC9B237DFD X-Spam-Score: -0.43 X-Migadu-Scanner: scn0.migadu.com X-TUID: 8xCXoxB0b/nY * 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 bca5f56b87..e7d2a7b833 100644 --- a/gnu/services/virtualization.scm +++ b/gnu/services/virtualization.scm @@ -852,23 +852,44 @@ (define qemu-binfmt-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