This commit is contained in:
Owen 2025-02-21 18:51:16 -05:00
parent 450b0bf4fa
commit b9080a1ec1
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
7 changed files with 15 additions and 18 deletions

View file

@ -32,7 +32,7 @@ gerbil:
site_block_size: 30 site_block_size: 30
subnet_group: 100.89.137.0/20 subnet_group: 100.89.137.0/20
wg_site: newt:
start_port: 51820 start_port: 51820
block_size: 24 block_size: 24
subnet_group: 100.89.138.0/20 subnet_group: 100.89.138.0/20

View file

@ -110,7 +110,7 @@ const configSchema = z.object({
block_size: z.number().positive().gt(0), block_size: z.number().positive().gt(0),
site_block_size: z.number().positive().gt(0) site_block_size: z.number().positive().gt(0)
}), }),
wg_site: z.object({ newt: z.object({
block_size: z.number().positive().gt(0), block_size: z.number().positive().gt(0),
subnet_group: z.string(), subnet_group: z.string(),
start_port: portSchema, start_port: portSchema,

View file

@ -18,7 +18,7 @@ import HttpCode from "@server/types/HttpCode";
import createHttpError from "http-errors"; import createHttpError from "http-errors";
import logger from "@server/logger"; import logger from "@server/logger";
import { eq, and } from "drizzle-orm"; import { eq, and } from "drizzle-orm";
import { addPeer } from "../gerbil/peers"; import { addPeer } from "../newt/peers";
import { fromError } from "zod-validation-error"; import { fromError } from "zod-validation-error";
import { newts } from "@server/db/schema"; import { newts } from "@server/db/schema";
import moment from "moment"; import moment from "moment";

View file

@ -101,16 +101,13 @@ export async function pickClientDefaults(
subnets.push( subnets.push(
address.replace( address.replace(
/\/\d+$/, /\/\d+$/,
`/${config.getRawConfig().wg_site.site_block_size}` `/${config.getRawConfig().newt.site_block_size}`
) )
); );
logger.debug(`Subnets: ${subnets}`);
logger.debug(`Address: ${address}`);
logger.debug(`Block size: ${config.getRawConfig().wg_site.block_size}`);
logger.debug(`Site block size: ${config.getRawConfig().wg_site.site_block_size}`);
const newSubnet = findNextAvailableCidr( const newSubnet = findNextAvailableCidr(
subnets, subnets,
config.getRawConfig().wg_site.site_block_size, config.getRawConfig().newt.site_block_size,
address address
); );
if (!newSubnet) { if (!newSubnet) {
@ -133,7 +130,7 @@ export async function pickClientDefaults(
name: site.name, name: site.name,
listenPort: listenPort, listenPort: listenPort,
endpoint: endpoint, endpoint: endpoint,
subnet: newSubnet, subnet: `${newSubnet.split("/")[0]}/${config.getRawConfig().newt.block_size}`, // we want the block size of the whole subnet
olmId: olmId, olmId: olmId,
olmSecret: secret olmSecret: secret
}, },

View file

@ -105,7 +105,7 @@ export const handleGetConfigMessage: MessageHandler = async (context) => {
clientsRes.map(async (client) => { clientsRes.map(async (client) => {
return { return {
publicKey: client.pubKey, publicKey: client.pubKey,
allowedIps: ["0.0.0.0/0"] // TODO: We should lock this down more allowedIps: [client.subnet]
}; };
}) })
); );
@ -144,8 +144,8 @@ async function getNextAvailableSubnet(): Promise<string> {
let subnet = findNextAvailableCidr( let subnet = findNextAvailableCidr(
addresses, addresses,
config.getRawConfig().wg_site.block_size, config.getRawConfig().newt.block_size,
config.getRawConfig().wg_site.subnet_group config.getRawConfig().newt.subnet_group
); );
if (!subnet) { if (!subnet) {
throw new Error("No available subnets remaining in space"); throw new Error("No available subnets remaining in space");
@ -167,7 +167,7 @@ async function getNextAvailablePort(): Promise<number> {
}).from(sites); }).from(sites);
// Find the first available port between 1024 and 65535 // Find the first available port between 1024 and 65535
let nextPort = config.getRawConfig().wg_site.start_port; let nextPort = config.getRawConfig().newt.start_port;
for (const port of existingPorts) { for (const port of existingPorts) {
if (port.listenPort && port.listenPort > nextPort) { if (port.listenPort && port.listenPort > nextPort) {
break; break;

View file

@ -73,11 +73,11 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
logger.warn("Site has no subnet"); logger.warn("Site has no subnet");
return; return;
} }
// add the peer to the exit node // add the peer to the exit node
await addPeer(site.siteId, { await addPeer(site.siteId, {
publicKey: publicKey, publicKey: publicKey,
allowedIps: [site.subnet] allowedIps: [client.subnet]
}); });
return { return {
@ -87,7 +87,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
endpoint: `${site.endpoint}:${site.listenPort}`, endpoint: `${site.endpoint}:${site.listenPort}`,
publicKey: site.publicKey, publicKey: site.publicKey,
serverIP: site.address!.split("/")[0], serverIP: site.address!.split("/")[0],
tunnelIP: client.subnet.split("/")[0] tunnelIP: client.subnet
} }
}, },
broadcast: false, // Send to all olms broadcast: false, // Send to all olms

View file

@ -84,7 +84,7 @@ export async function pickSiteDefaults(
name: exitNode.name, name: exitNode.name,
listenPort: exitNode.listenPort, listenPort: exitNode.listenPort,
endpoint: exitNode.endpoint, endpoint: exitNode.endpoint,
subnet: newSubnet, subnet: `${newSubnet.split("/")[0]}/${config.getRawConfig().gerbil.block_size}`, // we want the block size of the whole subnet
newtId, newtId,
newtSecret: secret newtSecret: secret
}, },