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

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
This commit is contained in:
Christian Manivong committed 2026-11-04 11:47:26 +01:00
1 parent 198f50f6be
commit a16918245c
4 files changed
+105 -1

No files matched your search

+9
View File
@@ -5,6 +5,10 @@ commands. A locked account is ``pw lock``'s: ``*LOCKED*`` in front of the
password, which sshd refuses a key login too. getpwnam(3) shows the password
field to root only, so the lock is read as root; nothing but its prefix is
looked at.
An account whose password is removed (NetOrk/netork#2013) gets ``*`` as its
password field, as ``pw useradd -w no`` gives a new one: no hash matches it,
and sshd takes only ``*LOCKED*`` for a lock, so the key still logs in.
"""
from __future__ import annotations
@@ -15,6 +19,8 @@ from napalm_device_types import LocalAccountsMixin
#: What ``pw lock`` puts in front of the password.
_LOCKED_PREFIX = "*LOCKED*"
#: The password field of an account that logs in with a key only: no hash matches it.
_KEY_ONLY = "*"
class FreeBSDLocalAccountsMixin(LocalAccountsMixin):
@@ -69,6 +75,9 @@ class FreeBSDLocalAccountsMixin(LocalAccountsMixin):
def _account_leave_group(self, name: str, group: str, groups: list[str]) -> list[str]:
return ["pw", "groupmod", group, "-d", name]
def _account_clear_password(self, name: str) -> list[list[str]]:
return [["chpass", "-p", _KEY_ONLY, name]]
@staticmethod
def _set_password(name: str, password_hash: str | None) -> list[list[str]]:
"""chpass takes the crypt(3) string itself from root."""