-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Bind mounting nscd socket in the sandbox causes getpwuid to return the wrong user #4991
Comments
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/haunted-nix-build-breaks-isolation/13869/16 |
git blame points to b6b142b |
And if the host does not have a UID=1000 user,
(This happened to me on a Ubuntu 18.04 machine with LDAP setup.) I tried to fix this with the following patch, hoping that it'd stop glibc from within the build to talk to the outside host for user info, but it didn't seem to work: diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc
index 7c1402918..2763e68c0 100644
--- a/src/libstore/build/local-derivation-goal.cc
+++ b/src/libstore/build/local-derivation-goal.cc
@@ -1729,7 +1729,7 @@ void LocalDerivationGoal::runChild()
// services. Don’t use it for anything else that may
// be configured for this system. This limits the
// potential impurities introduced in fixed-outputs.
- writeFile(chrootRootDir + "/etc/nsswitch.conf", "hosts: files dns\nservices: files\n");
+ writeFile(chrootRootDir + "/etc/nsswitch.conf", "passwd: files\nhosts: files dns\nservices: files\n");
/* N.B. it is realistic that these paths might not exist. It
happens when testing Nix building fixed-output derivations
|
This seems to have been reported before but that issue is closed for some reason: #3693 |
I did some more testing, comparing docker's isolation with nix's. Full logs here.
This makes sense. libnss probably assumes that if an nscd socket is available, it was created by an nscd that has already parsed I'm not entirely sure what caused the error in b6b142b, I'll try to reproduce it. Maybe they had an unusual nsswitch.conf or dns setup, preventing processes in the netns of the build from talking to the nameserver in |
I made the following change to nix master
I tried building this default.nix:
generates the output:
It successfully fetches the same file @edolstra was failing to fetch without nscd. getpwuid also returns the right result. |
My (uneducated) guess is that it failed for edolstra, because back in that day the full Line 2340 in b6b142b
Nowadays a stripped down version of nix/src/libstore/build/local-derivation-goal.cc Line 1752 in 6182ae6
|
Passing nscd socket into the build environment causes unexpected behavior in programs that make getpwuid and other related calls. relevant threads: - NixOS#4991 - https://discourse.nixos.org/t/haunted-nix-build-breaks-isolation/13869
…her calls Passing nscd socket into the build environment causes unexpected behavior in programs that make getpwuid and other related calls. relevant threads: - NixOS#4991 - https://discourse.nixos.org/t/haunted-nix-build-breaks-isolation/13869
Passing nscd socket into the build environment causes unexpected behavior in programs that make getpwuid and other related calls. relevant threads: - NixOS#4991 - https://discourse.nixos.org/t/haunted-nix-build-breaks-isolation/13869
Makes sense. If the underlying problem is solved, this change shouldn't cause any new issues. |
Fixed by eb47889 |
Describe the bug
When building a fixed-output derivation querying the user with getpwuid (3) results in the user with the UID 1000 outside the sandbox.
Steps To Reproduce
The nscd socket is bind mounted into the sandbox when building a fixed output derivation. This is probably because nscd handles DNS requests and since the build has access to the network this functionality is desirable.
nix/src/libstore/build/local-derivation-goal.cc
Lines 1747 to 1760 in 6182ae6
However, when we look at the manpage of nscd we find
So the problem is that inside the sandbox the libc function
getpwuid
queries the nscd socket to resolve the uid to a user name but because this is bind mounted to the outside it will resolve the normal user. We can easily verify this:Please don’t pay attention to the hash mismatches. They are on purpose so that the derivation is rebuilt every time.
Expected behavior
getpwuid (3) should always return the user inside the sandbox.
nix-env --version
outputnix-env (Nix) 2.4pre20210601_5985b8b
Additional context
https://discourse.nixos.org/t/haunted-nix-build-breaks-isolation/13869
The text was updated successfully, but these errors were encountered: