From c9385387bc0a09962be9bc8785dc326da4c5de2e Mon Sep 17 00:00:00 2001 From: Bobban Rydh Date: Sun, 1 Nov 2026 00:58:33 +0100 Subject: [PATCH] =?UTF-8?q?Create=20Authentik=20groups=20from=20Apps=20?= =?UTF-8?q?=E2=86=92=20Authentik?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A New group form in the Groups section makes a group with a name and nothing else: it starts empty and is never one that makes administrators of Authentik. A name Authentik already has is refused in its own words, and a name that decides a role in this app (Settings → Sign-in) is said to. Admin only; audited with who made which group. Co-Authored-By: Claude Sonnet 5.5 --- INTEGRATIONS.md | 6 +- README.md | 2 +- ROLES.md | 2 +- server/src/integrations/authentik/users.ts | 15 ++++- server/src/routes/authentik.ts | 21 +++++++ server/test/authentikGroups.test.ts | 64 +++++++++++++++++++++- web/src/api/client.ts | 1 + web/src/components/AuthentikGroupList.tsx | 51 ++++++++++++++++- web/src/pages/Authentik.tsx | 2 +- 9 files changed, 152 insertions(+), 12 deletions(-) diff --git a/INTEGRATIONS.md b/INTEGRATIONS.md index 3852e42..35ffb3c 100644 --- a/INTEGRATIONS.md +++ b/INTEGRATIONS.md @@ -530,11 +530,11 @@ osTicket's API cannot close a ticket, so this is the one place in the app that * they can no longer sign in, nothing of theirs is lost, *Switch on* brings it back) or **delete** one (a `DELETE`, for good: the user name has to be typed, and is checked again by the server against the user as Authentik has them now). **Refused, by the server, with the reason:** a service account, the account the token itself belongs to, and the last active administrator (so nobody can be locked out, or the sign-in in front of everything else cut off — for an edit, only when it would take them out of every group that makes them one); do those in Authentik. Each is in the audit log (*who edited — which fields, never their new values — switched off / on / deleted which user*). Switching off or deleting someone in Authentik does not end a session they already have in this app: end it under Users → *Signed in now*. Lists are read 200 at a time. - **Groups** on the same page lists the groups with how many are in each and lets an administrator **rename** one and **put users in and take them out** (a `PATCH` of `name` and nothing else; `POST /core/groups/{id}/add_user/` and `remove_user/`, one user each, + **Groups** on the same page lists the groups with how many are in each and lets an administrator **make** one (a name and nothing else, a `POST /core/groups/` with `is_superuser` always false: it starts empty and is never a group that makes administrators; a name Authentik already has is its own refusal), **rename** one and **put users in and take them out** (a `PATCH` of `name` and nothing else; `POST /core/groups/{id}/add_user/` and `remove_user/`, one user each, so somebody who joined meanwhile is never dropped by a whole list replacing the members). Everything asked is checked first and **nothing is changed unless all of it may be**: a service account, the token's own account, the last active administrator being taken out of the group that makes them one, and someone whose groups Authentik did not say (when taking them out of such a group) are refused with the reason. If Authentik fails part-way, the answer says how many of the changes had been made, and the audit log - (*who renamed which group, who was put in and taken out*) has what was done. Whether a group **makes its members administrators of Authentik** is shown and is **not** changed from here, and groups are not made or deleted here. A group whose name is one of the - *admin* or *operator* groups of **Settings → Sign-in** is marked *decides admins / operators here* and asks before it is saved: renaming it, or changing who is in it, changes people's roles in this app at their next sign-in. Without it nothing about the page changes for anyone but an administrator, who sees where to add one. The calls (`GET /core/groups/`, `POST /core/users/`, `POST /core/users/{id}/recovery/`, `GET /core/users/`, `GET /core/users/{id}/`, `GET /core/users/me/`, `PATCH` (`is_active`, or `name`, `email` and `groups`) and `DELETE /core/users/{id}/`, `GET /core/groups/{id}/`, `PATCH /core/groups/{id}/` and `POST /core/groups/{id}/add_user/` and `remove_user/`; asking for a link that lasts a day, which a version of + (*who renamed which group, who was put in and taken out*) has what was done. Whether a group **makes its members administrators of Authentik** is shown and is **not** changed or set from here, and groups are not deleted here. A group whose name is one of the + *admin* or *operator* groups of **Settings → Sign-in** is marked *decides admins / operators here* and asks before it is saved: renaming it, or changing who is in it, changes people's roles in this app at their next sign-in. Making a group with such a name says so too (it is empty, so nothing changes until someone is put in it). Without it nothing about the page changes for anyone but an administrator, who sees where to add one. The calls (`GET /core/groups/`, `POST /core/users/`, `POST /core/users/{id}/recovery/`, `GET /core/users/`, `GET /core/users/{id}/`, `GET /core/users/me/`, `PATCH` (`is_active`, or `name`, `email` and `groups`) and `DELETE /core/users/{id}/`, `GET /core/groups/{id}/`, `POST /core/groups/`, `PATCH /core/groups/{id}/` and `POST /core/groups/{id}/add_user/` and `remove_user/`; asking for a link that lasts a day, which a version of Authentik that does not take that sets for itself) are **not verified against a live Authentik**; the tests use a pretend one. - **What it does:** every **five minutes** Authentik is read and stored — its version (and whether a newer one is out), whether a **worker** is connected, each **outpost** (the proxy outpost that guards your apps, an LDAP one) with how many instances reported in during the last five minutes and whether they run the right version, the **certificates** (those Authentik does not renew by itself) with their expiry, the **API tokens and app passwords** that expire, and how many **sign-ins failed** and **configuration errors** happened in the last day. **Apps → Authentik** shows it, with what runs out soonest first. diff --git a/README.md b/README.md index 964d232..dd8d63d 100644 --- a/README.md +++ b/README.md @@ -572,7 +572,7 @@ quietly never made. The page shows the photo and video counts, what the library **Authentik** (Apps → Authentik). Add an Authentik integration (its address and an API token) and the app watches the sign-in in front of everything else: it raises a **critical** alert when an **outpost** that guards applications stops reporting, and warns when a **certificate** or an **API token** is about to run out (the token it reads Authentik with included), when **no worker** is connected, and when **sign-ins are failing** or flows are misconfigured. The page lists the outposts, what runs out soonest and the failed sign-ins of the last day. See INTEGRATIONS.md and docs/MONITORING.md. -An administrator can also **make a user** from that page — with a second, optional token for it — and gets a **one-time recovery link** to send them, so they choose their own password; no password is ever set or seen here, and the link is shown once and not kept. The same page lists the users and lets an administrator **edit** one (name, email, groups), **switch one off** (and on again) or **delete** one (the user name has to be typed); service accounts, the account the token belongs to and the last active administrator are refused. **Groups** can be renamed and have users put in and taken out (never made or deleted, and whether a group makes administrators is not changed here); a group that decides roles in this app is marked and asks first. +An administrator can also **make a user** from that page — with a second, optional token for it — and gets a **one-time recovery link** to send them, so they choose their own password; no password is ever set or seen here, and the link is shown once and not kept. The same page lists the users and lets an administrator **edit** one (name, email, groups), **switch one off** (and on again) or **delete** one (the user name has to be typed); service accounts, the account the token belongs to and the last active administrator are refused. **Groups** can be made (empty, and never as a group that makes administrators), renamed and have users put in and taken out (not deleted, and whether a group makes administrators is not changed here); a group that decides roles in this app is marked and asks first. **Jellyfin** (Apps → Jellyfin). Add a Jellyfin integration (its address and an API key) and the app shows whether it is up, **who is streaming what** and whether it is being transcoded, the scheduled tasks that failed, and a chart of how many watched at once; it warns when Jellyfin **wants a restart**, a **task failed** or **sign-ins are failing**. And when the Jellyfin runs on a server the app manages, **an update run asks first if people are watching**, and a patch plan **waits for them (up to two hours)** instead of restarting the machine in the middle of a film. See INTEGRATIONS.md and docs/MONITORING.md. diff --git a/ROLES.md b/ROLES.md index 3a28951..517438a 100644 --- a/ROLES.md +++ b/ROLES.md @@ -163,7 +163,7 @@ even further, to admin only: - **Immich** (Apps → Immich): everyone signed in sees the counts, the disk and the job queues; adding one (its address and API key) is an administrator's job, like any integration. - **Paperless-ngx** (Apps → Paperless): everyone signed in sees the counts, the system status and the names of the files that failed to import; adding one (its address and a superuser's token) is an administrator's job, like any integration. - **Prometheus** (Monitoring → Prometheus): everyone signed in sees the targets, what is down and the alerts firing; adding one (its address, and a token if it needs one) is an administrator's job, like any integration. -- **Authentik** (Apps → Authentik): everyone signed in sees the outposts, what runs out and the failed-sign-in count (the names of tokens and certificates, not their values); adding one (its address and API token) is an administrator's job, like any integration. **Making a user** there (and the groups to offer), **listing** the users and **editing, switching them off or on or deleting them**, and **renaming groups and changing who is in them**, are an administrator's alone, and only for an Authentik that was given a token for it; each is written in the audit log (who made, edited (which fields, not the new values), switched off, switched on or deleted which user, who renamed which group and who was put in or taken out of it, and who made a recovery link), never the link. +- **Authentik** (Apps → Authentik): everyone signed in sees the outposts, what runs out and the failed-sign-in count (the names of tokens and certificates, not their values); adding one (its address and API token) is an administrator's job, like any integration. **Making a user** there (and the groups to offer), **listing** the users and **editing, switching them off or on or deleting them**, and **making and renaming groups and changing who is in them**, are an administrator's alone, and only for an Authentik that was given a token for it; each is written in the audit log (who made, edited (which fields, not the new values), switched off, switched on or deleted which user, who made or renamed which group and who was put in or taken out of it, and who made a recovery link), never the link. - **Jellyfin** (Apps → Jellyfin): everyone signed in sees who is streaming and what is wrong; adding one (its address and API key) is an administrator's job, like any integration. Starting an update run on a server people are streaming from needs `startAnyway` — the update drawer asks (operators). - **Media managers** (Apps → Media managers, for Sonarr, Radarr and Prowlarr): everyone signed in sees what each says is wrong, its queue, disks and indexers; adding one (its API key) is an administrator's job, like any integration. Nothing on the page changes anything in them. - **App versions** (Operations → App versions): everyone signed in sees what each application runs against the newest release; switching the lookup of releases on and off, and the number of days after which a newer release is a warning, are an administrator's. diff --git a/server/src/integrations/authentik/users.ts b/server/src/integrations/authentik/users.ts index 90fe873..022306d 100644 --- a/server/src/integrations/authentik/users.ts +++ b/server/src/integrations/authentik/users.ts @@ -5,9 +5,10 @@ * Making one takes three calls: the groups to offer (`GET /core/groups/`), the user (`POST /core/users/`) and a one-time recovery link for that user (`POST /core/users/{pk}/recovery/`), which is how the * person gets to choose their own password: this app never sets, sees or keeps one. The link is handed back once and not stored. * - * Looking after groups: the groups with who is in them (`GET /core/groups/`, one `GET /core/groups/{id}/`), renaming one (`PATCH` with only `name`) and putting a user in or taking one out + * Looking after groups: the groups with who is in them (`GET /core/groups/`, one `GET /core/groups/{id}/`), making one (`POST /core/groups/` with a name and never as a group that makes administrators), + * renaming one (`PATCH` with only `name`) and putting a user in or taking one out * (`POST /core/groups/{id}/add_user/` and `remove_user/`, one user each — never a whole list of members, so someone who joined meanwhile is not dropped). Whether a group makes its members - * administrators of Authentik (`is_superuser`) is shown and not changed from here. + * administrators of Authentik (`is_superuser`) is shown, and neither changed nor set when one is made, from here. * * Looking after them: the users (`GET /core/users/`, one `GET /core/users/{pk}/`), who the token is (`GET /core/users/me/`), switching one off or on (`PATCH /core/users/{pk}/` with only `is_active`), * changing their name, email and groups (the same `PATCH`, with only what changed — never the user name, which is how a person is known elsewhere) and deleting one (`DELETE /core/users/{pk}/`). Service accounts — what an outpost or an integration signs in with — are not listed and are refused, and so are the account the token belongs to and the last @@ -209,6 +210,7 @@ export interface AuthentikUsersAdapter { listGroups(): Promise; listGroupDetails(): Promise; getGroup(id: string): Promise; + createGroup(name: string): Promise; renameGroup(id: string, name: string): Promise; addMember(id: string, userPk: number): Promise; removeMember(id: string, userPk: number): Promise; @@ -298,6 +300,13 @@ export function createAuthentikUsersAdapter(config: AuthentikUsersConfig): Authe return group; } + async function createGroup(name: string): Promise { + // Only a name, and never a group that makes administrators: that is decided in Authentik. + const group = parseGroupDetail(await call("POST", "/core/groups/", { name, is_superuser: false })); + if (!group) throw new AuthentikUserError("Authentik answered, but not with the group it made", "failed"); + return group; + } + async function renameGroup(id: string, name: string): Promise { // Only the name: a PATCH leaves out what it does not mention, so whether the group makes administrators, its members and its parent are as they were. const group = parseGroupDetail(await call("PATCH", `/core/groups/${groupId(id)}/`, { name })); @@ -333,5 +342,5 @@ export function createAuthentikUsersAdapter(config: AuthentikUsersConfig): Authe return link; } - return withDiagLogging("authentik", { listUsers, getUser, whoAmI, activeAdmins, setActive, updateUser, deleteUser, listGroupDetails, getGroup, renameGroup, addMember, removeMember, listGroups, createUser, recoveryLink }); + return withDiagLogging("authentik", { listUsers, getUser, whoAmI, activeAdmins, setActive, updateUser, deleteUser, listGroupDetails, getGroup, createGroup, renameGroup, addMember, removeMember, listGroups, createUser, recoveryLink }); } diff --git a/server/src/routes/authentik.ts b/server/src/routes/authentik.ts index 62340dc..4e28468 100644 --- a/server/src/routes/authentik.ts +++ b/server/src/routes/authentik.ts @@ -423,3 +423,24 @@ authentikRouter.patch("/:id/groups/:gid", requireRole("admin"), asyncHandler(asy sendFailure(res, err); } })); + +const newGroupSchema = z.object({ name: z.string().trim().min(1, "A group needs a name.").max(200) }); + +/** + * Makes a group: a name, nothing else — it has no members (they are put in with the editor, which asks first where a group decides roles here) and it is never one that makes administrators of + * Authentik. A name Authentik already has is its own refusal. The answer says whether the new name decides a role in this app, so the page can say what putting someone in it would mean. + */ +authentikRouter.post("/:id/groups", requireRole("admin"), asyncHandler(async (req, res) => { + const parsed = newGroupSchema.safeParse(req.body); + if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: parsed.error.issues[0]?.message ?? "That is not a group.", details: parsed.error.flatten() }); + const target = await usersAdapterFor(req.params.id, res); + if (!target) return; + try { + const group = await target.adapter.createGroup(parsed.data.name); + await recordAudit({ actor: req.currentUser!, category: "integration", action: "create_authentik_group", targetType: "authentik_group", targetId: group.id, detail: { integrationId: target.id, integration: target.name, group: group.name } }); + const settings = await getSettings(); + res.status(201).json({ group: { ...group, decidesRole: roleForGroupName(settings.signIn, group.name) } }); + } catch (err) { + sendFailure(res, err); + } +})); diff --git a/server/test/authentikGroups.test.ts b/server/test/authentikGroups.test.ts index 45dc7dc..b96da5e 100644 --- a/server/test/authentikGroups.test.ts +++ b/server/test/authentikGroups.test.ts @@ -1,5 +1,5 @@ /** - * Looking after Authentik groups: reading them with who is in them, renaming one, putting users in and taking them out — and what is refused (service accounts, the account the token belongs + * Looking after Authentik groups: reading them with who is in them, making one, renaming one, putting users in and taking them out — and what is refused (service accounts, the account the token belongs * to, the last active administrator losing that, a user whose groups Authentik did not say), that nothing is changed unless all of it may be, how far a failure got, who may, what is in the * audit log, and which groups decide roles in this app. * @@ -8,6 +8,7 @@ import { test, describe, before, after } from "node:test"; import assert from "node:assert/strict"; import { createServer as createHttpServer, type Server } from "node:http"; +import { randomUUID } from "node:crypto"; import { mkdtempSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; @@ -123,6 +124,13 @@ before(async () => { }; const url = new URL(path, "http://x"); if (req.method === "GET" && url.pathname === "/api/v3/core/groups/") return send(200, { results: groupTable }); + if (req.method === "POST" && url.pathname === "/api/v3/core/groups/") { + const b = JSON.parse(body) as { name: string; is_superuser?: boolean }; + if (groupTable.some((g) => g.name === b.name)) return send(400, { name: ["A group with that name already exists."] }); + const made: FakeGroup = { pk: randomUUID(), name: b.name, is_superuser: b.is_superuser === true, users: [] }; + groupTable.push(made); + return send(201, made); + } const grp = /^\/api\/v3\/core\/groups\/([0-9a-f-]{36})\/(add_user\/|remove_user\/)?$/.exec(url.pathname); if (grp) { const group = groupTable.find((g) => g.pk === grp[1]); @@ -189,6 +197,17 @@ describe("the calls", () => { assert.equal(seen[0].auth, "Bearer write-tok"); }); + test("a group is made with a name and as one that does not make administrators — whatever else is asked of the adapter, only that is sent", async () => { + reset(); + const made = await adapter().createGroup("Gamers"); + assert.deepEqual([made.name, made.admin, made.members], ["Gamers", false, []]); + assert.deepEqual([seen[0].method, seen[0].path, seen[0].body], ["POST", "/api/v3/core/groups/", JSON.stringify({ name: "Gamers", is_superuser: false })]); + await assert.rejects( + () => adapter().createGroup("Gamers"), + (err: Error & { kind?: string }) => err.kind === "invalid" && /name: A group with that name already exists\./.test(err.message), + ); + }); + test("renaming is a PATCH of the name and nothing else; a member goes in or out with a POST of that one user", async () => { reset(); const renamed = await adapter().renameGroup(G_FAMILY, "Household"); @@ -221,6 +240,7 @@ describe("the routes", () => { const as = (sub: string) => ({ "content-type": "application/json", "x-sub": sub }); const details = (sub = "admin") => fetch(`${base}/${id}/group-details`, { headers: as(sub) }); const change = (gid: string, body: unknown, sub = "admin") => fetch(`${base}/${id}/groups/${gid}`, { method: "PATCH", headers: as(sub), body: JSON.stringify(body) }); + const make = (body: unknown, sub = "admin") => fetch(`${base}/${id}/groups`, { method: "POST", headers: as(sub), body: JSON.stringify(body) }); const writes = () => seen.filter((s) => s.method !== "GET"); const audit = async (action: string) => (await db.select().from(auditLog)).filter((e) => e.action === action); const refused = async (res: Response, pattern: RegExp) => { @@ -378,12 +398,54 @@ describe("the routes", () => { assert.match(((await (await change(G_OTHER, { membersAdd: [4] })).json()) as { message: string }).message, /0 of 1 changes had been made/); }); + test("making a group: admin only; it is made empty and never as an administrators group, and the audit log says who made which", async () => { + reset(); + for (const sub of ["viewer", "operator"]) assert.equal((await make({ name: "Gamers" }, sub)).status, 403, sub); + assert.deepEqual(seen, []); + const res = await make({ name: " Gamers " }); + assert.equal(res.status, 201); + const body = (await res.json()) as { group: { id: string; name: string; admin: boolean; members: number[]; decidesRole: string | null } }; + assert.deepEqual([body.group.name, body.group.admin, body.group.members, body.group.decidesRole], ["Gamers", false, [], null]); + assert.deepEqual(writes().map((s) => [s.method, s.path, s.body]), [["POST", "/api/v3/core/groups/", JSON.stringify({ name: "Gamers", is_superuser: false })]]); + assert.equal(groupTable.some((g) => g.name === "Gamers" && !g.is_superuser), true); + const [entry] = await audit("create_authentik_group"); + assert.deepEqual([entry.category, entry.targetType, entry.targetId], ["integration", "authentik_group", body.group.id]); + assert.deepEqual(JSON.parse(entry.detail ?? "{}"), { integrationId: id, integration: "Front door", group: "Gamers" }); + }); + + test("a new group whose name decides a role here is said to; a name that is taken is Authentik's own words", async () => { + reset(); + const res = await make({ name: "Ops" }); + assert.equal(res.status, 201); + assert.equal(((await res.json()) as { group: { decidesRole: string | null } }).group.decidesRole, null); + const mapped = await make({ name: "ADMINS-2" }); + assert.equal(((await mapped.json()) as { group: { decidesRole: string | null } }).group.decidesRole, null, "only the names in Settings → Sign-in"); + await updateSettings({ signIn: { roleFromGroups: true, groupsClaim: "groups", adminGroups: ["admins", "Root Team"], operatorGroups: ["family"], otherwise: "viewer" } }); + const root = await make({ name: "root team" }); + assert.equal(((await root.json()) as { group: { decidesRole: string | null } }).group.decidesRole, "admin", "compared the way sign-in compares"); + seen.length = 0; + const dup = await make({ name: "Family" }); + assert.equal(dup.status, 400); + assert.match(((await dup.json()) as { message: string }).message, /name: A group with that name already exists/); + }); + + test("what is wrong with a new group is said before Authentik is asked", async () => { + reset(); + for (const bad of [{}, { name: "" }, { name: " " }, { name: "x".repeat(201) }, { name: 5 }]) { + const res = await make(bad); + assert.equal(res.status, 400, JSON.stringify(bad)); + assert.equal(typeof ((await res.json()) as { message: string }).message, "string"); + } + assert.deepEqual(seen, []); + }); + test("a group that is gone is not found; an Authentik with no token for managing users is not asked anything", async () => { reset(); assert.equal((await change("99999999-9999-4999-8999-999999999999", { name: "x" })).status, 404); seen.length = 0; assert.equal((await fetch(`${base}/${readOnly}/group-details`, { headers: as("admin") })).status, 400); assert.equal((await fetch(`${base}/${readOnly}/groups/${G_FAMILY}`, { method: "PATCH", headers: as("admin"), body: JSON.stringify({ name: "x" }) })).status, 400); + assert.equal((await fetch(`${base}/${readOnly}/groups`, { method: "POST", headers: as("admin"), body: JSON.stringify({ name: "x" }) })).status, 400); assert.deepEqual(seen, []); }); }); diff --git a/web/src/api/client.ts b/web/src/api/client.ts index 891098e..68d4eeb 100644 --- a/web/src/api/client.ts +++ b/web/src/api/client.ts @@ -3444,6 +3444,7 @@ export const api = { users: (id: number, search = "") => request<{ users: AuthentikPerson[]; more: boolean; self: number | null }>(`/api/authentik/${id}/users${search.trim() ? `?search=${encodeURIComponent(search.trim())}` : ""}`), setUserActive: (id: number, pk: number, active: boolean) => request<{ user: AuthentikPerson }>(`/api/authentik/${id}/users/${pk}/active`, { method: "POST", body: JSON.stringify({ active }) }), groupDetails: (id: number) => request<{ groups: AuthentikGroupDetail[]; people: AuthentikGroupPerson[]; more: boolean; self: number | null }>(`/api/authentik/${id}/group-details`), + createGroup: (id: number, name: string) => request<{ group: AuthentikGroupDetail }>(`/api/authentik/${id}/groups`, { method: "POST", body: JSON.stringify({ name }) }), updateGroup: (id: number, gid: string, body: { name?: string; membersAdd?: number[]; membersRemove?: number[] }) => request<{ changed: string[]; added: number; removed: number }>(`/api/authentik/${id}/groups/${gid}`, { method: "PATCH", body: JSON.stringify(body) }), updateUser: (id: number, pk: number, body: { name?: string; email?: string; groupsAdd?: string[]; groupsRemove?: string[] }) => request<{ user: AuthentikPerson; changed: string[] }>(`/api/authentik/${id}/users/${pk}`, { method: "PATCH", body: JSON.stringify(body) }), deleteUser: (id: number, pk: number, username: string) => request(`/api/authentik/${id}/users/${pk}`, { method: "DELETE", body: JSON.stringify({ username }) }), diff --git a/web/src/components/AuthentikGroupList.tsx b/web/src/components/AuthentikGroupList.tsx index e25be37..8902cd4 100644 --- a/web/src/components/AuthentikGroupList.tsx +++ b/web/src/components/AuthentikGroupList.tsx @@ -74,7 +74,8 @@ function EditGroup({ g, people, self, busy, onSave, onCancel }: { g: AuthentikGr } /** - * The groups of an Authentik, for an administrator to rename and to put users in and take them out of. Whether a group makes its members administrators is shown, not changed. A group that + * The groups of an Authentik, for an administrator to make, rename and to put users in and take them out of. Whether a group makes its members administrators is shown, not changed — and a group + * made here never does. A group that * decides somebody's role in this app says so, and asks before it is changed. */ export default function AuthentikGroupList({ a }: { a: AuthentikInfo }) { @@ -85,9 +86,32 @@ export default function AuthentikGroupList({ a }: { a: AuthentikInfo }) { const [busy, setBusy] = useState(null); const [error, setError] = useState(null); const [notice, setNotice] = useState(null); + const [creating, setCreating] = useState(false); + const [newName, setNewName] = useState(""); if (!a.canCreateUsers) return null; + async function create(e: FormEvent) { + e.preventDefault(); + if (busy !== null) return; + setBusy("new"); + setError(null); + setNotice(null); + try { + const { group } = await api.authentik.createGroup(a.id, newName.trim()); + setCreating(false); + setNewName(""); + setNotice( + `Made "${group.name}", with no members.${group.decidesRole ? ` Its name decides who is ${group.decidesRole === "admin" ? "an administrator" : "an operator"} here (Settings → Sign-in): whoever is put in it gets that role at their next sign-in.` : ""}`, + ); + if (groups !== null) await load(); + else setBusy(null); + } catch (err) { + setError(readableError(err)); + setBusy(null); + } + } + async function load() { setBusy("list"); setError(null); @@ -132,8 +156,31 @@ export default function AuthentikGroupList({ a }: { a: AuthentikInfo }) {

