fix(users): list real login accounts and read admins from the ACL

The passwd filter's precedence was inverted: it listed uid < 1000
(daemon, bin, ...) and skipped regular users. The level check looked
for "Administrator" in the user record, which never names roles. The
level now comes from /access/acl (Administrator on /, by user or
group), root@pam always 15.

Closes #19
This commit is contained in:
Christian Manivong committed 2026-11-01 21:50:16 +01:00
1 parent 037a725b74
commit 4ee74e4b3d
4 files changed
+142 -42

No files matched your search

-2
View File
@@ -16,7 +16,6 @@
"napalm_proxmox/sdn_mixin.py::ProxmoxSDNMixin.set_vlan": 13,
"napalm_proxmox/system_mixin.py::ProxmoxSystemMixin.get_disk_smart": 22,
"napalm_proxmox/system_mixin.py::ProxmoxSystemMixin.get_packages": 16,
"napalm_proxmox/system_mixin.py::ProxmoxSystemMixin.get_users": 15,
"napalm_proxmox/utils.py::addresses_from_node_network": 15,
"napalm_proxmox/vm_contract_mixin.py::parse_vm_config": 16,
"napalm_proxmox/vm_mixin.py::ProxmoxVMMixin._get_vm_disk_and_boot": 16,
@@ -35,7 +34,6 @@
"napalm_proxmox/sdn_mixin.py::ProxmoxSDNMixin.set_vlan": 70,
"napalm_proxmox/system_mixin.py::ProxmoxSystemMixin.get_disk_smart": 74,
"napalm_proxmox/system_mixin.py::ProxmoxSystemMixin.get_packages": 66,
"napalm_proxmox/system_mixin.py::ProxmoxSystemMixin.get_users": 51,
"napalm_proxmox/system_mixin.py::ProxmoxSystemMixin.set_hostname": 114,
"napalm_proxmox/vm_mixin.py::ProxmoxVMMixin.get_vm_interfaces": 179,
"napalm_proxmox/vm_mixin.py::ProxmoxVMMixin.get_vms": 114,
+66
View File
@@ -0,0 +1,66 @@
"""get_users: Proxmox users with their level, and the node's login accounts (#19)."""
from __future__ import annotations
from unittest.mock import patch
PASSWD = """\
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
alice:x:1000:1000:Alice:/home/alice:/bin/bash
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
"""
# GET /access/acl: who holds which role where.
ACL = [
{"path": "/", "roleid": "Administrator", "type": "user", "ugid": "admin@pve", "propagate": 1},
{"path": "/", "roleid": "Administrator", "type": "group", "ugid": "ops", "propagate": 1},
{"path": "/vms/100", "roleid": "Administrator", "type": "user", "ugid": "vm@pve"},
{"path": "/", "roleid": "PVEAuditor", "type": "user", "ugid": "audit@pve", "propagate": 1},
]
USERS = [
{"userid": "root@pam", "groups": ""},
{"userid": "admin@pve", "groups": ""},
{"userid": "bob@pve", "groups": "ops,dev"},
{"userid": "vm@pve", "groups": ""},
{"userid": "audit@pve", "groups": ""},
]
def _users(driver, passwd=PASSWD):
driver._api.access.users.get.return_value = USERS
driver._api.access.acl.get.return_value = ACL
with patch.object(driver, "_exec_ssh_command", return_value=passwd):
return driver.get_users()
class TestLocalAccounts:
def test_root_and_real_users_not_system_accounts(self, driver):
result = _users(driver)
assert result["root"]["level"] == 15
assert "alice" in result
for system in ("daemon", "bin", "www-data", "nobody"):
assert system not in result
class TestProxmoxUsers:
def test_administrator_on_the_whole_datacenter_is_level_15(self, driver):
result = _users(driver)
assert result["admin@pve"]["level"] == 15
def test_administrator_through_a_group_is_level_15(self, driver):
assert _users(driver)["bob@pve"]["level"] == 15
def test_root_at_pam_is_always_level_15(self, driver):
assert _users(driver)["root@pam"]["level"] == 15
def test_another_role_or_a_narrower_path_is_level_1(self, driver):
result = _users(driver)
assert result["audit@pve"]["level"] == 1
assert result["vm@pve"]["level"] == 1