From ff0c93ed739f178b8dbeaa49996f96635fcddb4d Mon Sep 17 00:00:00 2001 From: Slawomir Koszewski Date: Sun, 22 Nov 2026 19:48:02 +0100 Subject: [PATCH] fix: the webui does not allow to disable the last admin now. --- ADR.md | 2 ++ README.md | 4 ++-- debian-package/debian/changelog | 4 ++++ .../src/usr/lib/linux-manager/linuxmanager_users.py | 10 +++++++++- docs/users.md | 4 +++- web/src/GroupsPanel.tsx | 7 +++++-- web/src/ServiceAccountsPanel.tsx | 7 +++++-- web/src/SiteFiles.tsx | 7 +++++-- web/src/SitesPanel.tsx | 7 +++++-- web/src/UsersPanel.tsx | 9 ++++++--- 10 files changed, 46 insertions(+), 15 deletions(-) diff --git a/ADR.md b/ADR.md index 5684be6..485d5be 100644 --- a/ADR.md +++ b/ADR.md @@ -327,6 +327,8 @@ creation, without a maximum, signed with the server's key; `/auth` never issues admin token may call everything, and only an admin token may change `admins`: create it, rename a group to it, change or remove it, add or take out its members, or remove a user who is a member of it. The first member is added with `linux-manager-group` on the server, which acts as root. +The last enabled member of `admins` is not disabled, through the API or `linux-manager-user`, so +an administrator who can sign in remains; another member is enabled or added first. Consequences: Removing a user from `admins` takes effect at the next request, without waiting for the user's tokens to expire. Membership of `admins` changes only through root on the server. diff --git a/README.md b/README.md index 5b848e0..9440504 100644 --- a/README.md +++ b/README.md @@ -752,7 +752,7 @@ linux-manager-user otp-remove alice | `update [--first-name F] [--last-name L] [--email E]` | Changes the names or the e-mail address | | `update [--display-name N] [--description D] [--email E] [--redirect-uri U ...] [--post-logout-redirect-uri U ...] [--allowed-group G ...] [--grant G ...] [--public-client yes\|no] [--client-scope R:S ...] [--resource-scope S ...]` | Changes the display name, the description, the e-mail address or the OpenID Provider settings of a service account; `''` removes one; a repeated option gives all values of its kind | | `passwd ` | Sets the password | -| `disable `, `enable ` | Locks the user out of OpenVPN and `/auth`, and lets the user in again | +| `disable `, `enable ` | Locks the user out of OpenVPN and `/auth`, and lets the user in again; the last enabled member of `admins` is not disabled | | `unlock ` | Ends a lockout after failed logins and clears the failure count; a disabled user stays disabled | | `remove ` | Takes the user out of its groups, revokes the certificate, renews the CRL and removes the user; refused while the user is the last member of a group | | `profile ` | The OpenVPN client profile, with the CA, the certificate and the key inline | @@ -1253,7 +1253,7 @@ and answer bodies are JSON; a request body is at most 65536 bytes. | `POST /users` | `{"name", "password", "first_name", "last_name", "email"}` for a VPN user; `{"name", "password", "email"?}` for a Manager-only account | 201 and the user | | `PUT /users/` | any of `{"first_name", "last_name", "email", "wireguard_peers"}`; `wireguard_peers`, `[{"public_key", "ips"}]`, replaces a VPN user's WireGuard peers (see Configuration); for a Manager-only account only `{"email"}`, `""` removing it | the user | | `PUT /users//password` | `{"password": ...}` | the user | -| `POST /users//disable` | | the user | +| `POST /users//disable` | | the user; 409 for the last enabled member of `admins` | | `POST /users//enable` | | the user | | `POST /users//unlock` | | the user | | `DELETE /users/` | | `{"name", "removed": true}` | diff --git a/debian-package/debian/changelog b/debian-package/debian/changelog index dd8dc3c..753481d 100644 --- a/debian-package/debian/changelog +++ b/debian-package/debian/changelog @@ -45,6 +45,10 @@ linux-manager (0.41.0-1) unstable; urgency=medium * The examples switch the router and the VPN on. * A NAT rule that the configuration no longer needs is removed from the running firewall at once, not only at the next boot. + * The last enabled member of admins can no longer be disabled, through + the API, the Manager or linux-manager-user (409, status 4). + * The Users, Groups, Service accounts, Web Sites and Files pages keep a + refused change's message above the list after they read it again. * tests/remote/run.py tests the components on Ubuntu 26.04 instances of an LXD remote, and tests/remote/vm.py starts and removes one server VM there to work with, reached through ports 7080, 7081 and 2222 (SSH) diff --git a/debian-package/src/usr/lib/linux-manager/linuxmanager_users.py b/debian-package/src/usr/lib/linux-manager/linuxmanager_users.py index 428ec71..f427077 100644 --- a/debian-package/src/usr/lib/linux-manager/linuxmanager_users.py +++ b/debian-package/src/usr/lib/linux-manager/linuxmanager_users.py @@ -765,9 +765,17 @@ def passwd(connection, name, password): def disable(connection, name): - """Lock the user out; the WireGuard peers of a disabled user are left out of wg0.conf.""" + """Lock the user out; the WireGuard peers of a disabled user are left out of wg0.conf. + + The last enabled member of admins is not disabled, so the server keeps an administrator who can sign in; + Failure with status 4. + """ current = entry(connection, name) if current.get('pwdAccountLockedTime') != [LOCKED]: + admins = groups_of(connection, name).get(ADMIN_GROUP) + if admins is not None and not any(entry(connection, member).get('pwdAccountLockedTime') != [LOCKED] + for member in admins if member != name): + raise Failure(f'{name} is the last enabled member of {ADMIN_GROUP} and cannot be disabled', 4) connection.modify_s(dn_of(name), [(ldap.MOD_REPLACE, 'pwdAccountLockedTime', [LOCKED])]) if 'linuxManagerWireGuardPeer' in current: apply_wireguard() diff --git a/docs/users.md b/docs/users.md index cff7470..0da86c9 100644 --- a/docs/users.md +++ b/docs/users.md @@ -22,7 +22,9 @@ The users of the server's directory, without the [service accounts](service-acco - **Add:** a VPN user, or with Manager access only a Manager-only account. - **Edit:** the names and the e-mail address of a VPN user, the e-mail address of a Manager-only account. -- **Password**, **Disable**, **Enable**, **Unlock** after failed logins, and **Remove**. +- **Password**, **Disable**, **Enable**, **Unlock** after failed logins, and **Remove**. The last + enabled member of `admins` cannot be disabled, so the server keeps an administrator who can sign + in. - **Profile:** downloads the OpenVPN client profile, while the server runs OpenVPN. - **Apple VPN profile** (Apple icon): downloads a `.mobileconfig` that sets up the server's IKEv2 VPN on a Mac, iPhone or iPad, while the server runs IKEv2. The password you type protects the diff --git a/web/src/GroupsPanel.tsx b/web/src/GroupsPanel.tsx index 93ed099..2e56bb2 100644 --- a/web/src/GroupsPanel.tsx +++ b/web/src/GroupsPanel.tsx @@ -58,13 +58,16 @@ export default function GroupsPanel() { /** Runs a change of a group, then reads the list again; a failure is shown above the list. */ async function change(work: () => Promise) { setBusy(true) + let failure: string | null = null try { await work() - setError(null) } catch (caught) { - setError((caught as Error).message) + failure = (caught as Error).message } await refresh() + if (failure !== null) { + setError(failure) + } } function remove(group: Group) { diff --git a/web/src/ServiceAccountsPanel.tsx b/web/src/ServiceAccountsPanel.tsx index e00acca..66c2cf9 100644 --- a/web/src/ServiceAccountsPanel.tsx +++ b/web/src/ServiceAccountsPanel.tsx @@ -95,13 +95,16 @@ export default function ServiceAccountsPanel() { /** Runs a change of an account, then reads the list again; a failure is shown above the list. */ async function change(work: () => Promise) { setBusy(true) + let failure: string | null = null try { await work() - setError(null) } catch (caught) { - setError((caught as Error).message) + failure = (caught as Error).message } await refresh() + if (failure !== null) { + setError(failure) + } } function remove(account: User) { diff --git a/web/src/SiteFiles.tsx b/web/src/SiteFiles.tsx index ddab73f..c8d3b4c 100644 --- a/web/src/SiteFiles.tsx +++ b/web/src/SiteFiles.tsx @@ -114,13 +114,16 @@ export default function SiteFiles(props: { site: string | null; onSite: (name: s /** Runs a change of the files, then reads the folder again; a failure is shown above the list. */ async function change(work: () => Promise) { setBusy(true) + let failure: string | null = null try { await work() - setError(null) } catch (caught) { - setError((caught as Error).message) + failure = (caught as Error).message } await refresh() + if (failure !== null) { + setError(failure) + } } /** Uploads the files one after the other into the folder shown, a zip archive extracted there while extract is on. */ diff --git a/web/src/SitesPanel.tsx b/web/src/SitesPanel.tsx index 15527ee..299c9be 100644 --- a/web/src/SitesPanel.tsx +++ b/web/src/SitesPanel.tsx @@ -79,13 +79,16 @@ export default function SitesPanel(props: { onOpenFiles: (name: string) => void /** Runs a change of a site, then reads the list again; a failure is shown above the list. */ async function change(work: () => Promise) { setBusy(true) + let failure: string | null = null try { await work() - setError(null) } catch (caught) { - setError((caught as Error).message) + failure = (caught as Error).message } await refresh() + if (failure !== null) { + setError(failure) + } } function remove(site: Site) { diff --git a/web/src/UsersPanel.tsx b/web/src/UsersPanel.tsx index aa272e5..0ab9f9b 100644 --- a/web/src/UsersPanel.tsx +++ b/web/src/UsersPanel.tsx @@ -97,16 +97,19 @@ export default function UsersPanel() { void refresh() }, [refresh]) - /** Runs a change of a user, then reads the list again; a failure is shown above the list. */ + /** Runs a change of a user, then reads the list again; a failure is shown above the list after the reading. */ async function change(work: () => Promise) { setBusy(true) + let failure: string | null = null try { await work() - setError(null) } catch (caught) { - setError((caught as Error).message) + failure = (caught as Error).message } await refresh() + if (failure !== null) { + setError(failure) + } } async function download(name: string) {