From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id UFngKrhEGWe4LAAAqHPOHw:P1 (envelope-from ) for ; Wed, 23 Oct 2024 18:47:20 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id UFngKrhEGWe4LAAAqHPOHw (envelope-from ) for ; Wed, 23 Oct 2024 20:47:20 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=GERbnpyh; dkim=fail ("headers rsa verify failed") header.d=freakingpenguin.com header.s=x header.b=XqKJyctY; 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"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1729709240; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: 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=Yps8+VrzjsqGW5X9iYieiHHsFYW5sWkljBmrUcqi5cU=; b=Km2b/VhJawznUnspv1uwCuOPlsXZdLEbQCXq5OzMv42oey3L/bTx72HzVg0XHT8U51j59T WNtTEePPUHM25MSabN0MxNNjeRDnhvbZZEragLfmYMRYcHlgl/nTAtqJ/W0q/ajEIvqK/m SYGioHhLJnOwFY2oQLKOD9tdhg4wzngS0FfSvYA3Q606upkXJNsVpYJDu+b8vGQh4EOFR1 /AHEmL+DnnWtqasXJ5U8kB68lWEAXCsQg4VCgTTNzknDPbGZ+3RfJoq30WdMrTh7uSRFqC 74TfsSkNklaAtJ18Sc1wPfOvcvDwpMJXotjiPCXhUmDPOohfgaw9cyJXR89UAw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1729709240; a=rsa-sha256; cv=none; b=V0qpZB+asqLsy+CfGL4WHdLOxopR9dAKAUmZbhhGYqoEbGV6bqR6nUn0/hjnpfakIQkTlR +lRzk82f221anqohr9qlK5kcMjhZLmkhJVqu5mR8mmzRX6m4q35+WLdAiavUnkrPu5i864 z240d7HKwvvn4X6+SYYG9cV65vXW9azruAPkkYUQ0eV9LPM1txbvMQJqZGdI+8NsY8WO8q zaHaM/3TaFrmRG0ux2izj7/TEbC43TV6twZdfxReYLfI5Mxs4VpPM1Qv7BrcvuWuFy4Uok 22ZbE3mup9UQ+skpH7N2+7/mX3Txvvt+/5X9Y2PBWhCgiF9R93XvcEAavAj0Wg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=GERbnpyh; dkim=fail ("headers rsa verify failed") header.d=freakingpenguin.com header.s=x header.b=XqKJyctY; 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"; dmarc=none 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 685615DB97 for ; Wed, 23 Oct 2024 20:47:20 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3gNV-0005wU-Po; Wed, 23 Oct 2024 14:46:41 -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 1t3gNM-0005up-Ii for guix-patches@gnu.org; Wed, 23 Oct 2024 14:46:37 -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 1t3gNM-0002JC-9l; Wed, 23 Oct 2024 14:46:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=Yps8+VrzjsqGW5X9iYieiHHsFYW5sWkljBmrUcqi5cU=; b=GERbnpyha+vjj2Nchw9qrIjxnPC50O6wU8lBZqJRlIYDb6GWt948XnBJAXpLz5LvLfEP8ULlEX1R30V/b7BKtt+/K9hOyGQ3JExXd5YpLpmMS/H5krtKTVSj76jisSMmOwiRtNCkOprjlfCdyd7YnX+7nv7h/8zPx5ra7mmxSnWRqpF5dYm9PdBf+lJIg8yExYdouHEHaYZItVBKoJVyreKa6C9IKXNnd82pFv9DKKBJgpxUUq+YsXiCK1gudo+X/uoFFL+VA0LEgawAtz7etJYapyyNIphefHK8axtF/X4On+JqoWOftBsvcoPHjrtkYm6HOPBLOu3/yASM8gqo4Q==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t3gNp-00025J-L4; Wed, 23 Oct 2024 14:47:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73955] [PATCH v3 1/3] services: wireguard: Make the private-key field optional. Resent-From: Richard Sent Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Wed, 23 Oct 2024 18:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73955 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 73955@debbugs.gnu.org Cc: Richard Sent , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 73955-submit@debbugs.gnu.org id=B73955.17297091887925 (code B ref 73955); Wed, 23 Oct 2024 18:47:01 +0000 Received: (at 73955) by debbugs.gnu.org; 23 Oct 2024 18:46:28 +0000 Received: from localhost ([127.0.0.1]:60797 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3gNH-00023h-SL for submit@debbugs.gnu.org; Wed, 23 Oct 2024 14:46:28 -0400 Received: from mail-108-mta101.mxroute.com ([136.175.108.101]:35099) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3gNF-00023R-DI for 73955@debbugs.gnu.org; Wed, 23 Oct 2024 14:46:26 -0400 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta101.mxroute.com (ZoneMTA) with ESMTPSA id 192bab3207e0003e01.001 for <73955@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 23 Oct 2024 18:45:54 +0000 X-Zone-Loop: dd171930292cbf9799cd9ce9cf890fb3e9203317cb89 X-Originating-IP: [136.175.111.3] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Yps8+VrzjsqGW5X9iYieiHHsFYW5sWkljBmrUcqi5cU=; b=XqKJyctYDFSdmf0rmkdFoBKMDF BXMyBbDi5u8MhjzMDchLUOho5aMpyJtuUjHf2L5cd062fBOouiZ5YHPMcgRmbXQWtDDoL4ZoU/Uq/ xfndDuTc93jloJ+c6s2W4Y+mIbD/It7IRZhqkj0SyrxBER6VrHCxlqlN/H3fcYdN0l2Sn9T3GBYfl 3Wsk56cvXWwMXSdDzY+wlxmVhqvfR1KZANqKQwBm9g9oTPDmldvBemAstU26gtpVdsZtk6sPC4mZz I7sc3AQqUF5u9cUEDCeSSHAueI65jiqXTwfvt4wdLvBBNy3UCde/lfPO+M/I3rDaftM0FZcweSRHp hO/rYyrw==; From: Richard Sent Date: Wed, 23 Oct 2024 14:20:57 -0400 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authenticated-Id: richard@freakingpenguin.com 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -1.97 X-Spam-Score: -1.97 X-Migadu-Queue-Id: 685615DB97 X-Migadu-Scanner: mx13.migadu.com X-TUID: 6Q6DDGgqflD1 Users who retrieve the private-key via a PreUp field need to be able to disable the default retrieval mechanism. * gnu/services/vpn.scm ()[private-key]: Change comment. (wireguard-configuration-file): Conditionally serialize private-key. * gnu/services/vpn.scm (wireguard-activation): Do not create private-key if the field is #f. * doc/guix.texi (VPN Services)[wireguard-configuration]: Document it. Change-Id: Iac419809ae94eb76e97ff1f1749e2f4b3e65bb04 --- doc/guix.texi | 5 ++++- gnu/services/vpn.scm | 36 ++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index ac3a7adef0..5558bd7d44 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -34453,7 +34453,10 @@ VPN Services @item @code{private-key} (default: @code{"/etc/wireguard/private.key"}) The private key file for the interface. It is automatically generated -if the file does not exist. +if the file does not exist. If this field is @code{#f}, a private key +is not created and the path is not serialized to the configuration file. +This allows for retrieving the private key programmatically with a PreUp +command. @item @code{peers} (default: @code{'()}) The authorized peers on this interface. This is a list of diff --git a/gnu/services/vpn.scm b/gnu/services/vpn.scm index 7fb4775757..b62e0ac838 100644 --- a/gnu/services/vpn.scm +++ b/gnu/services/vpn.scm @@ -741,7 +741,7 @@ (define-record-type* (default '("10.0.0.1/32"))) (port wireguard-configuration-port ;integer (default 51820)) - (private-key wireguard-configuration-private-key ;string + (private-key wireguard-configuration-private-key ;maybe-string (default "/etc/wireguard/private.key")) (peers wireguard-configuration-peers ;list of (default '())) @@ -805,9 +805,12 @@ (define (wireguard-configuration-file config) #$@(if (null? pre-up) '() (list (format #f "~{PreUp = ~a~%~}" pre-up))) - (format #f "PostUp = ~a set %i private-key ~a\ -~{ peer ~a preshared-key ~a~}" #$(file-append wireguard "/bin/wg") -#$private-key '#$peer-keys) + (if #$private-key + (format #f "PostUp = ~a set %i private-key ~a\ +~{ peer ~a preshared-key ~a~}" + #$(file-append wireguard "/bin/wg") + #$private-key '#$peer-keys) + "") #$@(if (null? post-up) '() (list (format #f "~{PostUp = ~a~%~}" post-up))) @@ -838,18 +841,19 @@ (define (wireguard-activation config) (use-modules (guix build utils) (ice-9 popen) (ice-9 rdelim)) - (mkdir-p (dirname #$private-key)) - (unless (file-exists? #$private-key) - (let* ((pipe - (open-input-pipe (string-append - #$(file-append wireguard "/bin/wg") - " genkey"))) - (key (read-line pipe))) - (call-with-output-file #$private-key - (lambda (port) - (display key port))) - (chmod #$private-key #o400) - (close-pipe pipe)))))) + (when #$private-key + (mkdir-p (dirname #$private-key)) + (unless (file-exists? #$private-key) + (let* ((pipe + (open-input-pipe (string-append + #$(file-append wireguard "/bin/wg") + " genkey"))) + (key (read-line pipe))) + (call-with-output-file #$private-key + (lambda (port) + (display key port))) + (chmod #$private-key #o400) + (close-pipe pipe))))))) ;;; XXX: Copied from (guix scripts pack), changing define to define*. (define-syntax-rule (define-with-source (variable args ...) body body* ...) -- 2.46.0