Skip to content

fix: set shadow file to root:shadow 0640 in mutable mode#41

Open
jfroche wants to merge 1 commit intonikstur:mainfrom
jfroche:shadow-permissions
Open

fix: set shadow file to root:shadow 0640 in mutable mode#41
jfroche wants to merge 1 commit intonikstur:mainfrom
jfroche:shadow-permissions

Conversation

@jfroche
Copy link
Copy Markdown

@jfroche jfroche commented Feb 6, 2026

When mutable users are enabled, tools like passwd need to read /etc/shadow, which requires the file to be accessible to the shadow group.

In mutable mode, set the shadow file to mode 0640 with the shadow group.

In immutable mode the existing 0000 behavior is preserved.

When mutable users are enabled, tools like passwd need to read
/etc/shadow, which requires the file to be accessible to the shadow
group.

In mutable mode, set the shadow file to mode 0640 with the shadow group.

In immutable mode the existing 0000 behavior is preserved.
jfroche added a commit to numtide/system-manager that referenced this pull request Feb 6, 2026
We have added a PR to userborn to fix the ownership/permission on
/etc/shadow: nikstur/userborn#41

/etc/shadow has mode 0640 and group shadow after both
activation and deactivation.
@nikstur
Copy link
Copy Markdown
Owner

nikstur commented Feb 17, 2026

Can you please check whether this is also true with the passwd from util-linux? In nixpkgs we weirdly use these tools from shadow and not from util-linux. If util-linux works, I'd prefer we switch upstream Nixpkgs to use util-linux instead of shadow.

Edit: please ignore.

@kanashimia
Copy link
Copy Markdown

kanashimia commented Mar 28, 2026

Why do it only in mutable mode? It should always be root shadow.
Tools like unix_chkpwd use setgid shadow permission to access /etc/shadow
Just that NixOS has broken insecure permissions on unix_chkpwd and assigns setuid root instead, so the current behaviour of userborn works there (and it shouldn't).
https://github.com/NixOS/nixpkgs/blob/f48cce8648b6a0c331f54073a459c97f67ed72ea/nixos/modules/config/update-users-groups.pl#L317-L323
update-users-groups.pl always sets permissions to root:shadow 0640

@nikstur
Copy link
Copy Markdown
Owner

nikstur commented Mar 29, 2026

Userborn follows the semantics of systemd-sysusers which uses these exact file permissions.

@kanashimia
Copy link
Copy Markdown

kanashimia commented Mar 29, 2026

Userborn follows the semantics of systemd-sysusers

Well, you don't though? sysusers preserves existing permissions, it never overrides them, permissions it creates are relevant only when it creates a file that doesn't exist. Where as userborn and update-users-groups.pl always override permissions as it seems. So for systemd-sysusers you can create a file using systemd-tmpfiles and set whatever permissions you like.

Well, that is a different issue though.

@r-vdp
Copy link
Copy Markdown

r-vdp commented Apr 17, 2026

I took a slightly different approach in #46, before seeing this PR.

My main motivation is to remove setuid from unixchk_pwd and have only setgid instead.

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.

4 participants