Skip to content

Commit f26b5ba

Browse files
committed
Add in support for using a preshared key
Update documentation and initcpio scripts. Move to MAJOR.MINOR.COMMITS for versioning. -=david=- closes #4
1 parent 8b55539 commit f26b5ba

File tree

4 files changed

+286
-95
lines changed

4 files changed

+286
-95
lines changed

Diff for: README.adoc

+192-60
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= mkinitcpio Wireguard hook
1+
= mkinitcpio WireGuard hook
22
:author: David Harrigan
33
:email: <dharrigan [@] gmail [dot] com>
44
:docinfo: true
@@ -22,17 +22,35 @@ endif::[]
2222

2323
== ChangeLog
2424

25-
IMPORTANT: Until this package has stabilised and until it has reached a 1.0.0
26-
release, *please be very careful* to examine the version changes listed below
27-
as the package requirements and instructions can change to reflect a better
25+
[IMPORTANT]
26+
====
27+
This project follows the version scheme **MAJOR.MINOR.COMMITS** where
28+
**MAJOR** and **MINOR** provide some relative indication of the size of the
29+
change, but do **NOT** follow semantic versioning. In general, all changes
30+
endeavour to be non-breaking (by moving to new names rather than by breaking
31+
existing names). **COMMITS** is an ever-increasing counter of commits since
32+
the beginning of this repository.
33+
====
34+
35+
[IMPORTANT]
36+
====
37+
Until this package has stabilised and until it has reached a 1.0.0 release,
38+
*please be very careful* to examine the version changes listed below as the
39+
package requirements and instructions can change to reflect a better
2840
understanding of the problem domain. *DO NOT ASSUME THAT ANYTHING UNTIL AT
2941
LEAST A 1.0.0 RELEASE*
30-
31-
WARNING: Read the warning above.
42+
====
3243

3344
|===
3445
|Version | Note
3546

47+
| *0.5.11*
48+
a|
49+
* Added in support for using WireGuard a preshared key (closes #4).
50+
* Improved the documentation.
51+
* Improved the initcpio support files.
52+
* Change versioning to be MAJOR.MINOR.COMMITS.
53+
3654
| *0.4.10*
3755
a|
3856
* Improved documentation. No functional changes.
@@ -63,49 +81,58 @@ a|
6381

6482
== Rationale
6583

66-
Firstly, encryption. Encrypt all the things.
84+
**Firstly**, encryption. **Encrypt all the things!**
6785

68-
Secondly, I think https://www.wireguard.io[Wireguard] is pretty awesome. It's
86+
**Secondly**, I think https://www.wireguard.io[Wireguard] is pretty awesome. It's
6987
really easy to setup and use and works flawlessly (at least for me 😄).
7088

71-
Thirdly, the ability to remotely unlock encrypted partitions is extremely
89+
**Thirdly**, the ability to remotely unlock encrypted partitions is extremely
7290
useful. However, a limitation is that in order to remotely unlock the
7391
partition via SSH, you normally need to be on the same network (or at least
7492
routeable) to the computer that needs unlocking.
7593

7694
As far as I could tell, there was nothing available in
77-
https://aur.archlinux.org[AUR] that provided a Wireguard hook for
78-
`mkinitcpio`. Creating a hook should allow a basic Wireguard interface to be
95+
https://aur.archlinux.org[AUR] that provided a WireGuard hook for
96+
`mkinitcpio`. Creating a hook should allow a basic WireGuard interface to be
7997
established so that - via a secure network - you could gain access to the
80-
remote machine. This is my small attempt to achieve that aim.
98+
remote computer. This is my small attempt to achieve that aim.
8199

82-
IMPORTANT: I developed this little hook for myself and I'm releasing it into
100+
[IMPORTANT]
101+
====
102+
I developed this little hook for myself and I'm releasing it into
83103
the general community in the (probably misguided) hope that others may find it
84104
useful too. As usual, no warranty implied or otherwise is given towards the
85105
fitness of this software in meeting *YOUR* needs. Please refer to the included
86106
https://unlicense.org[Unlicense] license file for more information. That said,
87107
I find this little hook useful - perhaps you may too - so please enjoy! Oh,
88108
and please be be awesome to each other!
109+
====
89110

90-
WARNING: Ensure you have read the Arch wiki section on
111+
[WARNING]
112+
====
113+
Ensure you have read the Arch wiki section on
91114
https://wiki.archlinux.org/index.php/Dm-crypt/Specialties#Remote_unlocking_of_the_root_(or_other)_partition[remote
92115
unlocking]. It's a *very* good idea to get remote unlocking working *first* on
93116
your local network - proving that it works for you (this includes using either
94117
*tinyssh* or *dropbear* to authenticate and unlock successfully)
95-
- *before* attempting to setup this mkinitcpio Wireguard hook for remote
118+
- *before* attempting to setup this mkinitcpio WireGuard hook for remote
96119
unlocking.
120+
====
97121

