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`.
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.
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.
_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.
_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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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_keysisNonewhen 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=Falseremoves 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
sudo -n -u <name>), never as root. A link in a home the person owns may point anywhere. Root only askstest -e.<SUDOERS_DIR>/80-account-<name>,<name> ALL=(ALL) ALL).visudo -cfchecks it before install, andsudo -l -Uchecks afterwards that it took effect. A rule elsewhere, such as cloud-init's90-cloud-init-users, is reported and not edited. When the account is locked, that report is a note and not a failure.ACCOUNT_MIN_UID), invalid names, keys that are not one OpenSSH public key, and hashes not inACCOUNT_PASSWORD_SCHEME._account_create/_account_open/_account_lock/_account_locked/_account_leave_groupand 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._rootdid collide with the drivers' "is root" cache.Tests
tests/test_local_accounts.pyruns against a fake host that keeps accounts, groups, rules and files: 54 tests, the module at 96 % coverage.Merge this first: napalm-linux, napalm-bsd, napalm-openmediavault and napalm-qnap-qts pre-install device-types from
main.Two follow-up commits for NAPALM/napalm-openmediavault#12:
_account_add_key/_account_remove_keys/_account_read_keysare now hooks with the~/.sshdefault. 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 intest_local_accounts.py, full suite 949 green. Verified with real drivers on Debian 13, Rocky 9, FreeBSD 15.1 and OMV 8.