aboutsummaryrefslogtreecommitdiff
path: root/tests/nixos/broken-userns.nix
diff options
context:
space:
mode:
authorJade Lovelace <lix@jade.fyi>2024-05-04 00:55:15 -0700
committerJade Lovelace <lix@jade.fyi>2024-05-04 17:36:50 -0700
commit9909a175bf1602e7bb4ebfc1c9befeaa56da1fb4 (patch)
tree9b9db8ccb9017daf91d73164af5ede7905ec9360 /tests/nixos/broken-userns.nix
parent8dfb30a2355be667fcb947ea995669c801534fbf (diff)
Fix /etc/group having desynced IDs from the actual UID in the sandbox
This was found when `logrotate.conf` failed to build in a NixOS system with: /nix/store/26zdl4pyw5qazppj8if5lm8bjzxlc07l-coreutils-9.3/bin/id: cannot find name for group ID 30000 This was surprising because it seemed to mean that /etc/group was busted in the sandbox. Indeed it was: root:x:0: nixbld:!:100: nogroup:x:65534: We diagnosed this to sandboxUid() being called before usingUserNamespace() was called, in setting up /etc/group inside the sandbox. This code desperately needs refactoring. We also moved the /etc/group code to be with the /etc/passwd code, but honestly this code is all spaghetti'd all over the place and needs some more serious tidying than we did here. We also moved some checks to be earlier to improve locality with where the things they are checking come from. Change-Id: Ie29798771f3593c46ec313a32960fa955054aceb
Diffstat (limited to 'tests/nixos/broken-userns.nix')
-rw-r--r--tests/nixos/broken-userns.nix66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/nixos/broken-userns.nix b/tests/nixos/broken-userns.nix
new file mode 100644
index 000000000..a48467193
--- /dev/null
+++ b/tests/nixos/broken-userns.nix
@@ -0,0 +1,66 @@
+# Lix should be able to build derivations that want working NSS, even with
+# broken user namespaces support
+{ ... }:
+let
+ testDerivation = builtins.toFile "test.nix" ''
+ { cacheBreak }:
+ let pkgs = import <nixpkgs> { };
+ in
+ pkgs.runCommand "test" { } '''
+ # ''${cacheBreak}
+ id -g
+ id -u
+ echo "GROUP"
+ cat /etc/group
+ echo "PASSWD"
+ cat /etc/passwd
+
+ username=$(id -un)
+ groupname=$(id -gn)
+ [[ "$username" =~ nixbld* ]]
+ [[ "$groupname" =~ nixbld* ]]
+ touch $out
+ '''
+ '';
+in
+{
+ name = "broken-userns";
+
+ nodes.machine =
+ {
+ config,
+ lib,
+ pkgs,
+ ...
+ }:
+ {
+ virtualisation.writableStore = true;
+ nix.settings.substituters = lib.mkForce [ ];
+ nix.nixPath = [ "nixpkgs=${lib.cleanSource pkgs.path}" ];
+ virtualisation.additionalPaths = [
+ pkgs.stdenvNoCC
+ testDerivation
+ ];
+ };
+
+ testScript =
+ { nodes }:
+ ''
+ start_all()
+
+ # Building it normally should work
+ machine.succeed(r"""
+ nix-build --argstr cacheBreak 1 --store daemon ${testDerivation}
+ """)
+
+ # Building it with broken userns should also work
+ machine.succeed(r"""
+ # break user ns
+ sysctl -w user.max_user_namespaces=0
+ """)
+ machine.systemctl("restart nix-daemon")
+ machine.succeed(r"""
+ nix-build --argstr cacheBreak 2 --store daemon ${testDerivation}
+ """)
+ '';
+}