Skip to content

One owner for the system's users: oxyos-users, through NSS - #511

Open
NateIsern wants to merge 4 commits into
mainfrom
refactor/users-nss
Open

NateIsern wants to merge 4 commits into
mainfrom
refactor/users-nss

Conversation

@NateIsern

Copy link
Copy Markdown
Member

One owner for user-database lookups (code audit item 3, "one owner per concept"): oxyos-users, NSS only.

Why

The running system's users were looked up in seven places. Only oxyos-auth used NSS. The others read /etc/passwd and /etc/group by hand:

Copy Read Now
oxyos-auth User::named, user_name(uid), group_list NSS moved into oxyos-users
oxyos-account SystemUsers (lookup, GECOS, administrators) the files NSS for the system; files for a --prefix root
oxyos-accountd enrollers (the login program's user) /etc/passwd NSS
oxyos-install accounts::Passwd (a peer's user) /etc/passwd NSS by default; --passwd FILE still reads that file
oxyos-apps session_user /etc/passwd NSS
oxyos-networks nm::user_name /etc/passwd (after $USER) NSS (after $USER)
oxyos-activity Users (process owners) /etc/passwd NSS; a test machine's own file

A user from another NSS source (systemd's DynamicUsers, homed, a directory) was visible to auth/PAM/logind but not to the others, so programs could disagree about who a uid was.

What

  • crates/oxyos-users (T1, depends on libc only). user_named, user_by_uid (User: name, uid, gid, gecos, home, shell), group_members (getgrnam_r's gr_mem) and group_list (getgrouplist, moved from auth). Every call reads the database when it is made. If an entry does not fit the buffer (ERANGE), the call retries with a larger one, from 16 KiB up to 1 MiB. Before, auth failed on any entry over 16 KiB.
  • Another root's files are still read as files, clearly named and documented:
    • SystemUsers::with_prefix, plus passwd_entry/passwd_gecos/group_members in oxyos_account::users. These cover the tests' roots and a backup restored onto a target with useradd --prefix.
    • installd's --passwd FILE, the scenario gate's own passwd (regress.py). Passwd is now System | File(path), and the option is unset by default.
    • Activity Monitor's test machines: Procfs::passwd is Option<PathBuf>, None meaning the system's.
  • Not in this PR: oxyos-backup's service (user_of, administrator, the manifest's accounts) and migrate::login_user still read /etc/passwd and /etc/group through their options. Other forks are changing that crate right now, so that is left for a follow-up.

Behaviour

On a machine whose NSS reads files first, which includes the image (passwd: files systemd), CI and developers' machines, every answer is the same. The new tests prove it:

  • Every entry of /etc/passwd is found by name and by uid exactly as the file has it. A name or uid listed twice returns its first line, as the old find did. GECOS fields come back whole, commas included.
  • Every group of /etc/group comes back with the members the file lists.
  • Root is uid 0. This process's user is found by uid and by name. Unknown names (including empty and NUL) and unknown uids return none.
  • Activity Monitor names root and this user in the same sample, and shows an unknown uid as its number.

Differences:

  • A user known only to another NSS source is now seen by these services too.
  • In installd, if a uid's first entry has a name records cannot be kept under, NSS answers with that entry and the peer has no account. The old file scan kept looking for a later line with the same uid. A duplicate uid like that is not something OxyOS creates.
  • Activity Monitor asks NSS once per user, and asks again about a user with no entry at most once per sample. The old code reread the whole file at most once per sample, so every user of the first sample is still named.

Checks

On seldon: cargo fmt --check, cargo clippy --workspace --all-targets --locked -D warnings, check-native-boundary.py, cargo test --workspace --locked.

Layering: oxyos-users is T1 (an OS adapter). If ci/crate-layering lands first, it needs classifying there.

🤖 Generated with Claude Code

NateIsern and others added 4 commits November 10, 2026 02:02
The running system's users and groups were looked up seven ways: oxyos-auth through NSS
(getpwnam_r, getpwuid_r, getgrouplist), and by hand from /etc/passwd and /etc/group in
the accounts' service (its lookups, GECOS and administrators), accountd (the login
program's user), the install service (a peer's user), oxyos-apps (session_user),
oxyos-networks (the session's user) and Activity Monitor (process owners). Users from
another NSS source (systemd's, a directory's) were seen by some and not others.

oxyos-users (T1, libc only) is the one owner: user_named, user_by_uid, group_members and
group_list, each asked when needed, a larger buffer tried when an entry does not fit.
Every lookup of the running system the audit listed goes through it. The backup service's
(user_of, administrator, the manifest's accounts, migrate's login_user) still read
/etc/passwd and /etc/group through its options and are left for their own change.

Another root's files stay files, named as such: SystemUsers::with_prefix (the tests'
roots, a backup restored with --prefix) and passwd_entry/passwd_gecos/group_members in
oxyos_account::users; installd's --passwd FILE (the scenarios' own passwd), now an
option whose absence means the system's; Activity Monitor's test machines (Procfs's
passwd, now None for the system's).

Activity Monitor asks NSS per user, once, and again for a user it has none for at most
once a sample, so every user of a first sample is named (its file was read whole).

Tests: every entry of /etc/passwd and /etc/group found through NSS as the file says
(first line for a name or uid listed twice, GECOS commas and all), root, this process's
user, unknown names and uids; Activity Monitor names root and this user in one sample.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It adapts the C library's account database (NSS) and depends on libc only; its users are
system, service and program crates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant