Authentik: know when the front door is about to shut
New Authentik integration (read-only, every 5 minutes): version, workers, outposts and their health, certificates and API tokens that expire, failed sign-ins and configuration errors. Monitoring -> Authentik page. Alerts: an outpost that serves apps has gone quiet (critical), certificate or token about to run out (critical close to it), no worker, failed sign-ins, configuration errors. Held by maintenance, held when unreadable, in /metrics. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0146eb8bca
commit
aebe98bf15
33 files changed
+8050
-7
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { Router } from "express";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { authentikState, integrations } from "../db/schema.js";
|
||||
import { requireAuth } from "../auth/middleware.js";
|
||||
import { authentikProblems, authentikSyncStatuses, certificatesOf, daysUntil, isAuthentikFresh, outpostsOf, tokensOf } from "../services/authentikSync.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
|
||||
export const authentikRouter = Router();
|
||||
authentikRouter.use(requireAuth);
|
||||
|
||||
/** Every Authentik, how it is, from what the last read stored: its outposts, certificates and tokens that run out, and what is wrong. Everyone signed in can see it, like the other pages made of stored readings. */
|
||||
authentikRouter.get("/", asyncHandler(async (_req, res) => {
|
||||
const [rows, states, statuses] = await Promise.all([
|
||||
db.select({ id: integrations.id, name: integrations.name, enabled: integrations.enabled }).from(integrations).where(eq(integrations.type, "authentik")).orderBy(integrations.name),
|
||||
db.select().from(authentikState),
|
||||
authentikSyncStatuses(),
|
||||
]);
|
||||
const byId = new Map(states.map((s) => [s.integrationId, s]));
|
||||
const now = new Date();
|
||||
res.json({
|
||||
authentiks: rows.map((r) => {
|
||||
const state = byId.get(r.id) ?? null;
|
||||
const status = statuses[r.id] ?? null;
|
||||
const fresh = isAuthentikFresh(status ?? undefined, now.getTime());
|
||||
return {
|
||||
id: r.id,
|
||||
name: r.name,
|
||||
enabled: r.enabled,
|
||||
status,
|
||||
fresh,
|
||||
state: state
|
||||
? {
|
||||
version: state.version,
|
||||
latestVersion: state.latestVersion,
|
||||
outdated: state.outdated,
|
||||
workers: state.workers,
|
||||
outposts: outpostsOf(state),
|
||||
certificates: certificatesOf(state).map((c) => ({ ...c, days: daysUntil(c.expires, now) })).sort((a, b) => a.days - b.days),
|
||||
tokens: tokensOf(state).map((t) => ({ ...t, days: daysUntil(t.expires, now) })).sort((a, b) => a.days - b.days),
|
||||
failedLogins24h: state.failedLogins24h,
|
||||
configErrors24h: state.configErrors24h,
|
||||
lastConfigError: state.lastConfigError,
|
||||
updatedAt: state.updatedAt,
|
||||
}
|
||||
: null,
|
||||
problems: state && fresh ? authentikProblems(r.id, r.name, state, now) : [],
|
||||
};
|
||||
}),
|
||||
});
|
||||
}));
|
||||
Reference in new issue
Block a user