diff options
| author | Richard Sent <richard@freakingpenguin.com> | 2024-12-04 15:59:33 -0500 |
|---|---|---|
| committer | Mathieu Othacehe <othacehe@gnu.org> | 2024-12-06 20:09:28 +0100 |
| commit | aa12068c91d40c568a44c8d2e36d2ee88ce79d84 (patch) | |
| tree | 443991057a1a3c07128ef804d1b8d6e6897eae03 /gnu/services | |
| parent | d101a6275ac4ee287859349a77c08d43e98a4c88 (diff) | |
services: wireguard: Make the private-key field optional.
Users who retrieve the private-key via a PreUp field need to be able to
disable the default retrieval mechanism.
* gnu/services/vpn.scm (<wireguard-configuration>)[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
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
Diffstat (limited to 'gnu/services')
| -rw-r--r-- | gnu/services/vpn.scm | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/gnu/services/vpn.scm b/gnu/services/vpn.scm index 7fb4775757f..b62e0ac838e 100644 --- a/gnu/services/vpn.scm +++ b/gnu/services/vpn.scm | |||
| @@ -741,7 +741,7 @@ strongSwan."))) | |||
| 741 | (default '("10.0.0.1/32"))) | 741 | (default '("10.0.0.1/32"))) |
| 742 | (port wireguard-configuration-port ;integer | 742 | (port wireguard-configuration-port ;integer |
| 743 | (default 51820)) | 743 | (default 51820)) |
| 744 | (private-key wireguard-configuration-private-key ;string | 744 | (private-key wireguard-configuration-private-key ;maybe-string |
| 745 | (default "/etc/wireguard/private.key")) | 745 | (default "/etc/wireguard/private.key")) |
| 746 | (peers wireguard-configuration-peers ;list of <wiregard-peer> | 746 | (peers wireguard-configuration-peers ;list of <wiregard-peer> |
| 747 | (default '())) | 747 | (default '())) |
| @@ -805,9 +805,12 @@ strongSwan."))) | |||
| 805 | #$@(if (null? pre-up) | 805 | #$@(if (null? pre-up) |
| 806 | '() | 806 | '() |
| 807 | (list (format #f "~{PreUp = ~a~%~}" pre-up))) | 807 | (list (format #f "~{PreUp = ~a~%~}" pre-up))) |
| 808 | (format #f "PostUp = ~a set %i private-key ~a\ | 808 | (if #$private-key |
| 809 | ~{ peer ~a preshared-key ~a~}" #$(file-append wireguard "/bin/wg") | 809 | (format #f "PostUp = ~a set %i private-key ~a\ |
| 810 | #$private-key '#$peer-keys) | 810 | ~{ peer ~a preshared-key ~a~}" |
| 811 | #$(file-append wireguard "/bin/wg") | ||
| 812 | #$private-key '#$peer-keys) | ||
| 813 | "") | ||
| 811 | #$@(if (null? post-up) | 814 | #$@(if (null? post-up) |
| 812 | '() | 815 | '() |
| 813 | (list (format #f "~{PostUp = ~a~%~}" post-up))) | 816 | (list (format #f "~{PostUp = ~a~%~}" post-up))) |
| @@ -838,18 +841,19 @@ strongSwan."))) | |||
| 838 | (use-modules (guix build utils) | 841 | (use-modules (guix build utils) |
| 839 | (ice-9 popen) | 842 | (ice-9 popen) |
| 840 | (ice-9 rdelim)) | 843 | (ice-9 rdelim)) |
| 841 | (mkdir-p (dirname #$private-key)) | 844 | (when #$private-key |
| 842 | (unless (file-exists? #$private-key) | 845 | (mkdir-p (dirname #$private-key)) |
| 843 | (let* ((pipe | 846 | (unless (file-exists? #$private-key) |
| 844 | (open-input-pipe (string-append | 847 | (let* ((pipe |
| 845 | #$(file-append wireguard "/bin/wg") | 848 | (open-input-pipe (string-append |
| 846 | " genkey"))) | 849 | #$(file-append wireguard "/bin/wg") |
| 847 | (key (read-line pipe))) | 850 | " genkey"))) |
| 848 | (call-with-output-file #$private-key | 851 | (key (read-line pipe))) |
| 849 | (lambda (port) | 852 | (call-with-output-file #$private-key |
| 850 | (display key port))) | 853 | (lambda (port) |
| 851 | (chmod #$private-key #o400) | 854 | (display key port))) |
| 852 | (close-pipe pipe)))))) | 855 | (chmod #$private-key #o400) |
| 856 | (close-pipe pipe))))))) | ||
| 853 | 857 | ||
| 854 | ;;; XXX: Copied from (guix scripts pack), changing define to define*. | 858 | ;;; XXX: Copied from (guix scripts pack), changing define to define*. |
| 855 | (define-syntax-rule (define-with-source (variable args ...) body body* ...) | 859 | (define-syntax-rule (define-with-source (variable args ...) body body* ...) |