98-
IMPORTANT: It is also *strongly* recommend that a *separate* Wireguard network
122+
[IMPORTANT]
123+
====
124+
It is also *strongly* recommend that a *separate* WireGuard network
99125
is setup and configured *just* for unlocking. You see, a private key (and a
100126
public key) and a configuration file are written to the ramdisk (which
101127
typically lives in an unencrypted boot partition). It's super trivially easy
102128
for anyone to copy this ramdisk, extract out the contents and use the private
103-
key and Wireguard configuration found therein to connect to your Wireguard
129+
key and WireGuard configuration found therein to connect to your WireGuard
104130
network. As a minimum, you could disable (on the remote peer *nominally called
105-
the `server`*) the ability for the target machine (the `client` - the one on
131+
the `server`*) the ability for the target computer (the `client` - the one on
106132
which you are remotely unlocking partitions) to connect and authenticate -
107133
only enabling connection *when* and *if* required. Please be careful and think
108134
this through! Safety first!
135+
====
109136

110137
== OS Installation
111138

@@ -117,10 +144,12 @@ https://github.com/Jguer/yay[yay] package manager to install the utility.
117144
Please refer to your favourite package manager's documentation in learn how to
118145
install it for you 😄
119146

120-
NOTE: Obviously, you must also install Wireguard! Choose either manual
121-
installation (using git and compiling it yourself), or using
122-
`wireguard-tools`. Life is short, so personally I just roll with
123-
`wireguard-tools`.
147+
[NOTE]
148+
====
149+
Obviously, you must also install WireGuard! Choose either manual installation
150+
(using git and compiling it yourself), or using `wireguard-tools`. Life is
151+
short, so personally I just roll with `wireguard-tools`.
152+
====
124153

125154
== Additional Requirements
126155

@@ -129,14 +158,14 @@ This software requires a few necessary additions:
129158
* `mkinitcpio-utils`
130159
* `mkinitcpio-netconf`
131160

132-
These packages provide the means to configure the network interface
133-
via passed in kernel parameters and the ability to ssh to the machine
134-
remotely. Basic instructions follow:
161+
These packages provide the means to configure the network interface via passed
162+
in kernel parameters and the ability to ssh to a remote computer. Basic
163+
instructions follow.
135164

136165
You will need to choose been `mkinitcpio-tinyssh` or
137166
`mkinitcpio-dropbear` and install one or the other. This documentation
138167
describes only `mkinitcpio-tinyssh` as it supports ed25519 and I quite
139-
like it.
168+
like it (both ed25519 and tinyssh).
140169

141170
* `mkinitcpio-tinyssh`
142171
* `mkinitcpio-dropbear`
@@ -153,75 +182,164 @@ below on `Hook Installation` for the module ordering for
153182
This package sets up the interfaces just immediately after booting the
154183
kernel based upon the IP parameters passed into the kernel via GRUB.
155184
This is very important as this sets thing up in order for tinyssh (or
156-
dropbear) and wireguard to function. For example, in your
185+
dropbear) and WireGuard to function. For example, in your
157186
`/etc/default/grub` file, the `GRUB_CMDLINE_LINUX` line may look like
158187
this:
159188

160189
```
161-
GRUB_CMDLINE_LINUX="cryptdevice=UUID=35fbb65a-eeb9-4a6a-7b13-a05d9b0fcf6f:cryptroot root=/dev/mapper/cryptroot ip=192.168.1.10:192.168.1.1:255.255.255.0::eth0::"
190+
GRUB_CMDLINE_LINUX="cryptdevice=UUID=35fbb65a-eeb9-4a6a-7b13-a05d9b0fcf6f:cryptroot root=/dev/mapper/cryptroot ip=192.168.1.10::192.168.1.1:255.255.255.0::eth0::"
162191
```
163192

164-
This says to use the cryptdevice defined by the UUID, which will map
165-
itself to `cryptoroot` after successful unlocking and also set the IP
166-
parameters on the kernel, i.e., host = 192.168.1.10, gateway =
167-
192.168.1.1, netmask = 255.255.255.0, and kernel network interface
168-
eth0.
193+
This says to use the cryptdevice defined by the UUID, which will map itself to
194+
`cryptoroot` after successful unlocking and also set the IP parameters on the
195+
kernel, i.e., `host=192.168.1.10`, `gateway=192.168.1.1`, `netmask =
196+
255.255.255.0`, and kernel network interface `eth0`.
169197

170198
Further information on the ip kernel parameter can be found
171199
https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/nfs/nfsroot.rst[here].
172200

