mirror of
https://github.com/tale/headplane.git
synced 2026-08-27 15:37:04 +00:00
feat(config): use minimal headscale config
This commit is contained in:
@@ -67,7 +67,7 @@ export async function dnsAction({ request, context }: Route.ActionArgs) {
|
||||
return { message: "Magic DNS state updated successfully" };
|
||||
}
|
||||
case "remove_ns": {
|
||||
const config = headscaleConfig.c!;
|
||||
const config = headscaleConfig.getDNSConfig();
|
||||
const ns = formData.get("ns")?.toString();
|
||||
const splitName = formData.get("split_name")?.toString();
|
||||
|
||||
@@ -76,7 +76,7 @@ export async function dnsAction({ request, context }: Route.ActionArgs) {
|
||||
}
|
||||
|
||||
if (splitName === "global") {
|
||||
const servers = config.dns.nameservers.global.filter((i) => i !== ns);
|
||||
const servers = config.nameservers.filter((i) => i !== ns);
|
||||
|
||||
await headscaleConfig.patch([
|
||||
{
|
||||
@@ -85,7 +85,7 @@ export async function dnsAction({ request, context }: Route.ActionArgs) {
|
||||
},
|
||||
]);
|
||||
} else {
|
||||
const splits = config.dns.nameservers.split;
|
||||
const splits = config.splitDns;
|
||||
const servers = splits[splitName].filter((i) => i !== ns);
|
||||
|
||||
await headscaleConfig.patch([
|
||||
@@ -100,7 +100,7 @@ export async function dnsAction({ request, context }: Route.ActionArgs) {
|
||||
return { message: "Nameserver removed successfully" };
|
||||
}
|
||||
case "add_ns": {
|
||||
const config = headscaleConfig.c!;
|
||||
const config = headscaleConfig.getDNSConfig();
|
||||
const ns = formData.get("ns")?.toString();
|
||||
const splitName = formData.get("split_name")?.toString();
|
||||
|
||||
@@ -109,8 +109,7 @@ export async function dnsAction({ request, context }: Route.ActionArgs) {
|
||||
}
|
||||
|
||||
if (splitName === "global") {
|
||||
const servers = config.dns.nameservers.global;
|
||||
servers.push(ns);
|
||||
const servers = [...config.nameservers, ns];
|
||||
|
||||
await headscaleConfig.patch([
|
||||
{
|
||||
@@ -119,9 +118,8 @@ export async function dnsAction({ request, context }: Route.ActionArgs) {
|
||||
},
|
||||
]);
|
||||
} else {
|
||||
const splits = config.dns.nameservers.split;
|
||||
const servers = splits[splitName] ?? [];
|
||||
servers.push(ns);
|
||||
const splits = config.splitDns;
|
||||
const servers = [...(splits[splitName] ?? []), ns];
|
||||
|
||||
await headscaleConfig.patch([
|
||||
{
|
||||
@@ -135,13 +133,13 @@ export async function dnsAction({ request, context }: Route.ActionArgs) {
|
||||
return { message: "Nameserver added successfully" };
|
||||
}
|
||||
case "remove_domain": {
|
||||
const config = headscaleConfig.c!;
|
||||
const config = headscaleConfig.getDNSConfig();
|
||||
const domain = formData.get("domain")?.toString();
|
||||
if (!domain) {
|
||||
return data({ success: false }, 400);
|
||||
}
|
||||
|
||||
const domains = config.dns.search_domains.filter((i) => i !== domain);
|
||||
const domains = config.searchDomains.filter((i) => i !== domain);
|
||||
await headscaleConfig.patch([
|
||||
{
|
||||
path: "dns.search_domains",
|
||||
@@ -153,14 +151,13 @@ export async function dnsAction({ request, context }: Route.ActionArgs) {
|
||||
return { message: "Domain removed successfully" };
|
||||
}
|
||||
case "add_domain": {
|
||||
const config = headscaleConfig.c!;
|
||||
const config = headscaleConfig.getDNSConfig();
|
||||
const domain = formData.get("domain")?.toString();
|
||||
if (!domain) {
|
||||
return data({ success: false }, 400);
|
||||
}
|
||||
|
||||
const domains = config.dns.search_domains;
|
||||
domains.push(domain);
|
||||
const domains = [...config.searchDomains, domain];
|
||||
|
||||
await headscaleConfig.patch([
|
||||
{
|
||||
|
||||
@@ -35,17 +35,7 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
||||
|
||||
const writablePermission = auth.can(principal, Capabilities.write_network);
|
||||
|
||||
const config = headscaleConfig.c!;
|
||||
const dns = {
|
||||
prefixes: config.prefixes,
|
||||
magicDns: config.dns.magic_dns,
|
||||
baseDomain: config.dns.base_domain,
|
||||
nameservers: config.dns.nameservers.global,
|
||||
splitDns: config.dns.nameservers.split,
|
||||
searchDomains: config.dns.search_domains,
|
||||
overrideDns: config.dns.override_local_dns,
|
||||
extraRecords: headscaleConfig.d,
|
||||
};
|
||||
const dns = headscaleConfig.getDNSConfig();
|
||||
|
||||
return {
|
||||
...dns,
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
||||
// Only warn if Headscale isn't using OIDC — if it is, the user
|
||||
// Just needs to connect a device and Headscale will auto-create
|
||||
// Their account, at which point auto-link will pick it up.
|
||||
if (!headscaleConfig.c?.oidc) {
|
||||
if (!headscaleConfig.hasOIDCConfig()) {
|
||||
unlinked = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,12 +43,7 @@ export async function loader({ request, params, context }: Route.LoaderArgs) {
|
||||
throw data(null, { status: 204 });
|
||||
}
|
||||
|
||||
let magic: string | undefined;
|
||||
if (headscaleConfig.readable()) {
|
||||
if (headscaleConfig.c?.dns.magic_dns) {
|
||||
magic = headscaleConfig.c.dns.base_domain;
|
||||
}
|
||||
}
|
||||
const magic = headscaleConfig.getMagicDNSBaseDomain();
|
||||
|
||||
const { api } = await getRequestApi(request);
|
||||
const [nodesSnap, usersSnap] = await Promise.all([
|
||||
|
||||
@@ -56,12 +56,7 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
||||
const nodes = nodesSnap.data;
|
||||
const users = usersSnap.data;
|
||||
|
||||
let magic: string | undefined;
|
||||
if (headscaleConfig.readable()) {
|
||||
if (headscaleConfig.c?.dns.magic_dns) {
|
||||
magic = headscaleConfig.c.dns.base_domain;
|
||||
}
|
||||
}
|
||||
const magic = headscaleConfig.getMagicDNSBaseDomain();
|
||||
|
||||
const agents = agentsFeature.state === "enabled" ? agentsFeature.value : undefined;
|
||||
const [statsResult, policyResult] = await Promise.allSettled([
|
||||
|
||||
@@ -48,7 +48,9 @@ export async function restrictionAction({ request, context }: Route.ActionArgs)
|
||||
});
|
||||
}
|
||||
|
||||
const domains = [...new Set([...(headscaleConfig.c?.oidc?.allowed_domains ?? []), domain])];
|
||||
const domains = [
|
||||
...new Set([...(headscaleConfig.getOIDCConfig()?.allowedDomains ?? []), domain]),
|
||||
];
|
||||
|
||||
await headscaleConfig.patch([
|
||||
{
|
||||
@@ -69,7 +71,7 @@ export async function restrictionAction({ request, context }: Route.ActionArgs)
|
||||
});
|
||||
}
|
||||
|
||||
const storedDomains = headscaleConfig.c?.oidc?.allowed_domains ?? [];
|
||||
const storedDomains = headscaleConfig.getOIDCConfig()?.allowedDomains ?? [];
|
||||
if (!storedDomains.includes(domain)) {
|
||||
// Domain not found in the list
|
||||
throw data(`Domain "${domain}" not found in allowed domains.`, {
|
||||
@@ -97,7 +99,9 @@ export async function restrictionAction({ request, context }: Route.ActionArgs)
|
||||
});
|
||||
}
|
||||
|
||||
const groups = [...new Set([...(headscaleConfig.c?.oidc?.allowed_groups ?? []), group])];
|
||||
const groups = [
|
||||
...new Set([...(headscaleConfig.getOIDCConfig()?.allowedGroups ?? []), group]),
|
||||
];
|
||||
|
||||
await headscaleConfig.patch([
|
||||
{
|
||||
@@ -118,7 +122,7 @@ export async function restrictionAction({ request, context }: Route.ActionArgs)
|
||||
});
|
||||
}
|
||||
|
||||
const storedGroups = headscaleConfig.c?.oidc?.allowed_groups ?? [];
|
||||
const storedGroups = headscaleConfig.getOIDCConfig()?.allowedGroups ?? [];
|
||||
if (!storedGroups.includes(group)) {
|
||||
// Group not found in the list
|
||||
throw data(`Group "${group}" not found in allowed groups.`, {
|
||||
@@ -147,7 +151,7 @@ export async function restrictionAction({ request, context }: Route.ActionArgs)
|
||||
});
|
||||
}
|
||||
|
||||
const users = [...new Set([...(headscaleConfig.c?.oidc?.allowed_users ?? []), user])];
|
||||
const users = [...new Set([...(headscaleConfig.getOIDCConfig()?.allowedUsers ?? []), user])];
|
||||
|
||||
await headscaleConfig.patch([
|
||||
{
|
||||
@@ -168,7 +172,7 @@ export async function restrictionAction({ request, context }: Route.ActionArgs)
|
||||
});
|
||||
}
|
||||
|
||||
const storedUsers = headscaleConfig.c?.oidc?.allowed_users ?? [];
|
||||
const storedUsers = headscaleConfig.getOIDCConfig()?.allowedUsers ?? [];
|
||||
if (!storedUsers.includes(user)) {
|
||||
// User not found in the list
|
||||
throw data(`User "${user}" not found in allowed users.`, {
|
||||
|
||||
@@ -24,7 +24,8 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
||||
});
|
||||
}
|
||||
|
||||
if (!headscaleConfig.c?.oidc) {
|
||||
const oidc = headscaleConfig.getOIDCConfig();
|
||||
if (!oidc) {
|
||||
throw data("OIDC is not configured on this Headscale instance.", {
|
||||
status: 501,
|
||||
});
|
||||
@@ -33,9 +34,9 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
||||
return {
|
||||
access: auth.can(principal, Capabilities.configure_iam),
|
||||
settings: {
|
||||
domains: [...new Set(headscaleConfig.c.oidc.allowed_domains)],
|
||||
groups: [...new Set(headscaleConfig.c.oidc.allowed_groups)],
|
||||
users: [...new Set(headscaleConfig.c.oidc.allowed_users)],
|
||||
domains: [...new Set(oidc.allowedDomains)],
|
||||
groups: [...new Set(oidc.allowedGroups)],
|
||||
users: [...new Set(oidc.allowedUsers)],
|
||||
},
|
||||
writable: headscaleConfig.writable(),
|
||||
};
|
||||
|
||||
@@ -138,12 +138,7 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
||||
claimed: claimedIds.has(u.id),
|
||||
}));
|
||||
|
||||
let magic: string | undefined;
|
||||
if (headscaleConfig.readable()) {
|
||||
if (headscaleConfig.c?.dns.magic_dns) {
|
||||
magic = headscaleConfig.c.dns.base_domain;
|
||||
}
|
||||
}
|
||||
const magic = headscaleConfig.getMagicDNSBaseDomain();
|
||||
|
||||
const isOwner = isUserPrincipal(principal) && principal.user.role === "owner";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user