gravitl / netmaker

Netmaker makes networks with WireGuard. Netmaker automates fast, secure, and distributed virtual networks.
https://netmaker.io
Other
9.52k stars 552 forks source link

[Bug]: Changing UI/API port is complicated #2340

Closed FallingSnow closed 1 year ago

FallingSnow commented 1 year ago

Contact Details

No response

What happened?

Changing UI/API port requires multiple changes.

  1. An environmental variable should be added to netmaker.env (e.g. PUBLIC_PORT). This should probably be set by default to 443. As far as I can tell changing env variable API_PORT changes an internal port which messes things up.
  2. netmaker container needs env variable BROKER_ENDPOINT=wss://broker.${NM_DOMAIN}:${PUBLIC_PORT} and TURN_SERVER_API_HOST=https://turnapi.${NM_DOMAIN}:${PUBLIC_PORT}
  3. netmaker-ui container needs env variable BACKEND_URL: "https://api.${NM_DOMAIN}:${PUBLIC_PORT}"
  4. caddy container needs port changed from - "443:443" to - "${PUBLIC_PORT}:443"

After this a user should just be able to change PUBLIC_PORT and everything works out of the box, except maybe the port 80 https redirect...

Version

v0.20.0

What OS are you using?

Linux

Relevant log output

$ uname -a
Linux namu 5.15.0-72-generic #79-Ubuntu SMP Wed Apr 19 08:22:18 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Contributing guidelines

FallingSnow commented 1 year ago

I've discovered that after following the instructions above, the UI generates tokens that do not contain the new port. However this can be done by decoding the base64 token, adding the port to the address, then encoding the token back into base64.

I did a little digging and it seems like the enrollment keys are pulled from the database?

FallingSnow commented 1 year ago

Seems these lines would need to change to pull the port as well so it can be stored in the token. https://github.com/gravitl/netmaker/blob/45584ce02985116c65d6cab121331e52e4388022/controllers/enrollmentkeys.go#L45 https://github.com/gravitl/netmaker/blob/45584ce02985116c65d6cab121331e52e4388022/controllers/enrollmentkeys.go#L115

FallingSnow commented 1 year ago

Turns out that there were some more changes that were needed to make actual wireguard connections. I've updated the initial issue.