Skip to content

Issue 14 - run nsncd as nscd user - #129

Open
morisja wants to merge 8 commits into
twosigma:mainfrom
morisja:issue-14
Open

morisja wants to merge 8 commits into
twosigma:mainfrom
morisja:issue-14

Conversation

@morisja

@morisja morisja commented Oct 6, 2024

Copy link
Copy Markdown
Collaborator

Building on top of
#110

@morisja
morisja force-pushed the issue-14 branch 4 times, most recently from 160e820 to 0b2b69f Compare September 9, 2026 21:43
@morisja morisja changed the title Issue 14 - run nsncd as nsncd user Issue 14 - run nsncd as nscd user Sep 9, 2026
@morisja
morisja force-pushed the issue-14 branch 3 times, most recently from e514bf4 to 2a51dca Compare September 9, 2026 21:55
This updates the nsncd.service systemd unit file to run nsncd as a
`nscd` user and group, and enables sandboxing.

Fixes twosigma#14.
@morisja
morisja force-pushed the issue-14 branch 4 times, most recently from 4bc4486 to a8844c6 Compare September 13, 2026 21:23
@morisja
morisja requested review from geofft and leifwalsh September 13, 2026 21:26
@morisja
morisja force-pushed the issue-14 branch 3 times, most recently from a5160d5 to 6b28468 Compare September 24, 2026 13:58
This is a debian patch and required to omit specific lookup types

@geofft geofft left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to add adduser to Depends in debian/control. That probably also means it can be removed from the GHA script, since installing nsncd will pull it in as needed.

Other than that, LGTM. I worried a bit about whether there are any NSS modules in common use that require privileged subprocesses (analogous to how pam_unix runs unix_chkpwd to get access to /etc/shadow) and so the sandboxing would affect that, but I don't think there is. I asked Claude to scrape the Debian repos to see if there's any packaged NSS modules that include setuid/setcap binaries but it didn't find any, either. This doesn't rule out that there might be some private / enterprise NSS module that does this, but that seems unusual. A more common design for something needing privileged access is a local client/server architecture, which e.g. both nslcd and sssd use for LDAP credentials.

The one case I'm worried about is whether an existing site specifically using nsncd has accidentally configured their system so that NSS lookups only work as root, e.g., /etc/passwd with the wrong permissions, or more practically, something like nss-extrausers with the extrausers file being unintentionally root-only. But that would arguably be our fault for previously running as root and it seems worth breaking that ASAP, and there's no good way for us to detect/warn about this. If we have something like release notes, I might document that users should confirm that their setup works as non-root.

Do you know if Debian has a preference for a static system user vs. using systemd's dynamic users feature? I suppose the risk of UID reuse on /var/run/nscd/ argues a bit in favor of a static user. (Mostly I'm thinking that dynamic users would save us from having to think about adduser at all, and would work on all distros without them having to create the _nsncd user in their packaging.)

Comment thread README.md
Comment thread nsncd.service
@morisja

morisja commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

Re: Dynamic user, I don't think so, I actually reached out to the Debian maintainer Philipp who suggested the _nsncd user and group.
For the release notes, I was going to bump to 1.6.0, or would you suggest 2.0.0 due to this change ?

@morisja
morisja enabled auto-merge October 18, 2026 20:27
@morisja
morisja requested a review from thwalker3 October 19, 2026 12:32
Comment thread README.md Outdated
Co-authored-by: Leif Walsh <leif.walsh@gmail.com>
Comment thread debian/postinst
case "$1" in
configure)
# 1. Create a system group if it doesn't exist
if ! getent group "$_GROUPNAME" >/dev/null; then

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see $_GROUPNAME set anywhere

Comment thread debian/postrm
case "$1" in
purge)
# Remove the system user if deluser exists and the user exists
if [ -x "$(command -v deluser)" ] && getent _nsncd >/dev/null; then

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getent group _nsncd

Comment thread debian/postinst
@@ -0,0 +1,34 @@
#!/bin/sh -e

set -e

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: redundant

Comment thread debian/postinst
configure)
# 1. Create a system group if it doesn't exist
if ! getent group "$_GROUPNAME" >/dev/null; then
addgroup --system --quiet _nsncd

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove this and specify --system --group in the adduser below

Comment thread nsncd.service
RestrictNamespaces=true
SystemCallArchitectures=native

RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restricting AF_NETLINK breaks things such as nss-myhostname

@thwalker3

Copy link
Copy Markdown
Collaborator

Running as non-root is definitely an admireable goal, but there are some (largely legacy) plugins like the old libnss_ldap that actually do need to be run as root. nscd has an opt-in "server-user" to drop privs. Maybe there is nothing modern left that we care about?

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.

5 participants