From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id oKjRDZ0YGGeoBwEA62LTzQ:P1 (envelope-from ) for ; Tue, 22 Oct 2024 21:26:53 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id oKjRDZ0YGGeoBwEA62LTzQ (envelope-from ) for ; Tue, 22 Oct 2024 23:26:53 +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=CV28kRRa; dkim=fail ("headers rsa verify failed") header.d=freakingpenguin.com header.s=x header.b=J5A+c4ug; dmarc=none; 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" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1729632412; a=rsa-sha256; cv=none; b=IrQBg+Av5Xnof0l1qN0Ghv3wHAM6sS3irSHw1fgaLBpeoWfIPZ92iFl9c3FClM8dN8PlYU jNzNaVR2QZBHM6QOIBcMVnBA4qNjYk0bIJONOd5/K52RPPP6NrRU88yIxZbHgFaMArZlNH 7VJaXt8EgZNmrof2dTjcQB2rqf/fG5lzt5vBC+hmWm80IblUf8pEZavz4lordcOr+Z2mdY tLh0iZ/hOlZk5orM/ClPkBXeCaA2sHknQ122lN5y/81eDrvCCqnusC3AqK3LaHamSoM1uh Xq029A7EYJ6liXqeOT9xLHar/Yk7FB9+KvHTThj7ayo+aNcUy+loB51uT4hedw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=CV28kRRa; dkim=fail ("headers rsa verify failed") header.d=freakingpenguin.com header.s=x header.b=J5A+c4ug; dmarc=none; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1729632412; 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=FOuLkEk4r/1avYPtflm1SEWvGMTIK0aFdp45LSkeQp31ZHfO/sgMnIu66l0XpUg+SBnbie 1Tw3hdDVsD9EAv44PHljYr7dC+nZgpNvYc+/5YhwsFOtcRdHNJatojqbV//NpU8YlQEfII arYVHn92YNFlkCEmqvcppbuTfVk0qh5LdpuOzUjkXu8kEavJfyG/AM3K+JVW9BzDyWpmDi 4SRHphfgZ5KCECQ7y2h/Gqx5ujH9UIZapxBZ3FhNJPsjHwUQdq7oxLd1iFpfoMC9Ux6rp4 fD4rSB4qwieElxJbLR/bKHhfkWrxyQTB7Qiu2UKHc6M1Clo1eoV+m6+GBVkRaQ== 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 BD2AE18EFD for ; Tue, 22 Oct 2024 23:26:52 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3MOj-0003R2-37; Tue, 22 Oct 2024 17:26:37 -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 1t3MOh-0003QT-L0 for guix-patches@gnu.org; Tue, 22 Oct 2024 17:26:35 -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 1t3MOg-0005aw-74; Tue, 22 Oct 2024 17:26:34 -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=CV28kRRa+BA9MeO7MYI8FsCNmWliV+n78ULRrmz0KtVxAWfx9pA5tU42J4dHkaSMoja2GzzYFrLaV02IMFpqRAghhDVMUgqcca95ARGsklOSwtnBX5MO+3njNHjv5NMf/i1YfN0jKpIj8OmtztekL2DojXmlISk4/I+eQUxc7RKSWVt4d3UBXVYdLi9l7/NRCySc/l5es6zvf1n21fzm/rRPcNzGE0pygJvCEYsjmgoOaqXa+H7wg+Fi5GE5dNFDpEwzrjWWvWn/WqEQ43OGcHdTIa9ZEVRgwvlrOxDc9j2qrblj6hxrLGSybDMCS3/qBWy+7G1IAmyegv6SjXhfNA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t3MP8-0000k5-1y; Tue, 22 Oct 2024 17:27:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73955] [PATCH 1/2] 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: Tue, 22 Oct 2024 21:27:02 +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: othacehe@gnu.org, Richard Sent , guix@twilken.net, maxim.cournoyer@gmail.com, eu@euandre.org, 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.17296323802754 (code B ref 73955); Tue, 22 Oct 2024 21:27:02 +0000 Received: (at 73955) by debbugs.gnu.org; 22 Oct 2024 21:26:20 +0000 Received: from localhost ([127.0.0.1]:57670 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3MOR-0000iM-PP for submit@debbugs.gnu.org; Tue, 22 Oct 2024 17:26:20 -0400 Received: from mail-108-mta133.mxroute.com ([136.175.108.133]:33443) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3MOP-0000iA-NT for 73955@debbugs.gnu.org; Tue, 22 Oct 2024 17:26:18 -0400 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta133.mxroute.com (ZoneMTA) with ESMTPSA id 192b61f15da0003e01.001 for <73955@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 22 Oct 2024 21:25:43 +0000 X-Zone-Loop: c13ec8335bc03e30c1d6c294c8d07998fe900d791ef4 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=J5A+c4ugJ8wJmDJNwTkl88TFh2 ni4Jh65X/C0www1UIWbMIetxOMgVBHR8OwAdjCgVw3bEgv6BnokZw2h+NSSQGNge/Bl/NEyQCMgl7 xae4S0HyCdXRos+Tylw8cmtyY3SC8wamFGNUHx/81ElnC2P3gQujQx7I2xbFQ4Z6mqqzsDtRWrWYN IedtNkhau4Ll4Sq6HWmoCJhvUwrAYHi5pdvsmYgRIUyZOqGiCJlNlVcuiQZzSG+XJtHyeABBWIHhU ueDMI+UHGQQX5X/MciLj39pa5bwCo87AuB+klLRX8dJJI5c0Gl4bAsYOpQHkfUnlfsNKXbQvOpHd3 uaT92bhA==; From: Richard Sent Date: Tue, 22 Oct 2024 17:25:28 -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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.77 X-Spam-Score: -2.77 X-Migadu-Queue-Id: BD2AE18EFD X-Migadu-Scanner: mx10.migadu.com X-TUID: r2+ozA8ayag1 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