Exit node filtering

This commit is contained in:
Owen 2025-06-19 09:29:54 -04:00
parent 3b3d7b134a
commit a0ac757982
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
2 changed files with 38 additions and 17 deletions

View file

@ -95,6 +95,9 @@ export class Config {
}
public getDomain(domainId: string) {
if (!this.rawConfig.domains || !this.rawConfig.domains[domainId]) {
return null;
}
return this.rawConfig.domains[domainId];
}

View file

@ -6,7 +6,7 @@ import HttpCode from "@server/types/HttpCode";
import config from "@server/lib/config";
import { orgs, resources, sites, Target, targets } from "@server/db";
let currentExitNodeName: string;
let currentExitNodeId: number;
export async function traefikConfigProvider(
_: Request,
@ -17,20 +17,38 @@ export async function traefikConfigProvider(
const allResources = await db.transaction(async (tx) => {
// First query to get resources with site and org info
// Get the current exit node name from config
if (!currentExitNodeId) {
if (config.getRawConfig().gerbil.exit_node_name) {
currentExitNodeName =
const exitNodeName =
config.getRawConfig().gerbil.exit_node_name!;
const [exitNode] = await tx
.select({
exitNodeId: exitNodes.exitNodeId
})
.from(exitNodes)
.where(eq(exitNodes.name, exitNodeName));
if (!exitNode) {
logger.error(
`Exit node with name ${exitNodeName} not found in the database`
);
return [];
}
currentExitNodeId = exitNode.exitNodeId;
} else {
const [exitNode] = await tx
.select({
name: exitNodes.name
exitNodeId: exitNodes.exitNodeId
})
.from(exitNodes);
.from(exitNodes)
.limit(1);
if (!exitNode) {
logger.error("No exit node found in the database");
return [];
}
currentExitNodeName = exitNode.name;
currentExitNodeId = exitNode.exitNodeId;
}
}
// Get the site(s) on this exit node
@ -53,7 +71,8 @@ export async function traefikConfigProvider(
site: {
siteId: sites.siteId,
type: sites.type,
subnet: sites.subnet
subnet: sites.subnet,
exitNodeId: sites.exitNodeId,
},
// Org fields
org: {
@ -67,7 +86,7 @@ export async function traefikConfigProvider(
.from(resources)
.innerJoin(sites, eq(sites.siteId, resources.siteId))
.innerJoin(orgs, eq(resources.orgId, orgs.orgId))
.where(eq(sites.name, currentExitNodeName));
.where(eq(sites.exitNodeId, currentExitNodeId));
// Get all resource IDs from the first query
const resourceIds = resourcesWithRelations.map((r) => r.resourceId);
@ -353,7 +372,6 @@ export async function traefikConfigProvider(
hostHeaderMiddlewareName
];
}
} else {
// Non-HTTP (TCP/UDP) configuration
const protocol = resource.protocol.toLowerCase();