Refactor wireguard to use a different config dir instead of /etc/wireguard

This commit is contained in:
2026-09-13 13:37:48 +01:00
parent 06cf72b2c9
commit 42224c94d3
10 changed files with 192 additions and 34 deletions
@@ -0,0 +1,21 @@
import { describe, expect, test } from "bun:test";
import deriveWireguardInterfaceName from "./derive-wireguard-interface-name";
describe("deriveWireguardInterfaceName", () => {
test("derives interface name from host id", () => {
expect(deriveWireguardInterfaceName({ host_id: 0 })).toBe("wgui0");
expect(deriveWireguardInterfaceName({ host_id: 1 })).toBe("wgui1");
expect(deriveWireguardInterfaceName({ host_id: 7 })).toBe("wgui7");
});
test("uses a project-scoped prefix, never stock wgN", () => {
expect(deriveWireguardInterfaceName({ host_id: 0 })).not.toBe("wg0");
expect(deriveWireguardInterfaceName({ host_id: 1 })).not.toBe("wg1");
});
test("prefix matches wg-quick interface name requirements (<= 15 chars)", () => {
expect(deriveWireguardInterfaceName({ host_id: 0 }).length).toBeLessThanOrEqual(
15,
);
});
});
@@ -0,0 +1,9 @@
const WIREGUARD_INTERFACE_NAME_PREFIX = `wgui`;
type Params = {
host_id: number;
};
export default function deriveWireguardInterfaceName({ host_id }: Params) {
return `${WIREGUARD_INTERFACE_NAME_PREFIX}${host_id}`;
}
+9 -2
View File
@@ -33,8 +33,13 @@ export default function grabDirNames(params?: Params) {
const WGUI_LIB_IP_TABLES_DIR = path.join(WGUI_LIB_DIR, `iptables`);
const WGUI_LIB_KEYS_DIR = path.join(WGUI_LIB_DIR, `keys`);
const WGUI_LIB_CLIENTS_CONFIGS_DIR = path.join(WGUI_LIB_DIR, `clients`);
const WGUI_LIB_HOSTS_CONFIGS_DIR = path.join(WGUI_LIB_DIR, `hosts`);
const WGUI_LIB_SCRIPTS_DIR = path.join(WGUI_LIB_DIR, `scripts`);
const WGUI_WG_QUICK_SYSTEMD_SCRIPT = path.join(
WGUI_LIB_SCRIPTS_DIR,
`wg-quick-systemd.sh`,
);
const WIREGUARD_HOST_CONFIG_DIR = `/etc/wireguard`;
const WIREGUARD_PRIVATE_KEY_FILE_NAME = `private.key`;
const WIREGUARD_PUBLIC_KEY_FILE_NAME = `public.key`;
const WIREGUARD_CLIENT_CONFIG_FILE_NAME = `wg.conf`;
@@ -52,8 +57,10 @@ export default function grabDirNames(params?: Params) {
WGUI_LIB_IP_TABLES_DIR,
WGUI_LIB_KEYS_DIR,
WGUI_LIB_CLIENTS_CONFIGS_DIR,
WGUI_LIB_HOSTS_CONFIGS_DIR,
WGUI_LIB_SCRIPTS_DIR,
WGUI_WG_QUICK_SYSTEMD_SCRIPT,
WIREGUARD_HOST_CONFIG_DIR,
WIREGUARD_PRIVATE_KEY_FILE_NAME,
WIREGUARD_PUBLIC_KEY_FILE_NAME,
WIREGUARD_CLIENT_CONFIG_FILE_NAME,