Add INIT_ALLOWED_IPS for unattended setup (#2164)

* Add INIT_ALLOWED_IPS env var

Implement INIT_ALLOWED_IPS env var like the INIT_DNS to preset the global Allowed IPs field.

* Docs: Add INIT_ALLOWED_IPS var to unattended setup table

* Make UserConfigService.update param partial

Update UserConfigService.update() to accept any subset of the updatable fields.
Remove the unnecessary userConfig object from  DBService.initialSetup()

* formatting fix

* format on linux

On windows prettier get confused by global conf... common windows things
This commit is contained in:
Németh Bálint
2025-09-16 12:16:31 +02:00
committed by GitHub
parent 8892c43a7d
commit 6c0d8e91fa
4 changed files with 21 additions and 14 deletions

View File

@@ -7,7 +7,7 @@ If you want to run the setup without any user interaction, e.g. with a tool like
These will only be used during the first start of the container. After that, the setup will be disabled. These will only be used during the first start of the container. After that, the setup will be disabled.
| Env | Example | Description | Group | | Env | Example | Description | Group |
| ---------------- | ----------------- | --------------------------------------------------------- | ----- | | ------------------ | ---------------------------- | --------------------------------------------------------- | ----- |
| `INIT_ENABLED` | `true` | Enables the below env vars | 0 | | `INIT_ENABLED` | `true` | Enables the below env vars | 0 |
| `INIT_USERNAME` | `admin` | Sets admin username | 1 | | `INIT_USERNAME` | `admin` | Sets admin username | 1 |
| `INIT_PASSWORD` | `Se!ureP%ssw` | Sets admin password | 1 | | `INIT_PASSWORD` | `Se!ureP%ssw` | Sets admin password | 1 |
@@ -16,8 +16,9 @@ These will only be used during the first start of the container. After that, the
| `INIT_DNS` | `1.1.1.1,8.8.8.8` | Sets global dns setting | 2 | | `INIT_DNS` | `1.1.1.1,8.8.8.8` | Sets global dns setting | 2 |
| `INIT_IPV4_CIDR` | `10.8.0.0/24` | Sets IPv4 cidr | 3 | | `INIT_IPV4_CIDR` | `10.8.0.0/24` | Sets IPv4 cidr | 3 |
| `INIT_IPV6_CIDR` | `2001:0DB8::/32` | Sets IPv6 cidr | 3 | | `INIT_IPV6_CIDR` | `2001:0DB8::/32` | Sets IPv6 cidr | 3 |
| `INIT_ALLOWED_IPS` | `10.8.0.0/24,2001:0DB8::/32` | Sets global Allowed IPs | 4 |
/// warning | Variables have to be used together /// warning | Variables have to be used together
If variables are in the same group, you have to set all of them. For example, if you set `INIT_IPV4_CIDR`, you also have to set `INIT_IPV6_CIDR`. If variables are in the same group, you have to set all of them. For example, if you set `INIT_IPV4_CIDR`, you also have to set `INIT_IPV6_CIDR`.

View File

@@ -54,7 +54,7 @@ export class UserConfigService {
}); });
} }
update(data: UserConfigUpdateType) { update(data: Partial<UserConfigUpdateType>) {
return this.#db return this.#db
.update(userConfig) .update(userConfig)
.set(data) .set(data)

View File

@@ -89,13 +89,18 @@ async function initialSetup(db: DBServiceType) {
if (WG_INITIAL_ENV.DNS) { if (WG_INITIAL_ENV.DNS) {
DB_DEBUG('Setting initial DNS...'); DB_DEBUG('Setting initial DNS...');
const userConfig = await db.userConfigs.get();
await db.userConfigs.update({ await db.userConfigs.update({
...userConfig,
defaultDns: WG_INITIAL_ENV.DNS, defaultDns: WG_INITIAL_ENV.DNS,
}); });
} }
if (WG_INITIAL_ENV.ALLOWED_IPS) {
DB_DEBUG('Setting initial Allowed IPs...');
await db.userConfigs.update({
defaultAllowedIps: WG_INITIAL_ENV.ALLOWED_IPS,
});
}
if ( if (
WG_INITIAL_ENV.USERNAME && WG_INITIAL_ENV.USERNAME &&
WG_INITIAL_ENV.PASSWORD && WG_INITIAL_ENV.PASSWORD &&

View File

@@ -38,6 +38,7 @@ export const WG_INITIAL_ENV = {
DNS: process.env.INIT_DNS?.split(',').map((x) => x.trim()), DNS: process.env.INIT_DNS?.split(',').map((x) => x.trim()),
IPV4_CIDR: process.env.INIT_IPV4_CIDR, IPV4_CIDR: process.env.INIT_IPV4_CIDR,
IPV6_CIDR: process.env.INIT_IPV6_CIDR, IPV6_CIDR: process.env.INIT_IPV6_CIDR,
ALLOWED_IPS: process.env.INIT_ALLOWED_IPS?.split(',').map((x) => x.trim()),
HOST: process.env.INIT_HOST, HOST: process.env.INIT_HOST,
PORT: process.env.INIT_PORT PORT: process.env.INIT_PORT
? Number.parseInt(process.env.INIT_PORT, 10) ? Number.parseInt(process.env.INIT_PORT, 10)