Connect to WireGuard hosts and grab connection information on peers. This adapter is intended to be a monitoring instance for your WireGuard hosts. It supports plain installations and docker as well.
- running ssh server on every host to monitor
- The wg executable (wg.exe on Windows) needs to be in the search path
- username and password of a user with the permission to execute the wg command
- Check whether your WireGuard host is running an ssh server. If not - install one. If you can open a commandline using putty (or similar) you're running an ssh server.
- make sure the user you like to use for this is able to execute
wg
(same for Windows and Linux). This user needs admin privileges! - To sum up the test: open a remote command line, log in and execute the
wg show
command. If you receive a proper result you're done and can use these data to run the adapter. - Do this for every host you like to monitor
- Install the adapter and configure it
Since WireGuard internally only uses the public keys to identify peers, but they are pretty inconvenient to read and recognize for humans the translation page was added. Feel free to add public keys and Names to it to get the names integrated into the object tree.
- Main page
- Name: Just a symbolic name for the host, since it's more convenient and better memorable than it's IP address
- Host address: IP address of the host. A fqdn or dns name works also. If you're running WireGuard and ioBroker on the same host you can just use
localhost
as IP. - Port: Port number of your ssh server. Default: 22
- User: The user which executes the script on the host (will be stored encrypted)
- Password: Password for this user (will be stored encrypted)
- sudo: whether the wg command should be executed using sudo or not (requires valid config of sudoers! -> see [security hints])
- Docker: Executes a
docker exec
command to reach a wireguard server inside a docker container. Please check if it fits your needs or whether you may switch to a supported container. - poll interval: pause between each poll in seconds (will also delay the first run after adapter start)
- Container: Name of your docker container. Often "wireguard", but may differ especially when running more than one on a single server
- Translation page
- Public Key: The public key of one of your peers
- group name: A symbolic name for this peer
- Config files page
- Name: Must be the same as on the Main page
- Interface: Name of the interface stored in this config file (wg0, wg1, ...)
- config file: fully qualified path and name of the config file for this interface (/etc/wireguard/wg0.conf, ...)
- No checkbox checked:
wg show all dump
will be executed (for root-like users and use of the SetUID-Bit) - Sudo checkbox is checked:
sudo wg show all dump
will be executed (works with proper sudoers line) - Docker checkbox is checked:
docker exec -it wireguard /usr/bin/wg show all dump
will be executed - Sudo and Docker checkboxes are checked:
sudo docker exec -it wireguard /usr/bin/wg show all dump
will be executed
If you use WireGuard in a docker container, I assume you are familiar enough with both technologies and security concepts to configure your system to execute the shown commands in a way that doesn't ask for any password.
Basically everything said about regular installations also applies for docker and works the same way. Except the needed checkboxes to get the proper command executed and the needed sudoers line. If you use WireGuard inside a docker container you may need sudoers lines similar to this:
<wg-monitoring-user> ALL=NOPASSWD:/usr/bin/docker exec -it wireguard /usr/bin/wg show all dump
<wg-monitoring-user> ALL=NOPASSWD:/usr/bin/docker exec -it wireguard /usr/bin/wg set * peer * remove
<wg-monitoring-user> ALL=NOPASSWD:/usr/bin/docker exec -it wireguard /usr/bin/wg set * peer * allowed-ips *
<wg-monitoring-user> ALL=NOPASSWD:/usr/bin/docker exec -it wireguard /usr/bin/wg syncconf * *
This adapter expects the name wireguard
for your WireGuard container and the wg
command in /usr/bin/
inside the container.
These values currently can't be customized.
- info.connection of the adapter is used to indicate that at least one WireGuard interface is online and reported by
wg show all
. If no Wireguard interface is online - nothing is reported. In that case an error gets logged and the adapters' traffic light turns yellow. - This adapter opens an ssh shell on every configured host, executes the
wg show all dump
command, drops the shell and parses the result. - Since every public key is unique, the adapter uses them to translate the public key into user-friendly, readable and recognisable names.
- WireGuard unfortunately doesn't provide the "connected" state by itself. It only provides the last handshake information. Since handshakes usually occur every 120 seconds - this adapter calculates the connected state that way, that it assumes a peer is connected when the last handshake is received less than 130 seconds before.
I highly recommend the use of sudoers under Linux!
These security hints rely mainly on linux since it's security system is more complex than the windows one. On a Windows server you'll simply need to use an administrative user.
Since the wg
command (which is executed to grab the state of WireGuard) requires administrative permissions, think well of what you are doing here and how you configure the user you place in config.
To protect these credentials as well as possible both - username and password - are encrypted.
Basically there are three ways to execute the command:
- use an administrative user (root or similar). This will work but expose your entire server in case the credentials get lost/stolen.
- use of SetUID-Bit: By setting this bit (as far as I understood) each and every user is allowed to execute the flagged file with administrative privileges without needing any password. This includes hackers. So setting this bit on the wg command exposes the entire wg-command with all it's power. If you like to do so execute
chmod u+s /usr/bin/wg
as an administrator. - use of sudoers: From my perspective, the most secure way is to set up a new simple user with basic privileges and add a simple line to the sudoers file which allows this user to execute the needed command without entering a password - and ONLY THIS command. Please refer to the documentation of your distribution for proper information on editing the sudoers file and using visudo. The screenshot below shows what needs to be added to the file.
wireguard-monitoring-user
is the user of your choice. The rest needs to be exactly like you see.This setting allows the#iobroker.wireguard adapter wireguard-monitoring-user ALL=NOPASSWD:/usr/bin/wg show all dump wireguard-monitoring-user ALL=NOPASSWD:/usr/bin/wg set * peer * remove wireguard-monitoring-user ALL=NOPASSWD:/usr/bin/wg set * peer * allowed-ips * wireguard-monitoring-user ALL=NOPASSWD:/usr/bin/wg syncconf * *
<wireguard-monitoring-user>
onALL
hosts to execute thewg show all dump
command from the directory/usr/bin/
(may need to be changed on your distribution) without needing a password (NOPASSWD
).
- none
- (grizzelbee) Upd: minor fixes for adapter checker
- (grizzelbee) Upd: Dependencies got updated
- (grizzelbee) Fix: #120 Fixed some issues mentioned by adapter-checker
- (grizzelbee) Upd: Dependencies got updated
- (grizzelbee) Upd: Dependencies got updated
- (grizzelbee) Fix: Removed annoying warning when setting null or undefined values (introduced in v1.6.2)
- (grizzelbee) Upd: Requiring at least admin v6.13.16
- (grizzelbee) Upd: Dependencies got updated
- (grizzelbee) Fix: fixed sentry issues WIREGUARD-2B & WIREGUARD-2C
- (grizzelbee) Upd: Adapter requires at least node 18.x
- (mcm1957) Fix: #90 adapter-core 3.x.x is known to fail during installation at node 14 as npm 6 fails to install peerDependencies. So this adapter requires node 16 or newer
- (grizzelbee) Upd: Dependencies got updated
- (grizzelbee) Upd: removed some old news entries in io-package file
- (grizzelbee) Fix: #88 Avoid warning: Cannot read properties of undefined (reading 'at') when user- or devicename is empty
- (grizzelbee) Fix: Adapter doesn't crash anymore when user or device name is missing in config.
- (grizzelbee) Fix: First device of any user was missing in users viewing
- (grizzelbee) New: Added an icon to peers, users, peer and user
- (grizzelbee) Fix: Interface is now correctly set to offline if host is not reachable.
- (grizzelbee) Fix: Added missing icon file
- (grizzelbee) Fix: Some fixes to make iobroker.adapterchecker happy
- (grizzelbee) Fix: Another icon fix
- (grizzelbee) Fix: Adapter does not crash anymore when host isn't reachable
- (grizzelbee) Fix: Added .releaseconfig file
- (grizzelbee) Fix: Added icon to interface-device
- (grizzelbee) Fix: Some fixes to make iobroker.adapterchecker happy
- (grizzelbee) Fix: #65 No names in object tree
- (grizzelbee) Fix: #64 Online state of interface isn't set correctly if more than one server is queried
- (grizzelbee) Upd: Dependencies got updated
- (grizzelbee) Deprecated: The current peer name/description will be dropped in one of the next versions. So please move over to Username/Device config.
- (grizzelbee) New: Splitted Peer names in config in user and device names; So that you are able to group devices by user
- (grizzelbee) New: Some new data fields: connectedPeers, connectedPeersCount, connectedUsers, connectedUsersCount and connection states per user
- (grizzelbee) Fix: #61 Fixed continuous recreation of objects
- (grizzelbee) Upd: Dependencies got updated
- (grizzelbee) Upd: Dropped support for NodeJS 12
- (grizzelbee) Upd: Added support for NodeJS 18
- (grizzelbee) New: Showing number of currently connected peers for each interface
- (grizzelbee) New: #37 Added config options for port and docker container name
- (grizzelbee) Chg: Moved over to new jsonConfig Admin UI
- (grizzelbee) New: #38 Fixed "Adapter doesn't come online" bug caused by pseudo-tty settings
- (grizzelbee) New: #33 Added button to resume a single peer
- (grizzelbee) New: #33 Added buttons to suspend single and restore all peers of an interface
- (grizzelbee) Chg: Changed polling log entry from info to debug
- (grizzelbee) Upd: dependencies got updated
- (grizzelbee) Fixed: #20 Fixed a bug in tty linking which prevented docker option to work.
- (grizzelbee) New: #20 Added support for WireGuard inside a docker container
- (grizzelbee) New: Fixed sentry error WIREGUARD-1
- (grizzelbee) New: Fixed sentry error WIREGUARD-H
- (grizzelbee) New: Fixed sentry error WIREGUARD-C
- (grizzelbee) Upd: dependencies got updated
- (grizzelbee) New: Added donate button
- (grizzelbee) Upd: dependency update
- (grizzelbee) Upd: Changed titleLang from WireGuard to WireGuard monitoring
- (grizzelbee) Upd: dependency update
- (grizzelbee) New: Added support for sudo when using a proper sudoers rule
- (grizzelbee) Upd: Documentation update regarding security
- (grizzelbee) Upd: dependency update
- (grizzelbee) New: Added individual online state indicator for each interface
- (grizzelbee) fix: Improved some data roles
- (grizzelbee) fix: Improved documentation
- (grizzelbee) New: dropped use of wg-json script - not needed anymore
- (grizzelbee) New: making internal use of wg show all dump command and self parsing the result
- (grizzelbee) New: Added windows support by using the wg show all command
- (grizzelbee) Upd: moved dependency admin to globalDependency as requested during adapter review
- (grizzelbee) Fix: removed unnecessary secret from index_m.html file
- (grizzelbee) Fix: Using info.connection of adapter to indicate that at least one interface is online.
- (grizzelbee) Fix: Updated adapter icon
- (grizzelbee) New: Improved optical quality of admin page - no technical improvements
- (grizzelbee) New: Improved documentation
- (grizzelbee) New: Username and password for WireGuard hosts are getting encrypted now
- (grizzelbee) New: admin extended with second page
- (grizzelbee) New: data file is getting parsed
- (grizzelbee) New: data tree is getting populated
- (grizzelbee) New: entire basic functionality is implemented
- (grizzelbee) New: added plugin sentry
- (grizzelbee) New: admin is working as expected
- (grizzelbee) New: first steps in backend
- (grizzelbee) working on admin
- (grizzelbee) initial release
This adapter uses sentry.io to collect details on crashes and report it automated to the author. The ioBroker.sentry plugin is used for it. Please refer to the plugin homepage for detailed information on what the plugin does, which information is collected and how to disable it, if you don't like to support the author with you're information on crashes.
This project is not related to WireGuard in any way. The name WireGuard and the WireGuard logo are only used to refer to this project and are the property of their owners. They are not part of this project.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2024 grizzelbee [email protected]