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
@@ -0,0 +1,193 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, type GroupRolePreview, type SignInSettings as SignInSettingsData } from "../../api/client";
|
||||
import { ErrorNotice } from "../../components/Notice";
|
||||
import { PageSkeleton } from "../../components/Skeleton";
|
||||
import { readableError } from "../../utils/errors";
|
||||
import { toast } from "../../utils/toast";
|
||||
|
||||
const DEFAULTS: SignInSettingsData = { roleFromGroups: false, groupsClaim: "groups", adminGroups: [], operatorGroups: [], otherwise: "viewer" };
|
||||
|
||||
/** One name per line or separated by commas — whichever is easier to paste in. */
|
||||
const parseNames = (text: string): string[] => [...new Set(text.split(/[\n,]/).map((s) => s.trim()).filter(Boolean))];
|
||||
|
||||
/**
|
||||
* Who is an administrator, an operator or a viewer, decided from the groups the identity provider (Authentik) says a person is in, each
|
||||
* time they sign in — instead of by hand on the Users page. Off by default. "Check" shows what each person would become, from the
|
||||
* groups they had at their last sign-in, before it is switched on.
|
||||
*/
|
||||
export default function SignInSettings() {
|
||||
const [loaded, setLoaded] = useState<SignInSettingsData | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [enabled, setEnabled] = useState(false);
|
||||
const [claim, setClaim] = useState("groups");
|
||||
const [adminText, setAdminText] = useState("");
|
||||
const [operatorText, setOperatorText] = useState("");
|
||||
const [otherwise, setOtherwise] = useState<"viewer" | "keep">("viewer");
|
||||
const [preview, setPreview] = useState<GroupRolePreview | null>(null);
|
||||
const [busy, setBusy] = useState<"check" | "save" | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
api.settings
|
||||
.get()
|
||||
.then((res) => {
|
||||
const s = res.settings.signIn ?? DEFAULTS;
|
||||
setLoaded(s);
|
||||
setEnabled(s.roleFromGroups);
|
||||
setClaim(s.groupsClaim);
|
||||
setAdminText(s.adminGroups.join("\n"));
|
||||
setOperatorText(s.operatorGroups.join("\n"));
|
||||
setOtherwise(s.otherwise);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
}, []);
|
||||
|
||||
if (!loaded) return error ? <ErrorNotice error={error} /> : <PageSkeleton />;
|
||||
|
||||
const draft = (): SignInSettingsData => ({ roleFromGroups: enabled, groupsClaim: claim.trim() || "groups", adminGroups: parseNames(adminText), operatorGroups: parseNames(operatorText), otherwise });
|
||||
const dirty = JSON.stringify(draft()) !== JSON.stringify(loaded);
|
||||
|
||||
async function check() {
|
||||
setBusy("check");
|
||||
setError(null);
|
||||
try {
|
||||
const d = draft();
|
||||
setPreview(await api.users.previewGroupRoles({ groupsClaim: d.groupsClaim, adminGroups: d.adminGroups, operatorGroups: d.operatorGroups, otherwise: d.otherwise }));
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function save() {
|
||||
setBusy("save");
|
||||
setError(null);
|
||||
try {
|
||||
const d = draft();
|
||||
await api.settings.update({ signIn: d });
|
||||
setLoaded(d);
|
||||
toast.success(d.roleFromGroups ? "Saved. Roles now follow groups at each sign-in." : "Saved. Roles are set by hand on the Users page.");
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
const noAdmin = enabled && preview !== null && preview.adminsAfter === 0;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center justify-content-between mb-3">
|
||||
<h3 className="mb-0">Sign-in</h3>
|
||||
<button className="btn btn-primary" onClick={save} disabled={busy !== null || !dirty || noAdmin}>
|
||||
{busy === "save" ? "Saving…" : "Save"}
|
||||
</button>
|
||||
</div>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Roles from groups</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<p className="text-secondary">
|
||||
By default a new person is a viewer until an administrator changes their role on the Users page. Here you can let the groups the identity provider reports decide it instead:
|
||||
at every sign-in a person is an administrator if they are in an admin group, an operator if they are in an operator group, and otherwise what you choose below.
|
||||
In Authentik the <code>groups</code> claim comes with the <em>profile</em> scope this app already asks for.
|
||||
</p>
|
||||
<label className="form-check mb-3">
|
||||
<input type="checkbox" className="form-check-input" checked={enabled} onChange={(e) => setEnabled(e.target.checked)} />
|
||||
<span className="form-check-label">Set roles from groups at each sign-in</span>
|
||||
</label>
|
||||
<div className="row g-3">
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="si-claim">
|
||||
Claim that holds the groups
|
||||
</label>
|
||||
<input id="si-claim" className="form-control" value={claim} onChange={(e) => setClaim(e.target.value)} />
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="si-admin">
|
||||
Admin groups
|
||||
</label>
|
||||
<textarea id="si-admin" className="form-control" rows={3} placeholder={"homelab-admins"} value={adminText} onChange={(e) => setAdminText(e.target.value)} />
|
||||
<div className="form-hint">One per line, or separated by commas. Case doesn't matter.</div>
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="si-operator">
|
||||
Operator groups
|
||||
</label>
|
||||
<textarea id="si-operator" className="form-control" rows={3} placeholder={"homelab-ops"} value={operatorText} onChange={(e) => setOperatorText(e.target.value)} />
|
||||
</div>
|
||||
<div className="col-md-6">
|
||||
<label className="form-label" htmlFor="si-otherwise">
|
||||
Someone in none of those groups
|
||||
</label>
|
||||
<select id="si-otherwise" className="form-select" value={otherwise} onChange={(e) => setOtherwise(e.target.value as "viewer" | "keep")}>
|
||||
<option value="viewer">becomes a viewer</option>
|
||||
<option value="keep">keeps the role they already have</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="alert alert-info mt-3 mb-0">
|
||||
Safeguards: if a sign-in carries no groups at all (a wrong claim name, say) roles are left exactly as they are; the only administrator is never demoted by a group rule;
|
||||
and the very first person to sign in is still the administrator. While this is on, roles can't be set by hand — a role set on the Users page would be undone at the next sign-in.
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-footer d-flex flex-wrap align-items-center gap-2">
|
||||
<button className="btn btn-outline-secondary" onClick={check} disabled={busy !== null}>
|
||||
{busy === "check" ? "Checking…" : "Check against the groups people had last time"}
|
||||
</button>
|
||||
<span className="text-secondary small">Changes nothing — it shows what each person would be.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{preview && (
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">What these rules would do</h3>
|
||||
</div>
|
||||
{preview.adminsAfter === 0 && (
|
||||
<div className="alert alert-danger m-3 mb-0" role="alert">
|
||||
With these rules nobody would be an administrator. Add an admin group that someone is in before switching this on.
|
||||
</div>
|
||||
)}
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Person</th>
|
||||
<th>Groups at last sign-in</th>
|
||||
<th>Now</th>
|
||||
<th>Would be</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{preview.people.map((p) => (
|
||||
<tr key={p.id}>
|
||||
<td>{p.name}</td>
|
||||
<td className="text-secondary">{p.groups === null ? "not known yet — they haven't signed in with groups" : p.groups.length === 0 ? "none" : p.groups.join(", ")}</td>
|
||||
<td>{p.role}</td>
|
||||
<td>
|
||||
{p.wouldBe === null ? (
|
||||
<span className="text-secondary">unchanged until they sign in</span>
|
||||
) : p.wouldBe === p.role ? (
|
||||
<span className="text-secondary">{p.wouldBe}</span>
|
||||
) : (
|
||||
<span className="fw-bold">{p.wouldBe}</span>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className="card-footer text-secondary small">
|
||||
Groups are recorded at every sign-in, whether or not this is on, so people need to have signed in once since this was installed to show up here.
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user