feat(accounts): clear a password, replace and remove keys on FreeBSD #29

Merged
christianmanivong merged 1 commits from fix/local-account-key-replace into main 2026-11-04 11:28:20 +00:00
Owner

What

Personal accounts on FreeBSD 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.

  • Replace a key (add_local_account(..., replaces=[...])) and remove keys (remove_local_account_keys) use the mixin's key-file implementation. As the person, it reads ~/.ssh/authorized_keys{,2} and runs install -m 600 with the kept lines, or rm -f when nothing is left. Root only runs test -e.
  • Clear the password (add_local_account(..., clear_password=True)): chpass -p '*' <name>. The sudo step removes /usr/local/etc/sudoers.d/80-account-<name> and runs pw groupmod wheel -d <name>.

Why *

* is the field pw useradd -w no gives a new key-only account, and that already logs in with a key. No hash matches it. sshd takes only *LOCKED* (the pw lock prefix) for a locked account, so the key still works with or without PAM. chpass -p is what the driver already uses to set a hash. A locked account is unlocked by the account step (pw unlock) before the password step runs.

Tests

Fixtures only, no device. Two tests failed first: test_clearing_the_password_leaves_the_star_pw_gives_a_key_only_account and test_removing_the_password_runs_chpass_and_takes_sudo_away. New tests also pin the replace and remove commands. 192 tests pass against the device-types branch. ruff, napalm-standard check and ratchet are clean, and mypy reports nothing in napalm_bsd.

## What Personal accounts on FreeBSD 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`. - **Replace a key** (`add_local_account(..., replaces=[...])`) and **remove keys** (`remove_local_account_keys`) use the mixin's key-file implementation. As the person, it reads `~/.ssh/authorized_keys{,2}` and runs `install -m 600` with the kept lines, or `rm -f` when nothing is left. Root only runs `test -e`. - **Clear the password** (`add_local_account(..., clear_password=True)`): `chpass -p '*' <name>`. The `sudo` step removes `/usr/local/etc/sudoers.d/80-account-<name>` and runs `pw groupmod wheel -d <name>`. ## Why `*` `*` is the field `pw useradd -w no` gives a new key-only account, and that already logs in with a key. No hash matches it. sshd takes only `*LOCKED*` (the `pw lock` prefix) for a locked account, so the key still works with or without PAM. `chpass -p` is what the driver already uses to set a hash. A locked account is unlocked by the `account` step (`pw unlock`) before the `password` step runs. ## Tests Fixtures only, no device. Two tests failed first: `test_clearing_the_password_leaves_the_star_pw_gives_a_key_only_account` and `test_removing_the_password_runs_chpass_and_takes_sudo_away`. New tests also pin the replace and remove commands. 192 tests pass against the device-types branch. ruff, `napalm-standard check` and `ratchet` are clean, and mypy reports nothing in `napalm_bsd`.
christianmanivong added 1 commit 2026-11-04 10:50:35 +00:00
feat(accounts): clear a password, replace and remove keys on FreeBSD
driver / lint (pull_request) Successful in 26s
driver / standard (pull_request) Successful in 29s
driver / types (pull_request) Successful in 1m9s
driver / test (3.13) (pull_request) Successful in 1m3s
driver / test (3.12) (pull_request) Successful in 1m11s
driver / lowest (pull_request) Successful in 36s
driver / build (pull_request) Successful in 43s
driver / security (pull_request) Successful in 1m27s
CI / driver (pull_request) Successful in 2m59s
driver / publish (pull_request) Skipped
a16918245c
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 chpass -p '*', the
field pw useradd -w no writes, which sshd does not take for a lock.

See NetOrk/netork#2013
christianmanivong merged commit f5a5efdab3 into main 2026-11-04 11:28:20 +00:00
christianmanivong deleted branch fix/local-account-key-replace 2026-11-04 11:28:20 +00:00
Sign in to join this conversation.