Groups

+ {creating ? ( +
+
+ + setNewName(e.target.value)} /> +
It starts with no members — put them in with Edit — and it does not make its members administrators of Authentik; that is decided in Authentik.
+
+ + +
+
+
+ ) : ( + + )} {groups === null ? ( - ) : ( diff --git a/web/src/pages/Authentik.tsx b/web/src/pages/Authentik.tsx index 09bcea0..f0f0099 100644 --- a/web/src/pages/Authentik.tsx +++ b/web/src/pages/Authentik.tsx @@ -162,7 +162,7 @@ export default function Authentik({ user }: { user: CurrentUser }) {

Authentik

The sign-in in front of everything else. It is read every few minutes with an API token (see Integrations). An outpost that goes quiet (the apps it guards stop letting anyone in), a certificate or an{" "} - API token that is about to run out, no worker and a burst of failed sign-ins are alerts — see Alerts.{user.role === "admin" && " An administrator can also make a user here, with a one-time link for them to choose a password, and switch users off or delete them, and rename groups and change who is in them."} + API token that is about to run out, no worker and a burst of failed sign-ins are alerts — see Alerts.{user.role === "admin" && " An administrator can also make a user here, with a one-time link for them to choose a password, and switch users off or delete them, and make and rename groups and change who is in them."}

{!data && !error && }