173-
IMPORTANT: Use the **kernel** device name, i.e., **eth0**, and not the
174-
well known predictable name, such as **enp0s31f6**.
201+
[WARNING]
202+
====
203+
Use the **kernel** device name, i.e., **eth0**, and not the well known
204+
predictable name, such as **enp0s31f6**.
205+
====
175206

176207
=== mkinitcpio-tinyssh (or mkinitcpio-dropbear)
177208

178209
This package installs `tinyssh` to allow SSH connections. It's small
179210
enough to fit into the daemon into the early userspace and allows for
180211
the use of ed25519 keys (which are great!)
181212

182-
The steps here are:
213+
[TIP]
214+
====
215+
Please refer to the Arch wiki on
216+
https://wiki.archlinux.org/title/Dm-crypt/Specialties#Remote_unlocking_of_root_(or_other)_partition[remote
217+
unlocking] for additional background reading.
218+
====
183219

184-
. Create an ed25519 keypair using openssh, i.e., `ssh-keygen -t ed25519`
185-
. Copy the public key to `/etc/tinyssh/root_key`
220+
[NOTE]
221+
====
222+
The following steps assume you are on the computer which is encrypted and you'll want to remote boot
223+
and that you are currently the `root` user.
224+
====
186225

187-
== Configuration
226+
The steps are:
227+
228+
* Create an `ed25519` keypair using openssh, i.e., `ssh-keygen -t ed25519`
229+
230+
[NOTE]
231+
====
232+
Any name will do, but we'll assume `server` as the keypair name (thus `server`
233+
and `server.pub` `ed25519` keyfiles are created)
234+
====
235+
236+
* Copy the `server.pub` keyfile to `/etc/tinyssh/root_key` (file)
237+
* Remove the existing `/etc/tinyssh/sshkeydir` directory, i.e., `rm -rf /etc/tinyssh/sshkeydir`
238+
* Generate a tinyssh compatible private key using `tinyssh-convert /etc/tinyssh/sshkeydir < server`
239+
240+
[NOTE]
241+
====
242+
The `server` file is the *private* `ed25519` keyfile that was generated a moment ago
243+
====
244+
245+
* Don't forget to copy the `ed25519` private key to the local computer from which you want to ssh *from*!
246+
** i.e., copy the `server` private keyfile to your local computer, perhaps put it in your `$HOME/.ssh` directory
247+
* It may be useful to add an entry to your personal `$HOME/.ssh/config` along the lines of:
248+
249+
----
250+
host server
251+
hostname ip-address-of-the-remote-encrypted-computer-wireguard-interface
252+
user root
253+
IdentityFile ~/.ssh/ed25519_private_key_of_the_remote_encrypted_computer
254+
----
255+
256+
For example, based upon the example `wireguard_config` file in this repository:
257+
258+
----
259+
host server
260+
hostname 10.0.200.21
261+
user root
262+
IdentityFile ~/.ssh/server
263+
----
188264

189-
IMPORTANT: The setup and running of `mkinitcpio-wireguard` is *very* basic and
190-
makes *lots* of assumptions. *This is intentional!* This hook is simple
191-
because it is designed to get a minimal Wireguard up and running so that you
192-
can remotely unlock encrypted partitions. The script does not attempt to do
193-
anything else. This script will never be super fancy or clever.
265+
== Configuration
194266

195-
WARNING: Please read and familiarise yourself with how Wireguard works. In
196-
particular, please refer to the *numerous* examples online of how to setup and
197-
configure Wireguard. It is *strongly* suggested you get Wireguard up and
198-
running first. A few examples of where to find documentation are listed below:
267+
[IMPORTANT]
268+
====
269+
The setup and running of `mkinitcpio-wireguard` is *very* basic and makes
270+
*lots* of assumptions. *This is intentional!* This hook is simple because it
271+
is designed to get a minimal WireGuard up and running so that you can remotely
272+
unlock encrypted partitions. The script does not attempt to do anything else.
273+
This script will never be super fancy or clever.
274+
====
275+
276+
[WARNING]
277+
====
278+
Please read and familiarise yourself with how WireGuard works. In particular,
279+
please refer to the *numerous* examples online of how to setup and configure
280+
WireGuard. It is *strongly* suggested you get WireGuard up and running first.
281+
A few examples of where to find documentation are listed below.
282+
====
199283

200284
* https://wiki.archlinux.org/index.php/WireGuard
201285
* https://www.wireguard.com/quickstart/
202286
* https://git.zx2c4.com/WireGuard/about/src/tools/man/wg.8
203287

204288
After installing `mkinitcpio-wireguard`, an example configuration file will be
205289
written to `/etc/wireguard/initcpio/unlock`. You *MUST* edit this file to suit
206-
your particular Wireguard requirements. The file is really simple and
290+
your particular WireGuard requirements. The file is really simple and
207291
therefore should be pretty self-explanatory.
208292

