Personal accounts on Linux now follow what the person changes. See NetOrk/netork#2013.
Needs the napalm-device-types release first (NAPALM/napalm-device-types#90, assumed to be 4.28.0). The floor is raised to napalm-device-types>=4.28.0. CI pre-installs device-types from git main, so this PR goes green once #90 is merged.
Replace a key (add_local_account(..., replaces=[...])) and remove keys (remove_local_account_keys) use the mixin's key-file implementation. As the person (sudo -n -u <name>), it reads ~/.ssh/authorized_keys{,2}, stages the lines that are kept and runs install -m 600 -- <staged> <file>, or rm -f -- <file> when nothing is left. Root only runs test -e. The tests here pin those commands on Linux.
Clear the password (add_local_account(..., clear_password=True)): usermod -p '*' <name>. The account logs in with its key only. The sudo step removes /etc/sudoers.d/80-account-<name> and takes the account out of sudo/wheel/admin.
Why *
The value has to stop every password and still let the key log in on Debian, Ubuntu and RHEL with sshd's defaults (UsePAM yes) and without PAM.
Not passwd -d (an empty field). pam_unix's nullok, which is on by default in Debian's and Ubuntu's common-auth, takes an empty field as "no password needed" for su and the console.
Not ! or usermod -L. With UsePAM no, sshd takes a ! prefix for a locked account and refuses the key too. With PAM it makes no difference, but * works both ways.
Not the expiry. That is this driver's lock (usermod -L -e 1), and PAM's account check refuses an expired account its key login.
usermod -p leaves the expiry alone and records today as the last password change, so pam_unix does not ask for a new password at the next key login. * is already in the driver's set of "no password" fields, so opening the account again later does not try usermod -U.
Tests
Fixtures only, no device. Two tests failed first, because the device-types default raises NotImplementedError for the clear hook: test_clearing_the_password_is_a_star_no_hash_matches and test_removing_the_password_runs_usermod_and_takes_sudo_away. New tests also pin the replace and remove commands and the fact that a key-only account opens again without a password coming back. 362 tests pass against the device-types branch. ruff, mypy, napalm-standard check and ratchet are clean.
## What
Personal accounts on Linux now follow what the person changes. See NetOrk/netork#2013.
**Needs the napalm-device-types release first** (NAPALM/napalm-device-types#90, assumed to be 4.28.0). The floor is raised to `napalm-device-types>=4.28.0`. CI pre-installs device-types from git main, so this PR goes green once #90 is merged.
- **Replace a key** (`add_local_account(..., replaces=[...])`) and **remove keys** (`remove_local_account_keys`) use the mixin's key-file implementation. As the person (`sudo -n -u <name>`), it reads `~/.ssh/authorized_keys{,2}`, stages the lines that are kept and runs `install -m 600 -- <staged> <file>`, or `rm -f -- <file>` when nothing is left. Root only runs `test -e`. The tests here pin those commands on Linux.
- **Clear the password** (`add_local_account(..., clear_password=True)`): `usermod -p '*' <name>`. The account logs in with its key only. The `sudo` step removes `/etc/sudoers.d/80-account-<name>` and takes the account out of sudo/wheel/admin.
## Why `*`
The value has to stop every password and still let the key log in on Debian, Ubuntu and RHEL with sshd's defaults (`UsePAM yes`) and without PAM.
- **Not `passwd -d` (an empty field).** pam_unix's `nullok`, which is on by default in Debian's and Ubuntu's `common-auth`, takes an empty field as "no password needed" for `su` and the console.
- **Not `!` or `usermod -L`.** With `UsePAM no`, sshd takes a `!` prefix for a locked account and refuses the key too. With PAM it makes no difference, but `*` works both ways.
- **Not the expiry.** That is this driver's lock (`usermod -L -e 1`), and PAM's account check refuses an expired account its key login.
`usermod -p` leaves the expiry alone and records today as the last password change, so pam_unix does not ask for a new password at the next key login. `*` is already in the driver's set of "no password" fields, so opening the account again later does not try `usermod -U`.
## Tests
Fixtures only, no device. Two tests failed first, because the device-types default raises `NotImplementedError` for the clear hook: `test_clearing_the_password_is_a_star_no_hash_matches` and `test_removing_the_password_runs_usermod_and_takes_sudo_away`. New tests also pin the replace and remove commands and the fact that a key-only account opens again without a password coming back. 362 tests pass against the device-types branch. ruff, mypy, `napalm-standard check` and `ratchet` are clean.
napalm-device-types 4.28.0 lets add_local_account remove the old keys
(replaces) and the password (clear_password), and adds
remove_local_account_keys. The key changes run through the mixin's own
key files as the person; the password goes with usermod -p '*', which
leaves the expiry (the lock) alone and keeps the key login working with
and without PAM, where an empty password or a '!' would not.
See NetOrk/netork#2013
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.
What
Personal accounts on Linux now follow what the person changes. See NetOrk/netork#2013.
Needs the napalm-device-types release first (NAPALM/napalm-device-types#90, assumed to be 4.28.0). The floor is raised to
napalm-device-types>=4.28.0. CI pre-installs device-types from git main, so this PR goes green once #90 is merged.add_local_account(..., replaces=[...])) and remove keys (remove_local_account_keys) use the mixin's key-file implementation. As the person (sudo -n -u <name>), it reads~/.ssh/authorized_keys{,2}, stages the lines that are kept and runsinstall -m 600 -- <staged> <file>, orrm -f -- <file>when nothing is left. Root only runstest -e. The tests here pin those commands on Linux.add_local_account(..., clear_password=True)):usermod -p '*' <name>. The account logs in with its key only. Thesudostep removes/etc/sudoers.d/80-account-<name>and takes the account out of sudo/wheel/admin.Why
*The value has to stop every password and still let the key log in on Debian, Ubuntu and RHEL with sshd's defaults (
UsePAM yes) and without PAM.passwd -d(an empty field). pam_unix'snullok, which is on by default in Debian's and Ubuntu'scommon-auth, takes an empty field as "no password needed" forsuand the console.!orusermod -L. WithUsePAM no, sshd takes a!prefix for a locked account and refuses the key too. With PAM it makes no difference, but*works both ways.usermod -L -e 1), and PAM's account check refuses an expired account its key login.usermod -pleaves the expiry alone and records today as the last password change, so pam_unix does not ask for a new password at the next key login.*is already in the driver's set of "no password" fields, so opening the account again later does not tryusermod -U.Tests
Fixtures only, no device. Two tests failed first, because the device-types default raises
NotImplementedErrorfor the clear hook:test_clearing_the_password_is_a_star_no_hash_matchesandtest_removing_the_password_runs_usermod_and_takes_sudo_away. New tests also pin the replace and remove commands and the fact that a key-only account opens again without a password coming back. 362 tests pass against the device-types branch. ruff, mypy,napalm-standard checkandratchetare clean.