diff --git a/CHANGELOG.md b/CHANGELOG.md index 2339a6c..8008b90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- netOrk's own account with a fixed uid (NetOrk/netork#1817): `_account_create_with_uid` + makes it with `useradd -m -u `. Below `UID_MIN` useradd warns and goes on, as a + system's account. - Personal accounts (NetOrk/netork#1793), through napalm-device-types' `LocalAccountsMixin`: `get_local_accounts()`, `add_local_account()` and `lock_local_account()` with shadow-utils' commands (`useradd -m -s /bin/bash`, `usermod`, `gpasswd -d`). A locked diff --git a/napalm_linux/_local_accounts.py b/napalm_linux/_local_accounts.py index f612e9f..5b7d2c5 100644 --- a/napalm_linux/_local_accounts.py +++ b/napalm_linux/_local_accounts.py @@ -29,6 +29,10 @@ class LinuxLocalAccountsMixin(LocalAccountsMixin): password = ["-p", password_hash] if password_hash else [] return [["useradd", "-m", "-s", self.ACCOUNT_SHELL, *password, name]] + def _account_create_with_uid(self, name: str, uid: int) -> list[list[str]]: + # Below UID_MIN useradd warns and goes on: netOrk's own account is a system's. + return [["useradd", "-m", "-u", str(uid), "-s", self.ACCOUNT_SHELL, name]] + def _account_open( self, name: str, password_hash: str | None, *, locked: bool ) -> list[list[str]]: diff --git a/tests/test_local_accounts.py b/tests/test_local_accounts.py index 45e69aa..42a494a 100644 --- a/tests/test_local_accounts.py +++ b/tests/test_local_accounts.py @@ -101,3 +101,10 @@ def test_leaving_a_group_is_gpasswd() -> None: "alice", "sudo", ] + + +def test_netorks_own_account_is_made_with_its_uid() -> None: + """A fixed uid on every host, below UID_MIN (NetOrk/netork#1817).""" + assert _Driver()._account_create_with_uid("netork", 900) == [ + ["useradd", "-m", "-u", "900", "-s", "/bin/bash", "netork"] + ]