ngoduykhanh / wireguard-ui

Wireguard web interface
MIT License
4.26k stars 525 forks source link

Wireguard-ui generating invalid config files on restart #531

Open ronnessim opened 10 months ago

ronnessim commented 10 months ago

We are usng the latest docker version of wireguard from dockerhub (super basic config, most things left as default except for passwords). The first time the container starts file, creates an empty DB and we can add some connections via the GUI and apply them. Then when we do docker compose down, and then up, we see that all tunnels are down in the log. The only way to fix it is to remove config/wg0.conf and then restart, edit a connection and then apply the config to regenerate a valid config. Here is the log output after a restart:

**** Server mode is selected ****
**** SERVERURL var is either not set or is set to "auto", setting external IP to auto detected value of 169.62.191.123 ****
**** External server port is set to 51820. Make sure that port is properly forwarded to port 51820 inside this container ****
**** Internal subnet is set to 10.13.13.0 ****
**** AllowedIPs for peers 0.0.0.0/0, ::/0 ****
**** PEERDNS var is either not set or is set to "auto", setting peer DNS to 10.13.13.1 to use wireguard docker host's DNS. ****
**** Server mode is selected ****
**** No changes to parameters. Existing configs are used. ****
[custom-init] No custom files found, skipping...
.:53
CoreDNS-1.10.1
linux/amd64, go1.20.11,
**** Found WG conf /config/wg_confs/wg0.conf, adding to list ****
**** Activating tunnel /config/wg_confs/wg0.conf ****
Warning: `/config/wg_confs/wg0.conf' is world accessible
wg-quick: `wg0' already exists
**** Tunnel /config/wg_confs/wg0.conf failed, will stop all others! ****
**** All tunnels are now down. Please fix the tunnel config /config/wg_confs/wg0.conf and restart the container ****
[ls.io-init] done.

The problem is likely that the config is also being added to config/wg_confs so it exists twice.

ClemontX commented 10 months ago

Seems to be related to a commit from october 2023

https://github.com/linuxserver/docker-wireguard/commit/36ca38850c150fa82a068f2543eb26e37919e810

by using this image: linuxserver/wireguard:v1.0.20210914-ls4 it should be working, but in my case i cant connect at the time but this can be related to another problem in my case. I will add info asap

ClemontX commented 10 months ago

Can confirm that it works with the specified image version of linuxserver.io's wireguard image. If i have time in the future i maybe create a PR for this here but at the moment i don't know anything about go.

ronnessim commented 10 months ago

Just tested with the image provided above and it survives a restart now. Thanks for the update. I will keep an eye out for this in future releases.

mattwebbio commented 9 months ago

Another solution that worked for me: just mount the config volume to the directory that the linuxserver container now expects it to be in

version: "3"

services:
  wireguard:
    image: linuxserver/wireguard:latest
    cap_add:
      - NET_ADMIN
    volumes:
-     - config:/config
+     - config:/config/wg_confs
    ports:
      - "51820:51820/udp"
...

Disclosure: I'm not familiar enough with Wireguard or wireguard-ui to know if there are any bad implications to moving the whole mount point for the config directory

Ignore this, don't do this. It doesn't work - I was just lucky.

Malnes commented 9 months ago

Another solution that worked for me: just mount the config volume to the directory that the linuxserver container now expects it to be in

version: "3"

services:
  wireguard:
    image: linuxserver/wireguard:latest
    cap_add:
      - NET_ADMIN
    volumes:
-     - config:/config
+     - config:/config/wg_confs
    ports:
      - "51820:51820/udp"
...

Disclosure: I'm not familiar enough with Wireguard or wireguard-ui to know if there are any bad implications to moving the whole mount point for the config directory

Are you using this config yourself? linuxserver/wireguard:latest creates the subfolders coredns, templates and wg_confs, which means mounting with - config:/config/wg_confs will create the path /config/wg_confs/wg_confs. If youre going to move the mount point, then you should at least do it for the wireguard-ui container, not the wireguard container. Also. i tried, but did not make it work...

vexdev commented 8 months ago

Two solutions that worked for me:

Symlink

  1. Stop wireguard-ui
  2. Remove config/wg0.conf
  3. Make a symlink to the correct file config/wg0.conf > config/wg_confs/wg0.conf
  4. Start wireguard-ui

Configuration

Apparently wireguard-ui can be configured to point to a different configuration file, in the case of the subdirectory wg_confs you should set it up like this (In docker-compose):

...
services:
  wireguard-ui:
    environment:
      - WGUI_CONFIG_FILE_PATH=/etc/wireguard/wg_confs/wg0.conf
...

Although I've had issues with this environment variable not being picked up with some reason, so I'm just using a symlink at the moment.