Add runbooks, backup coverage, inventory, roles from groups, Prometheus metrics and event webhooks

- Runbooks: notes per server/integration, shown next to matching alerts
- Backup coverage page across Proxmox and PBS, with a digest section
- Hardware inventory with warranty, power and running cost
- Authentik group to role mapping with preview and safeguards
- /metrics (bearer token) and signed outgoing event webhooks
- Docs: README, DATABASE, NOTIFICATIONS, ROLES and new API.md

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-17 20:41:00 +02:00
1 parent c36e2092c5
commit c17e9aa140
55 files changed
+7177 -27

No files matched your search

+44 -6
View File
@@ -1,35 +1,72 @@
import { eq } from "drizzle-orm";
import { and, eq, ne } from "drizzle-orm";
import { db } from "../db/client.js";
import { users } from "../db/schema.js";
import { users, type UserRole } from "../db/schema.js";
import { getSettings } from "../services/settingsStore.js";
import { roleFromGroups } from "./groups.js";
export interface RoleChange {
from: UserRole;
to: UserRole;
groups: string[];
/** The group rules would have taken the last administrator's rights away, so the role was left alone. */
blocked?: boolean;
}
/**
* Called on every successful OIDC login. The very first user ever to sign in
* becomes admin; everyone after defaults to viewer until an admin promotes
* them from the Users page.
* them from the Users page — or, when roles follow groups (Settings → Sign-in),
* until the groups the identity provider reports decide it.
*
* `groups` is what the provider said, or null/undefined when it said nothing about groups at all. That is not "in no groups": with no
* information the role is left exactly as it is, so a wrong claim name can't quietly demote everyone. And the last administrator is
* never demoted by a group rule, whatever the groups say.
*/
export async function upsertUserFromLogin(params: {
sub: string;
email?: string;
name?: string;
}): Promise<{ user: typeof users.$inferSelect; created: boolean }> {
groups?: string[] | null;
}): Promise<{ user: typeof users.$inferSelect; created: boolean; roleChange?: RoleChange }> {
const [existing] = await db.select().from(users).where(eq(users.oidcSub, params.sub)).limit(1);
const now = new Date().toISOString();
const { signIn } = await getSettings();
const mapping = signIn.roleFromGroups && params.groups !== null && params.groups !== undefined;
const groupsJson = params.groups ? JSON.stringify(params.groups) : undefined;
if (existing) {
let role = existing.role;
let roleChange: RoleChange | undefined;
if (mapping) {
const wanted = roleFromGroups(signIn, params.groups!, existing.role);
if (wanted !== existing.role) {
const demotesAdmin = existing.role === "admin" && wanted !== "admin";
const otherAdmin = demotesAdmin ? await db.select({ id: users.id }).from(users).where(and(eq(users.role, "admin"), ne(users.id, existing.id))).limit(1) : [];
if (demotesAdmin && otherAdmin.length === 0) {
roleChange = { from: existing.role, to: wanted, groups: params.groups!, blocked: true };
} else {
role = wanted;
roleChange = { from: existing.role, to: wanted, groups: params.groups! };
}
}
}
const [updated] = await db
.update(users)
.set({
email: params.email ?? existing.email,
name: params.name ?? existing.name,
lastLoginAt: now,
role,
...(groupsJson !== undefined ? { groups: groupsJson } : {}),
})
.where(eq(users.id, existing.id))
.returning();
return { user: updated, created: false };
return { user: updated, created: false, roleChange };
}
const anyUser = await db.select({ id: users.id }).from(users).limit(1);
const role = anyUser.length === 0 ? ("admin" as const) : ("viewer" as const);
// The first person ever is the administrator, so there is always one; after that the groups decide, when they are used, else viewer.
const role: UserRole = anyUser.length === 0 ? "admin" : mapping ? roleFromGroups({ ...signIn, otherwise: "viewer" }, params.groups!, "viewer") : "viewer";
const [created] = await db
.insert(users)
@@ -39,6 +76,7 @@ export async function upsertUserFromLogin(params: {
name: params.name,
role,
lastLoginAt: now,
...(groupsJson !== undefined ? { groups: groupsJson } : {}),
})
.returning();
return { user: created, created: true };