209-
NOTE: If you have an existing `wg0.conf` in your `/etc/wireguard` directory,
293+
[NOTE]
294+
====
295+
If you have an existing `wg0.conf` in your `/etc/wireguard` directory,
210296
you can use the contents of that file as a reference. Please be aware of the
211297
warning above concerning the recommended use of a separate network for remote
212298
unlocking.
299+
====
300+
301+
=== Configuration Keys
302+
303+
The current configuration keys found in the configuration file are:
304+
305+
|===
306+
|Key | Description
307+
308+
|**INTERFACE**| Specifies the name of the WireGuard interface (usually wg0).
309+
|**INTERFACE_ADDR**|Specifies the IP address that the WireGuard interface will use. Please ensure you specify the IP address in CIDR format.
310+
|**PEER_PUBLIC_KEY**|This is the public key of the peer (usually the WireGuard server).
311+
|**PEER_ENDPOINT**|This is normally the external public-facing IP address and port of the peer (usually the WireGuard server), but it may also be an internal IP address and port of a peer if you wish!
312+
|**PRIVATE_KEYFILE**|This is your private key previously setup to establish connection to the peer (usually the WireGuard server).
313+
|**PRESHARED_KEYFILE**|**OPTIONAL**
314+
This is the preshared key to be used. Don't forget to populate the preshared
315+
keyfile using something like:
316+
317+
`umask 077 && wg genpsk > /etc/wireguard/initcpio/presharedkey`
318+
319+
and that the preshared key matches on the other peer too!
320+
|**PERSISTENT_KEEPALIVES**|If you're behind a NAT, a ping of 25 seconds is useful to keep the connection alive between the peers.
321+
|**ALLOWED_IPS**|The IP range that will be allowed to flow across the wg0 interface.
322+
323+
|===
213324

214325
== Hook Installation
215326

216327
After you have edited the `/etc/wireguard/initcpio/unlock` file to suit your
217-
needs, ensure that you've added the `wireguard` hook to the *HOOKS* array of
218-
`/etc/mkinitcpio.conf`. Shown below is an example that also includes the use
219-
of `netconf`, `tinyssh` and `encryptssh`.
328+
needs, the next step is ensure that you've added the `wireguard` hook to the
329+
*HOOKS* array of `/etc/mkinitcpio.conf`. Shown below is an example that also
330+
includes the use of `netconf`, `tinyssh` and `encryptssh`
220331

221332
----
222333
HOOKS=(base udev autodetect keyboard keymap modconf block netconf wireguard tinyssh encryptssh filesystems fsck)
223334
----
224335

336+
[NOTE]
337+
====
338+
Your particular original `/etc/mkinitcpio.conf` file may be slightly different
339+
in the hooks already present (and the ordering in which they are presented).
340+
====
341+
342+
225343
== Final Steps
226344

227345
Lastly, run (still as root):
@@ -230,18 +348,32 @@ Lastly, run (still as root):
230348
mkinitcpio -P
231349
----
232350

233-
This will regenerate the ramdisk with your Wireguard configuration.
351+
This will regenerate the initramfs ramdisk with your WireGuard configuration.
352+
You can safely ignore all the warnings about possibly missing firmware
353+
modules.
234354

235-
You should now be able to reboot your machine and after the interface has come
236-
up be able to ping it via your Wireguard network! You should now also be able
237-
to SSH to the machine (you did remember to set that all up before doing this,
238-
right?) and unlock any encrypted partitions and thus enable the continuation
239-
of your boot process! FTW!
355+
You should now be able to reboot your remote computer and after the interface
356+
has come up be able to ping it via your WireGuard network!
240357

241-
NOTE: It could take a minute or two for your Wireguard interface to
358+
NOTE: It could take a minute or two for your WireGuard interface to
242359
authenticate and be recognised by the remote peer. Please be patient and hang
243360
on in there!
244361

362+
Once you can ping the remote computer, you should now also be able to SSH to
363+
it (you did remember to set that all up before doing this, right?).
364+
365+
After establishing a SSH connection to the remote computer, a prompt should
366+
appear asking for the LUKS passphrase to unlock the encrypted partition. Once
367+
the LUKS passphrase has been keyed in, the partition should unlock and the
368+
continuation of the boot process will continue! FTW!
369+
370+
== Updating the configuration
371+
372+
If you make changes to the `/etc/wireguard/initcpio/unlock` file, or if you
373+
change your private key (and/or optionally the preshared key) don't forget to
374+
regenerate the initramfs ramdisk using `mkinitcpio -P`, otherwise your new
375+
settings won't be picked up!
376+
245377
== Unlicensed
246378

247379
Find the full unlicense in the UNLICENSE file, but here's a snippet.

0 commit comments

Comments
 (0)