feat: personal accounts with shadow-utils, locked by expiry (NetOrk/netork#1793) #50

Merged
christianmanivong merged 3 commits from feat/local-accounts into main 2026-10-31 23:51:04 +00:00
Owner

Part of NetOrk/netork#1793. LinuxDriver mixes in napalm-device-types' LocalAccountsMixin (NAPALM/napalm-device-types, branch feat/local-accounts), which needs to be merged first. Until then CI pre-installs device-types main and stays red.

Commands

  • Create: useradd -m -s /bin/bash [-p <hash>] <name>.
  • Lock: usermod -L -e 1 <name>. A locked account is an expired one, because PAM's account check then refuses a key login too. A ! in front of the password (usermod -L alone) stops only the password.
  • Open again: usermod -e '' [-p <hash>|-U] <name>. This lifts the expiry and gives the old password back. An account that never had a password stays key-only, since usermod -U would refuse it.
  • Lock state: getent shadow <name> as root. Only the expiry field is looked at.
  • Leave a group: gpasswd -d <name> <group>. Admin groups: sudo, wheel, admin.

Verified

Debian 13 and Rocky Linux 9 containers with sshd and sudo:

  • add with sudo: key login works, and sudo takes the person's password
  • lock: key login is refused (ssh 255), the keys are gone, sudo is gone
  • reopen without sudo: key login works, sudo is refused
  • a cloud-init style rule in 90-cloud-init-users is reported
  • an account in sudo or wheel (as cloud-init makes it) leaves the group

OpenMediaVault and QNAP inherit LinuxDriver. OMV builds its own variant on it (NAPALM/napalm-openmediavault#12: setUser, _ssh, OMV's key store), and QNAP opts out (NAPALM/napalm-qnap-qts#15).

Part of NetOrk/netork#1793. `LinuxDriver` mixes in napalm-device-types' `LocalAccountsMixin` (NAPALM/napalm-device-types, branch `feat/local-accounts`), which needs to be merged first. Until then CI pre-installs device-types `main` and stays red. ## Commands - Create: `useradd -m -s /bin/bash [-p <hash>] <name>`. - Lock: `usermod -L -e 1 <name>`. A locked account is an **expired** one, because PAM's account check then refuses a key login too. A `!` in front of the password (`usermod -L` alone) stops only the password. - Open again: `usermod -e '' [-p <hash>|-U] <name>`. This lifts the expiry and gives the old password back. An account that never had a password stays key-only, since `usermod -U` would refuse it. - Lock state: `getent shadow <name>` as root. Only the expiry field is looked at. - Leave a group: `gpasswd -d <name> <group>`. Admin groups: `sudo`, `wheel`, `admin`. ## Verified Debian 13 and Rocky Linux 9 containers with sshd and sudo: - add with sudo: key login works, and `sudo` takes the person's password - lock: key login is refused (ssh 255), the keys are gone, sudo is gone - reopen without sudo: key login works, sudo is refused - a cloud-init style rule in `90-cloud-init-users` is reported - an account in `sudo` or `wheel` (as cloud-init makes it) leaves the group OpenMediaVault and QNAP inherit `LinuxDriver`. OMV builds its own variant on it (NAPALM/napalm-openmediavault#12: `setUser`, `_ssh`, OMV's key store), and QNAP opts out (NAPALM/napalm-qnap-qts#15).
christianmanivong added 1 commit 2026-10-31 22:25:03 +00:00
feat: personal accounts with shadow-utils, locked by expiry (NetOrk/netork#1793)
driver / standard (pull_request) Failing after 17s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Failing after 1m17s
driver / test (3.12) (pull_request) Failing after 1m19s
driver / test (3.13) (pull_request) Failing after 1m7s
driver / lowest (pull_request) Failing after 41s
driver / build (pull_request) Successful in 42s
driver / security (pull_request) Successful in 1m29s
CI / driver (pull_request) Failing after 3m19s
driver / publish (pull_request) Skipped
c5be71adac
LinuxDriver mixes in napalm-device-types' LocalAccountsMixin with
useradd -m -s /bin/bash, usermod and gpasswd -d. A locked account is an
expired one (usermod -L -e 1): PAM refuses it a key login too, where a
"!" in front of the password stops only the password. Opening it again
lifts the expiry and gives the old password back.

Checked on Debian 13 and Rocky Linux 9 containers with sshd and sudo:
key login works after adding, is refused after locking and works again
after reopening; the sudo rule takes effect with the person's password;
membership of sudo/wheel goes when sudo is not wanted.
christianmanivong added 2 commits 2026-10-31 23:48:03 +00:00
# Conflicts:
#	CHANGELOG.md
refactor: the interactive shell's end-of-output pattern lives in _shell (quality ratchet)
driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Successful in 1m15s
driver / test (3.12) (pull_request) Successful in 1m19s
driver / test (3.13) (pull_request) Successful in 1m11s
driver / lowest (pull_request) Successful in 35s
driver / build (pull_request) Successful in 37s
driver / security (pull_request) Successful in 1m19s
CI / driver (pull_request) Successful in 3m5s
driver / publish (pull_request) Skipped
448eeec0fa
expect_for and STATUS_ECHO_RE say when netmiko's interactive shell has
finished printing a command's output, next to PROMPT_RE they build on.
Moving them out keeps linux.py within its line count now that it mixes in
the personal accounts; the baseline goes down to 2265.
christianmanivong merged commit b702fa5125 into main 2026-10-31 23:51:04 +00:00
christianmanivong deleted branch feat/local-accounts 2026-10-31 23:51:04 +00:00
Sign in to join this conversation.