subspacecommunity / subspace

A fork of the simple WireGuard VPN server GUI community maintained
MIT License
1.8k stars 131 forks source link

docker-compose SUBSPACE_IPV4_POOL= ignored? #158

Open eroper opened 3 years ago

eroper commented 3 years ago

After providing SUBSPACE_IPV4_POOL as a docker-compose environment variable, I'm still ending up with peers defined in the default 10.99.98.3 space. Is this expected behavior?

version: "3.3"
services:
  subspace:
   image: eroper/subspace:latest
   container_name: subspace
   volumes:
    - /subspace-data:/data
   restart: always
   environment:
    - SUBSPACE_HTTP_HOST=somehost.example.com
    - SUBSPACE_LETSENCRYPT=true
    - SUBSPACE_HTTP_INSECURE=false
    - SUBSPACE_HTTP_ADDR=":80"
    - SUBSPACE_NAMESERVER=X.X.X.X
    - SUBSPACE_LISTENPORT=XXXXX
    - SUBSPACE_IPV4_POOL=192.168.198.0/24
    - SUBSPACE_IPV6_POOL=fd00::10:97:0/64
    - SUBSPACE_IPV4_GW=192.168.198.1
    - SUBSPACE_IPV6_GW=fd00::10:97:1
    - SUBSPACE_IPV6_NAT_ENABLED=1
   cap_add:
    - NET_ADMIN
   network_mode: "host"
[Interface]
PrivateKey = XXXX
ListenPort = XXXXX

[Peer]
PublicKey =XXXX
AllowedIPs = 10.99.97.3/32,fd00::10:97:3/128
DerDanilo commented 3 years ago

I can confirm that this doesn't seem to work. The gateway and DNS server target seems okay though (wireguard server as single dns server).

1F916 commented 3 years ago

I could confirm this in testing with and without docker-compose. Based on this line in "handlers.go" it looks like the actual subspace program is looking for an environment variable named "SUBSPACE_IPV4_PREF" instead of "SUBSPACE_IPV4_POOL". It worked in my tests when I set something like "SUBSPACE_IPV4_PREF=192.168.198.". You still need to keep the "SUBSPACE_IPV4_POOL" variable though, because "entrypoint.sh" sets iptables rules based on that.

The following docker-compose.yml worked fine for me:

version: "3.3"
services:
  subspace:
   image: subspacecommunity/subspace:latest
   container_name: subspace
   volumes:
    - /opt/docker/subspace:/data
   restart: always
   environment:
    - SUBSPACE_HTTP_HOST=wireguard.example.com
    - SUBSPACE_LETSENCRYPT=true
    - SUBSPACE_HTTP_INSECURE=false
    - SUBSPACE_HTTP_ADDR=":80"
    - SUBSPACE_NAMESERVERS=1.1.1.1,8.8.8.8
    - SUBSPACE_LISTENPORT=51820
    - SUBSPACE_IPV4_POOL=192.168.201.0/24
    - SUBSPACE_IPV4_PREF=192.168.201.
    - SUBSPACE_IPV4_CIDR=24
    - SUBSPACE_IPV4_GW=192.168.201.1
    - SUBSPACE_IPV6_NAT_ENABLED=0
   cap_add:
    - NET_ADMIN
   network_mode: "host"
1F916 commented 3 years ago

Upon further investigation, this line in "entrypoint.sh" basically sets the correct "SUBSPACE_IPV4_PREF" whenever "SUBSPACE_IPV4_GW" is left empty. So providing "SUBSPACE_IPV4_GW" basically leads to "SUBSPACE_IPV4_POOL" getting ignored in the main program, because the "SUBSPACE_IPV4_PREF" variable it expects is never set.