feat: LocalAccountsMixin, personal accounts added and locked again (NetOrk/netork#1793) #62

Merged
christianmanivong merged 4 commits from feat/local-accounts into main 2026-10-31 23:45:35 +00:00
Owner

Part of NetOrk/netork#1793: give people an account of their own on hosts netOrk already manages, and take it away again when they leave.

What it does

  • get_local_accounts(names) reads the named accounts back: uid, home, shell, groups, whether the account is locked, whether sudo lets it run everything, and the lines of its key files. A missing account is left out. A read that fails raises instead of returning nothing. authorized_keys is None when it cannot be read.
  • add_local_account(name, public_key, password_hash=None, admin=False) creates the account, or opens it again. An existing account keeps its other keys. The call is declarative: admin=False removes the sudo rule and the admin groups.
  • lock_local_account(name) removes the keys, refuses every login and removes sudo. The home stays. All three steps run even when an earlier one failed, because the lock matters most.

How

  • Every command root runs is one fixed command (argv, no shell syntax), so it fits the planned sudoers allowlist for netOrk's own user. A test checks this.
  • The key files are read and written as the person (sudo -n -u <name>), never as root. A link in a home the person owns may point anywhere. Root only asks test -e.
  • The sudo rule is a drop-in of its own (<SUDOERS_DIR>/80-account-<name>, <name> ALL=(ALL) ALL). visudo -cf checks it before install, and sudo -l -U checks afterwards that it took effect. A rule elsewhere, such as cloud-init's 90-cloud-init-users, is reported and not edited. When the account is locked, that report is a note and not a failure.
  • Refused: the login user's own account, system accounts (uid < ACCOUNT_MIN_UID), invalid names, keys that are not one OpenSSH public key, and hashes not in ACCOUNT_PASSWORD_SCHEME.
  • A driver supplies _account_create / _account_open / _account_lock / _account_locked / _account_leave_group and the class attributes (shell, admin groups, sudoers dir, root group, password scheme). The private helpers are prefixed _accounts_ so they cannot collide with a driver's own attributes. _root did collide with the drivers' "is root" cache.

Tests

  • tests/test_local_accounts.py runs against a fake host that keeps accounts, groups, rules and files: 54 tests, the module at 96 % coverage.
  • With napalm-linux, verified for real in Debian 13 and Rocky Linux 9 containers with sshd. The key login works after adding, is refused after locking, and works again after reopening. The sudo rule takes effect with the person's password.

Merge this first: napalm-linux, napalm-bsd, napalm-openmediavault and napalm-qnap-qts pre-install device-types from main.

Part of NetOrk/netork#1793: give people an account of their own on hosts netOrk already manages, and take it away again when they leave. ## What it does - `get_local_accounts(names)` reads the named accounts back: uid, home, shell, groups, whether the account is locked, whether sudo lets it run everything, and the lines of its key files. A missing account is left out. A read that fails raises instead of returning nothing. `authorized_keys` is `None` when it cannot be read. - `add_local_account(name, public_key, password_hash=None, admin=False)` creates the account, or opens it again. An existing account keeps its other keys. The call is declarative: `admin=False` removes the sudo rule and the admin groups. - `lock_local_account(name)` removes the keys, refuses every login and removes sudo. The home stays. All three steps run even when an earlier one failed, because the lock matters most. ## How - **Every command root runs is one fixed command** (argv, no shell syntax), so it fits the planned sudoers allowlist for netOrk's own user. A test checks this. - **The key files are read and written as the person** (`sudo -n -u <name>`), never as root. A link in a home the person owns may point anywhere. Root only asks `test -e`. - **The sudo rule is a drop-in of its own** (`<SUDOERS_DIR>/80-account-<name>`, `<name> ALL=(ALL) ALL`). `visudo -cf` checks it before install, and `sudo -l -U` checks afterwards that it took effect. A rule elsewhere, such as cloud-init's `90-cloud-init-users`, is reported and not edited. When the account is locked, that report is a note and not a failure. - **Refused:** the login user's own account, system accounts (uid < `ACCOUNT_MIN_UID`), invalid names, keys that are not one OpenSSH public key, and hashes not in `ACCOUNT_PASSWORD_SCHEME`. - A driver supplies `_account_create` / `_account_open` / `_account_lock` / `_account_locked` / `_account_leave_group` and the class attributes (shell, admin groups, sudoers dir, root group, password scheme). The private helpers are prefixed `_accounts_` so they cannot collide with a driver's own attributes. `_root` did collide with the drivers' "is root" cache. ## Tests - `tests/test_local_accounts.py` runs against a fake host that keeps accounts, groups, rules and files: 54 tests, the module at 96 % coverage. - With napalm-linux, verified for real in Debian 13 and Rocky Linux 9 containers with sshd. The key login works after adding, is refused after locking, and works again after reopening. The sudo rule takes effect with the person's password. Merge this first: napalm-linux, napalm-bsd, napalm-openmediavault and napalm-qnap-qts pre-install device-types from `main`.
christianmanivong added 1 commit 2026-10-31 22:25:03 +00:00
feat: LocalAccountsMixin, personal accounts added and locked again (NetOrk/netork#1793)
driver / standard (pull_request) Successful in 25s
driver / lint (pull_request) Successful in 30s
driver / types (pull_request) Successful in 1m36s
driver / test (3.13) (pull_request) Successful in 1m15s
driver / test (3.12) (pull_request) Successful in 1m41s
driver / lowest (pull_request) Successful in 46s
driver / build (pull_request) Successful in 36s
driver / security (pull_request) Successful in 1m21s
CI / driver (pull_request) Successful in 3m6s
driver / publish (pull_request) Skipped
49c65cbd5d
get_local_accounts(names) reads a person's account back: groups, lock,
sudo, key files. add_local_account() creates or reopens one with the
person's key, optional password hash and optional sudo rule;
lock_local_account() takes the keys and sudo away and refuses every
login, keeping the home.

Every command root runs is one fixed command, so a sudoers allowlist can
name it. The key files are read and written as the person (sudo -n -u),
never as root, since a link in a home the person owns may point anywhere.
The sudo rule is a drop-in of its own, checked with visudo before and
sudo -l after; a rule elsewhere (cloud-init's) is reported, not edited.
The login user's own account and system accounts are refused.

A driver supplies creating, opening, locking, reading the lock and
leaving a group.
christianmanivong added 1 commit 2026-10-31 22:29:46 +00:00
feat: a driver may keep the account keys elsewhere (NetOrk/netork#1793)
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Successful in 1m6s
driver / test (3.13) (pull_request) Successful in 1m8s
driver / test (3.12) (pull_request) Successful in 1m14s
driver / lowest (pull_request) Successful in 36s
driver / build (pull_request) Successful in 34s
driver / security (pull_request) Successful in 1m9s
CI / driver (pull_request) Successful in 2m44s
driver / publish (pull_request) Skipped
0545d1d814
OpenMediaVault keeps a user's keys in its own database and deploys them
to /var/lib/openmediavault/ssh/authorized_keys, and creates a home only
when its home directory setting is on. The key store becomes three hooks
with the ~/.ssh default: _account_read_keys, _account_add_key and
_account_remove_keys, each given the account's home.
christianmanivong added 1 commit 2026-10-31 22:31:05 +00:00
feat: a host may add a key file sshd reads (NetOrk/netork#1793)
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 1m6s
driver / test (3.12) (pull_request) Successful in 1m14s
driver / lowest (pull_request) Successful in 39s
driver / test (3.13) (pull_request) Successful in 1m23s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m5s
CI / driver (pull_request) Successful in 2m45s
driver / publish (pull_request) Skipped
2846824a21
_account_key_files says which files hold an account's keys; the default is
~/.ssh/authorized_keys and authorized_keys2. OpenMediaVault adds the file it
deploys under /var/lib/openmediavault/ssh/authorized_keys, so reading an
account back sees every key sshd would take.
Author
Owner

Two follow-up commits for NAPALM/napalm-openmediavault#12:

  • _account_add_key / _account_remove_keys / _account_read_keys are now hooks with the ~/.ssh default. A driver whose host keeps keys elsewhere (OMV's database) replaces them.
  • _account_key_files(name, home) lists every file sshd reads. OMV adds /var/lib/openmediavault/ssh/authorized_keys/<user>, so reading an account back sees every key sshd would take.

The convention, documented in the class: _account_* hooks belong to the driver, _accounts_* helpers are the mixin's own. Tests: 57 in test_local_accounts.py, full suite 949 green. Verified with real drivers on Debian 13, Rocky 9, FreeBSD 15.1 and OMV 8.

Two follow-up commits for NAPALM/napalm-openmediavault#12: - `_account_add_key` / `_account_remove_keys` / `_account_read_keys` are now hooks with the `~/.ssh` default. A driver whose host keeps keys elsewhere (OMV's database) replaces them. - `_account_key_files(name, home)` lists every file sshd reads. OMV adds `/var/lib/openmediavault/ssh/authorized_keys/<user>`, so reading an account back sees every key sshd would take. The convention, documented in the class: `_account_*` hooks belong to the driver, `_accounts_*` helpers are the mixin's own. Tests: 57 in `test_local_accounts.py`, full suite 949 green. Verified with real drivers on Debian 13, Rocky 9, FreeBSD 15.1 and OMV 8.
christianmanivong added 1 commit 2026-10-31 23:45:07 +00:00
Merge remote-tracking branch 'origin/main' into feat/local-accounts
driver / standard (pull_request) Failing after 18s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Successful in 59s
driver / test (3.12) (pull_request) Successful in 1m7s
driver / lowest (pull_request) Successful in 31s
driver / test (3.13) (pull_request) Successful in 58s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 59s
CI / driver (pull_request) Failing after 2m35s
driver / publish (pull_request) Skipped
9159106837
# Conflicts:
#	CHANGELOG.md
christianmanivong merged commit 1c71fe6896 into main 2026-10-31 23:45:35 +00:00
christianmanivong deleted branch feat/local-accounts 2026-10-31 23:45:35 +00:00
Sign in to join this conversation.