Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wg-quick linux: Add strip-and-eval cmd to extract keys from PostUp #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ypid
Copy link

@ypid ypid commented Oct 4, 2020

I will also submit this to the mailing list. I just open a PR here because I find it easier to get an overview what has been merged and what not.

Note that the patchset is incomplete (currently only for Linux). I don’t have all the other OSes laying around.

The manpage mentions the trick to use PostUp to read the PrivateKey (or PresharedKey) from a command (or file). However, when you actually use that you notice that this is currently not fully supported. The issue is that

wg syncconf wgnet0 <(wg-quick strip wgnet0)

from the manpage now breaks the VPN because it removes the private key from the WireGuard interface. The reason is that strip removes PostUp of course.

This patch tries to add full support to read WireGuard keys from files or command outputs by evaluating PostUp using a best effort approach (using regex). It will not work for everything but when you follow the manpage closely, it will work.

I also propose to update the systemd template to make seamless use of this. This is not a must because the sysadmin can easily change the ExecReload using systemd drop-in files.

Example use of this patch: https://github.com/ypid/ansible-wireguard/tree/prepare-for-debops

@ypid ypid force-pushed the feature/wg-quick/strip-and-eval branch from 6714da3 to 9762a0b Compare October 4, 2020 21:12
The manpage mentions the trick to use PostUp to read the PrivateKey (or
PresharedKey) from a command (or file). However, when you actually use
that you notice that this is currently not fully supported. The issue is
that

```Shell
wg syncconf wgnet0 <(wg-quick strip wgnet0)
```

from the manpage now breaks the VPN because it *removes* the private key
from the WireGuard interface. The reason is that `strip` removes PostUp
of course.

This patch tries to add full support to read WireGuard keys from files
or command outputs by evaluating PostUp using a best effort approach
(using regex). It will not work for everything but when you follow the
manpage closely, it will work.

I also propose to update the systemd template to make seamless use of
this. This is not a must because the sysadmin can easily change the
ExecReload using systemd drop-in files.

Note that the patchset is incomplete (currently only for Linux).
I don’t have all the other OSes laying around. When the patch looks ok,
I can apply it to the other versions also.

Example use of this patch:
https://github.com/ypid/ansible-wireguard/tree/prepare-for-debops

Signed-off-by: Robin Schneider <[email protected]>
@ypid ypid force-pushed the feature/wg-quick/strip-and-eval branch from 9762a0b to 4963c83 Compare October 4, 2020 21:19
@zx2c4-bot zx2c4-bot force-pushed the master branch 9 times, most recently from 542b7c0 to 4ad6d0d Compare June 25, 2021 20:54
@zx2c4-bot zx2c4-bot force-pushed the master branch 3 times, most recently from c39c2ea to ab264f7 Compare July 13, 2021 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant