MindFlavor / prometheus_wireguard_exporter

A Prometheus exporter for WireGuard, written in Rust.
https://mindflavor.github.io/prometheus_wireguard_exporter
MIT License
493 stars 51 forks source link

Add systemd-networkd peer syntax #92

Closed mbonino closed 2 years ago

mbonino commented 2 years ago

Systemd-networkd managed wireguard interfaces use [WireGuardPeer] rather than [Peer].

Friendly names need a peer section in config file. This change allow using both wireguard config files and systemd-networkd config files.

MindFlavor commented 2 years ago

Great! thank you!

aa-matthias commented 2 years ago

Hi @mbonino - short question - where are you setting the friendly names in this use case? are they part of the netplan?

mbonino commented 2 years ago

Hi @aa-matthias,

I don't use netplan, I use systemd-networkd to create Wireguard interfaces.

On my Ubuntu 20.04 server, I have create file /etc/systemd/network/20-wg0.netdev

File content:

[NetDev]
Name = wg0
Kind = wireguard
Description = WireGuard tunnel

[WireGuard]
ListenPort = 51860
PrivateKey = <privatekey>

[WireGuardPeer]
# friendly_name = admin
PublicKey = <blabla>
AllowedIPs = 192.168.1.2/32
AllowedIPs = 192.168.1.3/32
AllowedIPs = 192.168.1.4/32
AllowedIPs = 192.168.1.5/32
aa-matthias commented 2 years ago

Thanks for the heads up!

I thought of using netplan and systemd-networkd as a renderer to have only one place for all network config but I assume it's not possible to create the # friendly_name = .... property in this case

https://netplan.io/reference/#properties-for-device-type-tunnels%3A

mbonino commented 2 years ago

I guess support for friendly_name has to be added upstream. Currently netplan's parser for Wireguard doesn't support friendly names as far as I can tell.

https://github.com/canonical/netplan/blob/a73859781619331c466f38386009c7b9146366b2/src/networkd.c#L167

bastelfreak commented 2 years ago

Hi people, why not use the description attribute that systemd-networkd already supports?

mbonino commented 2 years ago

Hi @bastelfreak,

systemd-networkd support the description attribute at [NetDev] level. This means one attribute per interface. A wireguard interface can have multiple peers, so we can't use it. Each peer needs its own attribute.