subspace icon indicating copy to clipboard operation
subspace copied to clipboard

Allow to change IPv4/v6 Prefix from environment variables

Open valentin2105 opened this issue 5 years ago • 17 comments

This PR include :

Change the IPv4/v6 Pool via environment variables :

  • SUBSPACE_IPV4_POOL
  • SUBSPACE_IPV6_POOL

Change the IPv4/v6 Gateway via environment variables :

( .1 or :1 is used by default if not present)

  • SUBSPACE_IPV4_GW
  • SUBSPACE_IPV4_GW

Enable or disable IPv6 NAT

  • SUBSPACE_IPV6_NAT_ENABLED (default 1)

Change the DNS Server via environement variable :

  • SUBSPACE_NAMESERVER (default 1.1.1.1)

Feel free to ask if any change is needed.

valentin2105 avatar Feb 28 '19 06:02 valentin2105

I would love to see this merged!

Freekers avatar Jun 11 '19 20:06 Freekers

@Freekers , if you want to try it out, check this Docker image : valentinnc/subspace:latest or my repo https://github.com/valentin2105/subspace.

valentin2105 avatar Jun 11 '19 21:06 valentin2105

@valentin2105 Wohoo that works perfectly! Thank you so much!

Freekers avatar Jun 11 '19 21:06 Freekers

@valentin2105 Can you please merge up to this commit in your repo? I need it to work with my reverse proxy: https://github.com/subspacecloud/subspace/commit/502f0f56aecea93308395a404d1720629ce2ade2

A more recent commit is fine as well :)

Thank you very much!

Freekers avatar Jun 11 '19 21:06 Freekers

@Freekers can you try it from my repo ? I have merged master from subspace. (from Github UI so maybe it's broken).

Thanks. (ask if you want I update the docker Image)

valentin2105 avatar Jun 11 '19 21:06 valentin2105

The Docker image has not been updated yet on Docker Hub if I'm not mistaken? https://hub.docker.com/r/valentinnc/subspace

I will check back tomorrow :)

Freekers avatar Jun 11 '19 21:06 Freekers

@valentin2105 Something went wrong during the merge. In handlers.go, the struct got duplicated. I tried fixing it myself in addition to making the Listenport variable, but I didn't succeed. The port changes correctly in the server.conf and Wireguard is listening on the correct Port now, but when generating the client conf, it always falls back to the default port. Can you please help me? https://github.com/Freekers/subspace/blob/master/handlers.go

Thank yoU!

Freekers avatar Jun 12 '19 09:06 Freekers

@Freekers I have fixed in my repo and Updated the docker image, it should be good ;) FYI it was the Struct which need to respect the order of declaration and assignation of variable. It's fixed now.

valentin2105 avatar Jun 12 '19 22:06 valentin2105

@valentin2105 Thank you very much! Your image is working for me now! However, I'm still having issues getting my modification to work (i.e. allow changing the Listenport using an environmental variable). I just applied your commit to my repository as well, but Subspace keeps using the default port (51820) in the generated client conf files. The server confs are fine though... Can you spot the error in my handlers.go? https://github.com/Freekers/subspace/blob/master/handlers.go

Many thanks!!

Kind regards.

Freekers avatar Jun 12 '19 22:06 Freekers

@Freekers Your code seem fine, Do you :

  • Compile well and use the good binary and not the old one present in the git..
  • Set the env variable to change the port in your docker container or Machine before launch the subspace binary ?

valentin2105 avatar Jun 12 '19 22:06 valentin2105

@valentin2105 Thanks for your reply :)

  • Yes, I did a fresh pull of the repository and deleted the local docker image first before building a new one, just to make sure
  • Yes. I checked this by connecting to the container using bash and printing the env variable. It showed up correctly: https://i.imgur.com/MXlyzFs.png

Freekers avatar Jun 12 '19 22:06 Freekers

@Freekers Did you run :

go get -u github.com/jteeuwen/go-bindata/...
go-bindata --pkg main static/... templates/... email/... 
go build 
rm subspace-linux-amd64
mv subspace  subspace-linux-amd64
docker build ... && docker push

valentin2105 avatar Jun 12 '19 22:06 valentin2105

@valentin2105 Ah, no I didn't do that. Now I see what you mean by the old binary in git. I feel stupid now! Sorry about that. Do I literally copy/paste and run your code snippet, or do I need to run more code than just that?

I have to go now, I'll check back tomorrow. Thanks for all your help so far!

Freekers avatar Jun 12 '19 22:06 Freekers

@Freekers , Don't feel stupid, there is no documentation at all in the repo. You need to launch all this command in the subspace/ folder wherer you made your change.

If you want, I can add these modification in my repo, push it here and build my docker image with it, so You can test and confirm that it work ? :) We can use this PR for that. (hoping it will be merged anyday)

valentin2105 avatar Jun 12 '19 23:06 valentin2105

Thanks for all your help!! I managed to recompile subspace's binary, rebuild the Docker and can now confirm that your and mine changes are working :) I just opened a merge request to your fork, so that we have these features neatly integrated into the same fork and so that you can push the Docker image to Docker Hub for everyone to use :) Then one day, indeed, we can hope it gets merged into master....

https://github.com/valentin2105/subspace/pull/1

Kind regards.

Freekers avatar Jun 13 '19 09:06 Freekers

@valentin2105 thank you so much for your fork and docker hub image! saved me a ton of time doing it myself

theogravity avatar Jan 27 '20 01:01 theogravity

Hi. could you tell me how I can change default GW(i mean for client use Lan network and not 0.0.0.0/0). And I cant change the pool and have DNS uncorrected

docker create \
--name subspace \
--restart always \
--network host \
--cap-add NET_ADMIN \
--volume /data:/data \
--env SUBSPACE_HTTP_HOST="vpn.hostname" \
--env SUBSPACE_NAMESERVER="192.168.18.1" \
--env SUBSPACE_LISTENPORT="51821" \
--env SUBSPACE_IPV4_POOL="192.168.25.0/24" \
--env SUBSPACE_IPV4_GW="192.168.25.1" \
--env SUBSPACE_IPV6_NAT_ENABLED="0" \
subspacecommunity/subspace:latest

with the next setting for subspace, i have the next client config:


[Interface]
PrivateKey = DNS = 192.168.25.1, fd00::10:97:1
Address = 10.99.97.4/24,fd00::10:97:4/112

[Peer]
PublicKey = 
Endpoint = vpn.hostname:51821
AllowedIPs = 0.0.0.0/0, ::/0

I want to have next client config

[Interface]
PrivateKey = DNS = 192.168.18.1
Address = 192.168.25.3

[Peer]
PublicKey = 
Endpoint = vpn.hostname:51821
AllowedIPs = 192.168.18.0.24

i.e. want to only access to LAN. and next steps create SSO. thanks

pupkarev avatar May 07 '21 19:05 pupkarev