1 import ./make-test-python.nix ({ pkgs, ... }:
5 busybox = pkgs : pkgs.busybox.override {
6 # Without this, the busybox binary drops euid to ruid for most applets, including id.
7 # See https://bugs.busybox.net/show_bug.cgi?id=15101
8 extraConfig = "CONFIG_FEATURE_SUID n";
14 nodes.machine = { config, pkgs, ... }: {
15 ids.gids.users = usersGid;
29 source = "${busybox pkgs}/bin/busybox";
30 program = "suid_root_busybox";
36 source = "${busybox pkgs}/bin/busybox";
37 program = "sgid_root_busybox";
42 source = "${pkgs.libcap}/bin/capsh";
43 program = "capsh_with_chown";
44 capabilities = "cap_chown+ep";
51 def cmd_as_regular(cmd):
52 return "su -l regular -c '{0}'".format(cmd)
54 def test_as_regular(cmd, expected):
55 out = machine.succeed(cmd_as_regular(cmd)).strip()
56 assert out == expected, "Expected {0} to output {1}, but got {2}".format(cmd, expected, out)
58 test_as_regular('${busybox pkgs}/bin/busybox id -u', '${toString userUid}')
59 test_as_regular('${busybox pkgs}/bin/busybox id -ru', '${toString userUid}')
60 test_as_regular('${busybox pkgs}/bin/busybox id -g', '${toString usersGid}')
61 test_as_regular('${busybox pkgs}/bin/busybox id -rg', '${toString usersGid}')
63 test_as_regular('/run/wrappers/bin/suid_root_busybox id -u', '0')
64 test_as_regular('/run/wrappers/bin/suid_root_busybox id -ru', '${toString userUid}')
65 test_as_regular('/run/wrappers/bin/suid_root_busybox id -g', '${toString usersGid}')
66 test_as_regular('/run/wrappers/bin/suid_root_busybox id -rg', '${toString usersGid}')
68 test_as_regular('/run/wrappers/bin/sgid_root_busybox id -u', '${toString userUid}')
69 test_as_regular('/run/wrappers/bin/sgid_root_busybox id -ru', '${toString userUid}')
70 test_as_regular('/run/wrappers/bin/sgid_root_busybox id -g', '0')
71 test_as_regular('/run/wrappers/bin/sgid_root_busybox id -rg', '${toString usersGid}')
73 # We are only testing the permitted set, because it's easiest to look at with capsh.
74 machine.fail(cmd_as_regular('${pkgs.libcap}/bin/capsh --has-p=CAP_CHOWN'))
75 machine.fail(cmd_as_regular('${pkgs.libcap}/bin/capsh --has-p=CAP_SYS_ADMIN'))
76 machine.succeed(cmd_as_regular('/run/wrappers/bin/capsh_with_chown --has-p=CAP_CHOWN'))
77 machine.fail(cmd_as_regular('/run/wrappers/bin/capsh_with_chown --has-p=CAP_SYS_ADMIN'))