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:
1 parent
c36e2092c5
commit
c17e9aa140
55 files changed
+7177
-27
No files matched your search
@@ -6,14 +6,32 @@ import { users, userRoles } from "../db/schema.js";
|
||||
import { requireAuth, requireRole } from "../auth/middleware.js";
|
||||
import { recordAudit } from "../services/audit.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
import { getSettings } from "../services/settingsStore.js";
|
||||
import { roleFromGroups } from "../auth/groups.js";
|
||||
|
||||
export const usersRouter = Router();
|
||||
|
||||
usersRouter.use(requireAuth, requireRole("admin"));
|
||||
|
||||
/** What is stored for a person's groups, as a list. Anything that isn't one is none rather than an error. */
|
||||
export function parseGroups(stored: string | null): string[] | null {
|
||||
if (!stored) return null;
|
||||
try {
|
||||
const v = JSON.parse(stored);
|
||||
return Array.isArray(v) ? v.filter((g): g is string => typeof g === "string") : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
usersRouter.get("/", asyncHandler(async (_req, res) => {
|
||||
const rows = await db.select().from(users).orderBy(users.createdAt);
|
||||
res.json({ users: rows });
|
||||
const { signIn } = await getSettings();
|
||||
res.json({
|
||||
users: rows.map((u) => ({ id: u.id, oidcSub: u.oidcSub, email: u.email, name: u.name, role: u.role, createdAt: u.createdAt, lastLoginAt: u.lastLoginAt, groups: parseGroups(u.groups) })),
|
||||
// When roles follow groups, a role set by hand would be undone at the next sign-in, so the page says so instead of offering it.
|
||||
rolesFollowGroups: signIn.roleFromGroups,
|
||||
});
|
||||
}));
|
||||
|
||||
const updateRoleSchema = z.object({
|
||||
@@ -21,6 +39,10 @@ const updateRoleSchema = z.object({
|
||||
});
|
||||
|
||||
usersRouter.patch("/:id/role", asyncHandler(async (req, res) => {
|
||||
const { signIn } = await getSettings();
|
||||
if (signIn.roleFromGroups) {
|
||||
return res.status(409).json({ error: "managed_by_groups", message: "Roles are set from sign-in groups (Settings → Sign-in), so a role set here would be undone at the next sign-in. Change the person's group in the identity provider, or switch the group rules off." });
|
||||
}
|
||||
const id = Number(req.params.id);
|
||||
const parsed = updateRoleSchema.safeParse(req.body);
|
||||
if (!parsed.success) {
|
||||
@@ -60,3 +82,26 @@ usersRouter.patch("/:id/role", asyncHandler(async (req, res) => {
|
||||
|
||||
res.json({ user: updated });
|
||||
}));
|
||||
|
||||
const previewSchema = z.object({
|
||||
groupsClaim: z.string().optional(),
|
||||
adminGroups: z.array(z.string().trim().min(1).max(100)).max(20).default([]),
|
||||
operatorGroups: z.array(z.string().trim().min(1).max(100)).max(20).default([]),
|
||||
otherwise: z.enum(["viewer", "keep"]).default("viewer"),
|
||||
});
|
||||
|
||||
// What each person would be, if these group rules were switched on now and they signed in again with the groups they had last time.
|
||||
// Nothing is saved or changed: it is for checking the names before relying on them.
|
||||
usersRouter.post("/preview-group-roles", asyncHandler(async (req, res) => {
|
||||
const parsed = previewSchema.safeParse(req.body);
|
||||
if (!parsed.success) return res.status(400).json({ error: "invalid_body", details: parsed.error.flatten() });
|
||||
const rows = await db.select().from(users).orderBy(users.name);
|
||||
const rules = { roleFromGroups: true, groupsClaim: parsed.data.groupsClaim ?? "groups", adminGroups: parsed.data.adminGroups, operatorGroups: parsed.data.operatorGroups, otherwise: parsed.data.otherwise };
|
||||
const people = rows.map((u) => {
|
||||
const groups = parseGroups(u.groups);
|
||||
return { id: u.id, name: u.name ?? u.email ?? u.oidcSub, role: u.role, groups, wouldBe: groups === null ? null : roleFromGroups(rules, groups, u.role) };
|
||||
});
|
||||
// Said plainly, because it is the one way to lock yourself out: nobody left with admin.
|
||||
const adminsAfter = people.filter((p) => (p.wouldBe ?? p.role) === "admin").length;
|
||||
res.json({ people, adminsAfter });
|
||||
}));
|
||||
Reference in new issue
Block a user