From unknown Fri Aug 15 20:27:55 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#60182] [PATCH] services: wireguard: Allow specifying pre-shared keys. Resent-From: Timo Wilken Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 18 Dec 2022 18:54:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 60182 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 60182@debbugs.gnu.org Cc: zimon.toutoune@gmail.com, othacehe@gnu.org, ludo@gnu.org, mail@cbaines.net, rekado@elephly.net, rg@raghavgururajan.name, jgart@dismail.de, paren@disroot.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.167138963312775 (code B ref -1); Sun, 18 Dec 2022 18:54:03 +0000 Received: (at submit) by debbugs.gnu.org; 18 Dec 2022 18:53:53 +0000 Received: from localhost ([127.0.0.1]:35380 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p6ynI-0003Jx-8t for submit@debbugs.gnu.org; Sun, 18 Dec 2022 13:53:52 -0500 Received: from lists.gnu.org ([209.51.188.17]:58214) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p6xL5-000274-TK for submit@debbugs.gnu.org; Sun, 18 Dec 2022 12:20:40 -0500 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 1p6xL2-0004tT-Sy for guix-patches@gnu.org; Sun, 18 Dec 2022 12:20:39 -0500 Received: from mx1.mythic-beasts.com ([2a00:1098:0:86:1000:0:2:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p6xL0-0003VJ-Rt; Sun, 18 Dec 2022 12:20:36 -0500 Received: from [5.147.160.230] (port=51744 helo=timo-pc) by mailhub-cam-d.mythic-beasts.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1p6xKu-00GFyt-56; Sun, 18 Dec 2022 17:20:28 +0000 Date: Sun, 18 Dec 2022 18:19:47 +0100 From: Timo Wilken Message-ID: <20221218171947.vkhy4cwbr2wtwfjp@timo-pc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-BlackCat-Spam-Score: 19 X-Spam-Status: No, score=1.9 Received-SPF: pass client-ip=2a00:1098:0:86:1000:0:2:1; envelope-from=guix@twilken.net; helo=mx1.mythic-beasts.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Mailman-Approved-At: Sun, 18 Dec 2022 13:53:50 -0500 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 (--) Hi, I'm new around here; please forgive any mistakes in my patch submission! I've also CC'd the mentors; I hope that's OK. For my WireGuard setup, I use pre-shared keys in addition to the usual public/private keys. `wg-quick', which is invoked by `wireguard-service-type', supports these, Guix just needs to pass them through to its configuration file. After kind feedback from members of help-guix, I wrote this code such that it takes an existing file for each pre-shared key and loads it from the "main" configuration file, as is done for the private key. I've tested this code using `sudo -E ./pre-inst-env guix system reconfigure system.scm', with a system.scm that sets up a WireGuard service with peers both with and without a pre-shared key. This generates the correct wg-quick configuration file for me. * gnu/services/vpn.scm (): Add preshared-key field. * doc/guix.texi (VPN Services): Document the new preshared-key field. --- doc/guix.texi | 5 +++++ gnu/services/vpn.scm | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index eb37d4d393..06d6df01f8 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -31763,6 +31763,11 @@ VPN Services @item @code{public-key} The peer public-key represented as a base64 string. +@item @code{preshared-key} (default: @code{#f}) +An optional pre-shared key file for this peer. Giving a non-existent +file name here will result in an invalid WireGuard configuration; the +given file will not be autogenerated. + @item @code{allowed-ips} A list of IP addresses from which incoming traffic for this peer is allowed and to which incoming traffic for this peer is directed. diff --git a/gnu/services/vpn.scm b/gnu/services/vpn.scm index 7b3bb8903c..44c0d83494 100644 --- a/gnu/services/vpn.scm +++ b/gnu/services/vpn.scm @@ -61,6 +61,7 @@ (define-module (gnu services vpn) wireguard-peer-endpoint wireguard-peer-allowed-ips wireguard-peer-public-key + wireguard-peer-preshared-key wireguard-peer-keep-alive wireguard-configuration @@ -709,6 +710,8 @@ (define-record-type* (endpoint wireguard-peer-endpoint (default #f)) ;string (public-key wireguard-peer-public-key) ;string + (preshared-key wireguard-peer-preshared-key + (default #f)) ;string (allowed-ips wireguard-peer-allowed-ips) ;list of strings (keep-alive wireguard-peer-keep-alive (default #f))) ;integer @@ -762,10 +765,18 @@ (define (wireguard-configuration-file config) (format #f "PersistentKeepalive = ~a\n" keep-alive) "\n")))) + (define (peers->preshared-keys peer keys) + (let ((public-key (wireguard-peer-public-key peer)) + (preshared-key (wireguard-peer-preshared-key peer))) + (if preshared-key + (cons* public-key preshared-key keys) + keys))) + (match-record config (wireguard interface addresses port private-key peers dns pre-up post-up pre-down post-down table) (let* ((config-file (string-append interface ".conf")) + (peer-keys (fold peers->preshared-keys (list) peers)) (peers (map peer->config peers)) (config (computed-file @@ -780,7 +791,7 @@ (define (wireguard-configuration-file config) Address = ~a ~a ~a -PostUp = ~a set %i private-key ~a +PostUp = ~a set %i private-key ~a~{ peer ~a preshared-key ~a~} ~a ~a ~a @@ -800,6 +811,7 @@ (define (wireguard-configuration-file config) "\n")) #$(file-append wireguard "/bin/wg") #$private-key + '#$peer-keys #$(if (null? post-up) "" (string-join -- 2.38.1 From unknown Fri Aug 15 20:27:55 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Timo Wilken Subject: bug#60182: closed (Re: bug#60182: [PATCH] services: wireguard: Allow specifying pre-shared keys.) Message-ID: References: <87o7rrfp8h.fsf@gnu.org> <20221218171947.vkhy4cwbr2wtwfjp@timo-pc> X-Gnu-PR-Message: they-closed 60182 X-Gnu-PR-Package: guix-patches X-Gnu-PR-Keywords: patch Reply-To: 60182@debbugs.gnu.org Date: Sun, 25 Dec 2022 16:01:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1671984062-16203-1" This is a multi-part message in MIME format... ------------=_1671984062-16203-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #60182: [PATCH] services: wireguard: Allow specifying pre-shared keys. which was filed against the guix-patches package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 60182@debbugs.gnu.org. --=20 60182: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D60182 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1671984062-16203-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 60182-done) by debbugs.gnu.org; 25 Dec 2022 16:00:12 +0000 Received: from localhost ([127.0.0.1]:49947 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p9TQ4-0004BY-8g for submit@debbugs.gnu.org; Sun, 25 Dec 2022 11:00:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33286) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p9TQ2-0004AB-Ps for 60182-done@debbugs.gnu.org; Sun, 25 Dec 2022 11:00:11 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p9TPt-0002Yg-Nd; Sun, 25 Dec 2022 11:00:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=38yA3gXyP3I7uqe5F55wzYwhvo+syK2XljwMi5w+0Iw=; b=SGH1eKkePrXs5/kd451j EFmx8jjWhSicGboovCD/ggkRRfaFQls9+hKWtvVnxWHD5jrtVcYMD6RFmK/OgdT1bTHcDlmbLZUVa xDgyilci8oZFzEx2NPhPyGWZB8LPenLHQk7YkNBk+18v1Yt7/7R7PPbum1o7jFPV8L2YMEruQvuP+ 5dXC8hmMAD6ZHZBYgrnkKxc6R7zFP9F/OPbBEB72KufIJGqPedaqGQKmSVCe2uzkcyoUELZ24lS6b vVTiQce9Ota+KAjjB1W4MczqeBqVIb/Iek+N3vkbdtGjVpIAI1wz2ftVe7pbcSp1dQdl6oErZnwFD FIn+2j56qHudNQ==; Received: from [2a01:cb18:832e:5f00:3563:417e:2a38:86d8] (helo=meije) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p9TPt-0003cu-1h; Sun, 25 Dec 2022 11:00:01 -0500 From: Mathieu Othacehe To: Timo Wilken Subject: Re: bug#60182: [PATCH] services: wireguard: Allow specifying pre-shared keys. References: <20221218171947.vkhy4cwbr2wtwfjp@timo-pc> Date: Sun, 25 Dec 2022 16:59:58 +0100 In-Reply-To: <20221218171947.vkhy4cwbr2wtwfjp@timo-pc> (Timo Wilken's message of "Sun, 18 Dec 2022 18:19:47 +0100") Message-ID: <87o7rrfp8h.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 60182-done Cc: zimon.toutoune@gmail.com, paren@disroot.org, ludo@gnu.org, mail@cbaines.net, rekado@elephly.net, rg@raghavgururajan.name, 60182-done@debbugs.gnu.org, jgart@dismail.de 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 (---) Hello, > I'm new around here; please forgive any mistakes in my patch > submission! I've also CC'd the mentors; I hope that's OK. Welcome aboard! > * gnu/services/vpn.scm (): Add preshared-key field. > * doc/guix.texi (VPN Services): Document the new preshared-key field. It all seems nice, I added your copyright and removed a line from the documentation before pushing as 2967abf1a2ae6787842c04752949f3c214da9338. Thanks, Mathieu ------------=_1671984062-16203-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 18 Dec 2022 18:53:53 +0000 Received: from localhost ([127.0.0.1]:35380 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p6ynI-0003Jx-8t for submit@debbugs.gnu.org; Sun, 18 Dec 2022 13:53:52 -0500 Received: from lists.gnu.org ([209.51.188.17]:58214) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p6xL5-000274-TK for submit@debbugs.gnu.org; Sun, 18 Dec 2022 12:20:40 -0500 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 1p6xL2-0004tT-Sy for guix-patches@gnu.org; Sun, 18 Dec 2022 12:20:39 -0500 Received: from mx1.mythic-beasts.com ([2a00:1098:0:86:1000:0:2:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p6xL0-0003VJ-Rt; Sun, 18 Dec 2022 12:20:36 -0500 Received: from [5.147.160.230] (port=51744 helo=timo-pc) by mailhub-cam-d.mythic-beasts.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1p6xKu-00GFyt-56; Sun, 18 Dec 2022 17:20:28 +0000 Date: Sun, 18 Dec 2022 18:19:47 +0100 From: Timo Wilken To: guix-patches@gnu.org Subject: [PATCH] services: wireguard: Allow specifying pre-shared keys. Message-ID: <20221218171947.vkhy4cwbr2wtwfjp@timo-pc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-BlackCat-Spam-Score: 19 X-Spam-Status: No, score=1.9 Received-SPF: pass client-ip=2a00:1098:0:86:1000:0:2:1; envelope-from=guix@twilken.net; helo=mx1.mythic-beasts.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Sun, 18 Dec 2022 13:53:50 -0500 Cc: zimon.toutoune@gmail.com, othacehe@gnu.org, ludo@gnu.org, mail@cbaines.net, rekado@elephly.net, rg@raghavgururajan.name, jgart@dismail.de, paren@disroot.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 (--) Hi, I'm new around here; please forgive any mistakes in my patch submission! I've also CC'd the mentors; I hope that's OK. For my WireGuard setup, I use pre-shared keys in addition to the usual public/private keys. `wg-quick', which is invoked by `wireguard-service-type', supports these, Guix just needs to pass them through to its configuration file. After kind feedback from members of help-guix, I wrote this code such that it takes an existing file for each pre-shared key and loads it from the "main" configuration file, as is done for the private key. I've tested this code using `sudo -E ./pre-inst-env guix system reconfigure system.scm', with a system.scm that sets up a WireGuard service with peers both with and without a pre-shared key. This generates the correct wg-quick configuration file for me. * gnu/services/vpn.scm (): Add preshared-key field. * doc/guix.texi (VPN Services): Document the new preshared-key field. --- doc/guix.texi | 5 +++++ gnu/services/vpn.scm | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index eb37d4d393..06d6df01f8 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -31763,6 +31763,11 @@ VPN Services @item @code{public-key} The peer public-key represented as a base64 string. +@item @code{preshared-key} (default: @code{#f}) +An optional pre-shared key file for this peer. Giving a non-existent +file name here will result in an invalid WireGuard configuration; the +given file will not be autogenerated. + @item @code{allowed-ips} A list of IP addresses from which incoming traffic for this peer is allowed and to which incoming traffic for this peer is directed. diff --git a/gnu/services/vpn.scm b/gnu/services/vpn.scm index 7b3bb8903c..44c0d83494 100644 --- a/gnu/services/vpn.scm +++ b/gnu/services/vpn.scm @@ -61,6 +61,7 @@ (define-module (gnu services vpn) wireguard-peer-endpoint wireguard-peer-allowed-ips wireguard-peer-public-key + wireguard-peer-preshared-key wireguard-peer-keep-alive wireguard-configuration @@ -709,6 +710,8 @@ (define-record-type* (endpoint wireguard-peer-endpoint (default #f)) ;string (public-key wireguard-peer-public-key) ;string + (preshared-key wireguard-peer-preshared-key + (default #f)) ;string (allowed-ips wireguard-peer-allowed-ips) ;list of strings (keep-alive wireguard-peer-keep-alive (default #f))) ;integer @@ -762,10 +765,18 @@ (define (wireguard-configuration-file config) (format #f "PersistentKeepalive = ~a\n" keep-alive) "\n")))) + (define (peers->preshared-keys peer keys) + (let ((public-key (wireguard-peer-public-key peer)) + (preshared-key (wireguard-peer-preshared-key peer))) + (if preshared-key + (cons* public-key preshared-key keys) + keys))) + (match-record config (wireguard interface addresses port private-key peers dns pre-up post-up pre-down post-down table) (let* ((config-file (string-append interface ".conf")) + (peer-keys (fold peers->preshared-keys (list) peers)) (peers (map peer->config peers)) (config (computed-file @@ -780,7 +791,7 @@ (define (wireguard-configuration-file config) Address = ~a ~a ~a -PostUp = ~a set %i private-key ~a +PostUp = ~a set %i private-key ~a~{ peer ~a preshared-key ~a~} ~a ~a ~a @@ -800,6 +811,7 @@ (define (wireguard-configuration-file config) "\n")) #$(file-append wireguard "/bin/wg") #$private-key + '#$peer-keys #$(if (null? post-up) "" (string-join -- 2.38.1 ------------=_1671984062-16203-1--