-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide NSS modules globally, make nscd unnecessary (v2) #155655
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Ensure that NSS modules are accessible by glibc client binaries when | ||
# nscd is disabled | ||
|
||
import ./make-test-python.nix ({ lib, ... } : { | ||
name = "nssmodules-without-nscd"; | ||
|
||
meta = with lib.maintainers; { | ||
maintainers = [ earvstedt flokli ]; | ||
}; | ||
|
||
nodes.node = { | ||
services.nscd.enable = false; | ||
}; | ||
|
||
# Test dynamic user resolution via `libnss_systemd.so` which is only available | ||
# through `system.nssModules` | ||
testScript = '' | ||
node.succeed("systemd-run --property=DynamicUser=yes --property=User=testuser sleep infinity") | ||
node.succeed("getent passwd testuser") | ||
''; | ||
}) |
47 changes: 47 additions & 0 deletions
47
pkgs/development/libraries/glibc/add-extra-module-load-path.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Add NSS module load path /run/nss-modules-${word_size}-${glibc_version}/lib | ||
as a fallback. Previously, glibc only looked for NSS modules in ${glibc.out}/lib and | ||
LD_LIBRARY_PATH. | ||
|
||
On NixOS, this removes the dependency on nscd for enabling NSS functionality in | ||
glibc clients. | ||
nscd has caching bugs and leaks DNS requests across network namespaces. | ||
|
||
The module load path is only used by binaries that use the same glibc | ||
version and word size as the NSS modules. This avoids failures due to ABI | ||
incompatibilities. Incompatible binaries can still be served by nscd. | ||
|
||
On non-NixOS systems, this patch doesn't change behaviour, as the path | ||
doesn't exist there. | ||
|
||
diff --git a/nss/nss_module.c b/nss/nss_module.c | ||
index 6c5f341f..80b6eac0 100644 | ||
--- a/nss/nss_module.c | ||
+++ b/nss/nss_module.c | ||
@@ -133,5 +133,27 @@ module_load (struct nss_module *module) | ||
return false; | ||
|
||
handle = __libc_dlopen (shlib_name); | ||
+ | ||
+ /* After loading from the default locations, try loading from | ||
+ the NixOS module load path. */ | ||
+ if (handle == NULL) { | ||
+ | ||
+ #define STR_(x) #x | ||
+ #define STR(x) STR_(x) | ||
+ | ||
+ const char nix_nss_path[] = "/run/nss-modules-" STR(__WORDSIZE) "-" | ||
+ STR(__GLIBC__) "." STR(__GLIBC_MINOR__) "/lib/"; | ||
+ char shlib_path[1024]; | ||
+ size_t nix_nss_path_len = sizeof(nix_nss_path) - 1; | ||
+ size_t shlib_name_len = strlen(shlib_name); | ||
+ size_t shlib_path_len = nix_nss_path_len + shlib_name_len; | ||
+ | ||
+ if (shlib_path_len < sizeof(shlib_path)) { | ||
+ memcpy(&shlib_path[0], nix_nss_path, nix_nss_path_len); | ||
+ memcpy(&shlib_path[nix_nss_path_len], shlib_name, shlib_name_len + 1); | ||
+ handle = __libc_dlopen(shlib_path); | ||
+ } | ||
+ } | ||
+ | ||
free (shlib_name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this will "leak" symlinks over time as glibc versions change? Couldn't this be part of /run/current-system?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will create symlinks to nix store paths there (until it's rebooted). Nix might eventually garbage collect them away, I'm not sure if
/run
is checked. In that case, the NSS lookup will fail using that NSS module, which is probably still better than segfaulting ;-)Having these NSS moduels inside /run/current-system would mean one would need to keep multiple glibc versions around as part of the system closure.
As this is only meant to prevent breakage of still running old versions of binaries, compiled against an old glibc (and even those will use nscd by default), I'd consider this to be not much of a problem.