donaldzou / WGDashboard

Simple dashboard for WireGuard VPN written in Python & Vue.js
https://donaldzou.github.io/WGDashboard-Documentation/
Apache License 2.0
1.65k stars 254 forks source link

[QUESTION] Managing Multiple WGDashboard Instances with a Central PostgreSQL Database #429

Closed velrino closed 1 month ago

velrino commented 1 month ago

First, CONGRATULATIONS on this amazing tool! 😊

I'm exploring the possibility of using it in a project.

In my case, I'm developing a NestJS API that manages users, and now I also need to manage the WireGuard connections for these users.

My goal is to use the WGDashboard API to handle the communication with WireGuard.

I have a few questions I'd like to clarify:

  1. I noticed that WGDashboard uses SQLite by default, but I need to set up three instances of WGDashboard, one in each region (US, EU, JP). Is it possible to use a single shared PostgreSQL database for all instances to centralize management?

  2. If a centralized PostgreSQL setup is not recommended, would it be better to keep each instance with its own local SQLite database?

  3. Lastly, I would like to confirm this: do I need to send a POST request to /api/addPeers/<configName> every time a user connects, or is there a more efficient way to manage connections automatically?

Thank you in advance for your attention!

donaldzou commented 1 month ago

Hi @velrino, I'm glad you like the project!

Regarding your questions,

  1. I noticed that WGDashboard uses SQLite by default, but I need to set up three instances of WGDashboard, one in each region (US, EU, JP). Is it possible to use a single shared PostgreSQL database for all instances to centralize management?

Theoretically, Yes, but not a good idea. The reason is how WGDashboard designed in the first place. For example: US, EU and JP both have a configuration called wg0, and each of them have a user with public key ABCD123. If all 3 instances are writing to the same database, information on ABCD123 will get override by whoever is the latest to update the database table.

  1. If a centralized PostgreSQL setup is not recommended, would it be better to keep each instance with its own local SQLite database?

Yes, as I mentioned above ;) I won't say this is the perfect solution, as SQLite have its own limit ;( but combining what WGDashboard needs, and how it designed, SQLite seems like the perfect fit.

  1. Lastly, I would like to confirm this: do I need to send a POST request to /api/addPeers/ every time a user connects, or is there a more efficient way to manage connections automatically?

You don't need to do that every single time. You just need to do once, when you add a new user, then the user can connect to the configuration by either using the Share Link feature, or manually input the configuration to WireGuard.

velrino commented 1 month ago

Hi @donaldzou

Thank you for your detailed response and insights!

I now understand the potential risks of using a centralized PostgreSQL database, especially with the possibility of overlapping configurations and key conflicts. Your explanation about each instance having its own local SQLite database makes sense given WGDashboard’s design. I’ll proceed with that approach.

Also, I appreciate the clarification regarding the need to POST to /api/addPeers/. Knowing that I only need to do it once for each user simplifies things a lot!

Thanks again for your support!

donaldzou commented 1 month ago

I'm glad I solved your questions! Anytime!