diff options
author | alois31 <alois1@gmx-topmail.de> | 2024-05-25 04:21:53 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@lix-systems> | 2024-05-25 04:21:53 +0000 |
commit | ddfe379a6b93c678a9a0845e5c5a85f7e77b1b7d (patch) | |
tree | bc99ab3f691eeef509943bdcc83feae60bc39d0e /tests | |
parent | 5b4b216facfb8af2f08c25a4b50fba1e197ca06e (diff) | |
parent | f047e4357b4f7ad66c2e476506bf35cab82e441e (diff) |
Merge "libstore/build: always enable seccomp filtering and no-new-privileges" into main
Diffstat (limited to 'tests')
-rw-r--r-- | tests/nixos/default.nix | 4 | ||||
-rw-r--r-- | tests/nixos/no-new-privileges/no-sandbox.nix | 21 | ||||
-rw-r--r-- | tests/nixos/no-new-privileges/package.nix | 8 | ||||
-rw-r--r-- | tests/nixos/no-new-privileges/sandbox.nix | 18 | ||||
-rw-r--r-- | tests/nixos/root-in-sandbox/default.nix | 15 | ||||
-rw-r--r-- | tests/nixos/root-in-sandbox/package.nix | 8 |
6 files changed, 50 insertions, 24 deletions
diff --git a/tests/nixos/default.nix b/tests/nixos/default.nix index 354413a7c..5e8bc69ce 100644 --- a/tests/nixos/default.nix +++ b/tests/nixos/default.nix @@ -184,7 +184,9 @@ in symlinkResolvconf = runNixOSTestFor "x86_64-linux" ./symlink-resolvconf.nix; - rootInSandbox = runNixOSTestFor "x86_64-linux" ./root-in-sandbox; + noNewPrivilegesInSandbox = runNixOSTestFor "x86_64-linux" ./no-new-privileges/sandbox.nix; + + noNewPrivilegesOutsideSandbox = runNixOSTestFor "x86_64-linux" ./no-new-privileges/no-sandbox.nix; broken-userns = runNixOSTestFor "x86_64-linux" ./broken-userns.nix; diff --git a/tests/nixos/no-new-privileges/no-sandbox.nix b/tests/nixos/no-new-privileges/no-sandbox.nix new file mode 100644 index 000000000..d952a6862 --- /dev/null +++ b/tests/nixos/no-new-privileges/no-sandbox.nix @@ -0,0 +1,21 @@ +let + inherit (import ../util.nix) mkNixBuildTest; +in +mkNixBuildTest { + name = "no-new-privileges-outside-sandbox"; + extraMachineConfig = + { pkgs, ... }: + { + security.wrappers.ohno = { + owner = "root"; + group = "root"; + capabilities = "cap_sys_nice=eip"; + source = "${pkgs.libcap}/bin/getpcaps"; + }; + nix.settings = { + extra-sandbox-paths = [ "/run/wrappers/bin/ohno" ]; + sandbox = false; + }; + }; + expressionFile = ./package.nix; +} diff --git a/tests/nixos/no-new-privileges/package.nix b/tests/nixos/no-new-privileges/package.nix new file mode 100644 index 000000000..55c96bc2e --- /dev/null +++ b/tests/nixos/no-new-privileges/package.nix @@ -0,0 +1,8 @@ +{ runCommand, libcap }: +runCommand "cant-get-capabilities" { nativeBuildInputs = [ libcap.out ]; } '' + if [ "$(/run/wrappers/bin/ohno 2>&1)" != "failed to inherit capabilities: Operation not permitted" ]; then + echo "Oh no! We gained capabilities!" + exit 1 + fi + touch $out +'' diff --git a/tests/nixos/no-new-privileges/sandbox.nix b/tests/nixos/no-new-privileges/sandbox.nix new file mode 100644 index 000000000..e2475555e --- /dev/null +++ b/tests/nixos/no-new-privileges/sandbox.nix @@ -0,0 +1,18 @@ +let + inherit (import ../util.nix) mkNixBuildTest; +in +mkNixBuildTest { + name = "no-new-privileges-in-sandbox"; + extraMachineConfig = + { pkgs, ... }: + { + security.wrappers.ohno = { + owner = "root"; + group = "root"; + capabilities = "cap_sys_nice=eip"; + source = "${pkgs.libcap}/bin/getpcaps"; + }; + nix.settings.extra-sandbox-paths = [ "/run/wrappers/bin/ohno" ]; + }; + expressionFile = ./package.nix; +} diff --git a/tests/nixos/root-in-sandbox/default.nix b/tests/nixos/root-in-sandbox/default.nix deleted file mode 100644 index 110d83f86..000000000 --- a/tests/nixos/root-in-sandbox/default.nix +++ /dev/null @@ -1,15 +0,0 @@ -let - inherit (import ../util.nix) mkNixBuildTest; -in mkNixBuildTest { - name = "root-in-sandbox"; - extraMachineConfig = { pkgs, ... }: { - security.wrappers.ohno = { - owner = "root"; - group = "root"; - setuid = true; - source = "${pkgs.coreutils}/bin/whoami"; - }; - nix.settings.extra-sandbox-paths = ["/run/wrappers/bin"]; - }; - expressionFile = ./package.nix; -} diff --git a/tests/nixos/root-in-sandbox/package.nix b/tests/nixos/root-in-sandbox/package.nix deleted file mode 100644 index a1069160c..000000000 --- a/tests/nixos/root-in-sandbox/package.nix +++ /dev/null @@ -1,8 +0,0 @@ -{ runCommand }: -runCommand "cant-get-root-in-sandbox" {} '' - if /run/wrappers/bin/ohno; then - echo "Oh no! We're root in the sandbox!" - exit 1 - fi - touch $out -'' |