Skip to content

Commit dec2adc

Browse files
committed
configuration/wireguard: drop wg-quick warnings
wg-quick is working without issues now. Also add example on how to use NetworkManager.
1 parent ab098f7 commit dec2adc

File tree

1 file changed

+65
-9
lines changed

1 file changed

+65
-9
lines changed

modules/ROOT/pages/sysconfig-configure-wireguard.adoc

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
= Configuring FCOS to use WireGuard
22

3-
WARNING: Some examples in this page may not work properly. An issue with WireGuard SELinux isolation breaks Pre/Post actions in the WireGuard configuration for recent releases of Fedora Coreos. You can check the progress of this issue on the https://github.com/coreos/fedora-coreos-tracker/issues/1487[issue tracker].
43

54
== Introduction
65

@@ -12,10 +11,15 @@ https://www.wireguard.com/[WireGuard] is a novel VPN that runs inside the Linux
1211

1312
FCOS has full support for WireGuard out of the box. This guide is going to demonstrate how to set up a single connection between a FCOS server and one client computer. It goes over the basic client configuration, but it does not cover installing WireGuard on your clients.
1413

14+
There are several ways to set up wireguard on FCOS, here we show two approaches:
15+
* Using [wg-quick](https://www.man7.org/linux/man-pages/man8/wg-quick.8.html).
16+
* importing the Wireguard configuration in NetworkManager.
17+
1518
== Generate Keys
1619

17-
You will need to generate some keys to configure WireGuard. For this guide, the keys should be pre-generated on your workstation. First, let's create the FCOS WireGuard keys:
20+
You will need to generate some keys to configure WireGuard. You can generate the keys on your workstation or a running FCOS system.
1821

22+
First, let's create the FCOS WireGuard keys:
1923
.Generate FCOS WireGuard keys
2024
[source,bash]
2125
----
@@ -36,7 +40,7 @@ $ wg genkey | tee privatekey | wg pubkey > publickey
3640

3741
These keys will be referenced as `client_one_public_key` and `client_one_private_key` from here on out in this guide.
3842

39-
Now create a PresharedKey:
43+
You can optionnaly generate a pre-shared key to increase security:
4044

4145
.Generate a Preshared key per peer pair
4246
[source,bash]
@@ -71,19 +75,60 @@ storage:
7175
[Peer]
7276
PublicKey = <client_one_public_key>
7377
PresharedKey = <fcos_client_one_psk>
74-
AllowedIPs = 192.168.71.0/24,fdc9:3c6b:21c7:e6bd::/64
78+
AllowedIPs = 192.168.71.2/32,fdc9:3c6b:21c7:e6bd::2/128
79+
----
80+
81+
=== Import the wireguard configuration to NetworkManager
82+
83+
You can import the configuration with a simple oneshot unit :
84+
[source,yaml,subs="attributes"]
85+
----
86+
systemd:
87+
units:
88+
- name: import-wireguard-config.service
89+
enabled: true
90+
contents: |
91+
[Unit]
92+
ConditionPathExists=!/etc/NetworkManager/system-connections/wg0.nmconnection
93+
Description=Import wireguard configuration to NetworkManager
94+
[Service]
95+
Type=oneshot
96+
RemainAfterExit=yes
97+
ExecStart=nmcli connection import type wireguard file /etc/wireguard/wg0.conf
98+
[Install]
99+
WantedBy=multi-user.target
100+
----
101+
102+
NOTE: NetworkManager will ignore `PostUp` and `PostDown` directives in the wiregaurd config. If you have firewall configuration to apply, make sure to apply it with a separate unit, or manually.
103+
104+
NOTE: If you need to make further changes to update Wireguard's configuration, delete the connection and re-import it from the updated configuration file.
105+
.Re-import updated Wireguard configuration on FCOS
106+
[source,bash]
107+
----
108+
[core@wireguard-demo ~]$ sudo nmcli con delete wg0 && sudo nmcli con import type wireguard file /etc/wireguard/wg0.conf
109+
Connection 'wg0' (1e4f869e-f95c-4221-b2b9-99726ffde92b) successfully deleted.
110+
Connection 'wg0' (18cd8e61-1cc2-43a2-9f2e-467b75cd99da) successfully added.
111+
----
112+
113+
114+
=== Using wg-quick
115+
116+
[source,yaml,subs="attributes"]
117+
----
75118
systemd:
76119
units:
77120
78121
enabled: true
79122
----
80123

124+
NOTE: If you need to make further changes to Wireguard's configuration, reload the service with `systemctl reload [email protected]`.
125+
81126
Boot FCOS and log in. When you run `sudo wg show` you should see this:
82127

83128
.Check WireGuard configuration on FCOS
84129
[source,bash]
85130
----
86-
[core@wireguard-demo ~]$ sudo wg show
131+
[core@wireguard-demo ~]# sudo wg show
87132
interface: wg0
88133
public key: <fcos_public_key>
89134
private key: (hidden)
@@ -94,7 +139,7 @@ peer: <client_one_public_key>
94139
endpoint: <Client IP Address>:51821
95140
allowed ips: 192.168.71.0/24, fdc9:3c6b:21c7:e6bd::/64
96141
97-
[root@wireguard-demo ~]# ip a s wg0
142+
[core@wireguard-demo ~]# sudo ip a s wg0
98143
12: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000
99144
link/none
100145
inet 192.168.71.1/24 scope global wg0
@@ -126,7 +171,8 @@ AllowedIPs = 192.168.71.0/24,fdc9:3c6b:21c7:e6bd::/64
126171

127172
NOTE: <FCOS IP address> is the IP or FQDN of the FCOS server.
128173

129-
Write the above config to `/etc/wireguard/wg0.conf` and `chmod 0600 /etc/wireguard/wg0.conf` on your client. Run `sudo systemctl start [email protected]` and then check your configuration:
174+
Write the above config to `/etc/wireguard/wg0.conf` and `chmod 0600 /etc/wireguard/wg0.conf` on your client.
175+
Run `nmcli con import type wireguard file /etc/wireguard/wg0.conf` and then check your configuration:
130176

131177
.Check WireGuard configuration on a client
132178
[source,bash]
@@ -141,6 +187,7 @@ peer: <fcos_public_key>
141187
preshared key: (hidden)
142188
endpoint: <FCOS IP address>:51820
143189
allowed ips: 192.168.71.0/24, fdc9:3c6b:21c7:e6bd::/64
190+
144191
[root@wireguard-client ~]# ip a s wg0
145192
21: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000
146193
link/none
@@ -189,7 +236,6 @@ interface: wg0
189236
public key: <client_one_public_key>
190237
private key: (hidden)
191238
listening port: 51821
192-
193239
peer: <fcos_public_key>
194240
preshared key: (hidden)
195241
endpoint: <Client IP address>:51820
@@ -239,8 +285,18 @@ storage:
239285
AllowedIPs = 192.168.71.0/24,fdc9:3c6b:21c7:e6bd::/64
240286
systemd:
241287
units:
242-
- name: wg-quick@wg0.service
288+
- name: import-wireguard-config.service
243289
enabled: true
290+
contents: |
291+
[Unit]
292+
ConditionPathExists=!/etc/NetworkManager/system-connections/wg0.nmconnection
293+
Description=Import wireguard configuration to NetworkManager
294+
[Service]
295+
Type=oneshot
296+
RemainAfterExit=yes
297+
ExecStart=nmcli connection import type wireguard file /etc/wireguard/wg0.conf
298+
[Install]
299+
WantedBy=multi-user.target
244300
----
245301

246302
NOTE: FCOS uses https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/[predictable interface names] by https://lists.fedoraproject.org/archives/list/[email protected]/thread/6IPTZL57Z5NLBMPYMXNVSYAGLRFZBLIP/[default]. Please take care to use the correct interface name for your hardware in the above PostUp and PostDown commands!

0 commit comments

Comments
 (0)