summaryrefslogtreecommitdiffstats
path: root/nixos
diff options
context:
space:
mode:
authorworldofpeace <worldofpeace@protonmail.ch>2020-08-14 14:05:39 -0400
committerGitHub <noreply@github.com>2020-08-14 14:05:39 -0400
commitbea55603543a8bc6569524be0e8126be406157fb (patch)
tree1e5bc38131247918e4dd3a9f23778f8c537eed46 /nixos
parent3cc42af71fab4695324d08b8b866a12ffb16a400 (diff)
parent15c53cf0fa87d6f01abb0de526827a4cffafd86a (diff)
Merge pull request #94878 from stigtsp/package/firejail-test
nixos/tests: add test for firejail
Diffstat (limited to 'nixos')
-rw-r--r--nixos/tests/all-tests.nix1
-rw-r--r--nixos/tests/firejail.nix82
2 files changed, 83 insertions, 0 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index d7e5d70328ce..7c35ba8b29d6 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -101,6 +101,7 @@ in
ferm = handleTest ./ferm.nix {};
firefox = handleTest ./firefox.nix {};
firefox-esr = handleTest ./firefox.nix { esr = true; };
+ firejail = handleTest ./firejail.nix {};
firewall = handleTest ./firewall.nix {};
fish = handleTest ./fish.nix {};
flannel = handleTestOn ["x86_64-linux"] ./flannel.nix {};
diff --git a/nixos/tests/firejail.nix b/nixos/tests/firejail.nix
new file mode 100644
index 000000000000..a723cb01664f
--- /dev/null
+++ b/nixos/tests/firejail.nix
@@ -0,0 +1,82 @@
+import ./make-test-python.nix ({ pkgs, ...} : {
+ name = "firejail";
+ meta = with pkgs.stdenv.lib.maintainers; {
+ maintainers = [ sgo ];
+ };
+
+ nodes.machine = { ... }: {
+ imports = [ ./common/user-account.nix ];
+
+ programs.firejail = {
+ enable = true;
+ wrappedBinaries = {
+ bash-jailed = "${pkgs.bash}/bin/bash";
+ };
+ };
+
+ systemd.services.setupFirejailTest = {
+ wantedBy = [ "multi-user.target" ];
+ before = [ "multi-user.target" ];
+
+ environment = {
+ HOME = "/home/alice";
+ };
+
+ unitConfig = {
+ type = "oneshot";
+ RemainAfterExit = true;
+ user = "alice";
+ };
+
+ script = ''
+ cd $HOME
+
+ mkdir .password-store && echo s3cret > .password-store/secret
+ mkdir my-secrets && echo s3cret > my-secrets/secret
+
+ echo publ1c > public
+
+ mkdir -p .config/firejail
+ echo 'blacklist ''${HOME}/my-secrets' > .config/firejail/globals.local
+ '';
+ };
+ };
+
+ testScript = ''
+ start_all()
+ machine.wait_for_unit("multi-user.target")
+
+ # Test path acl with wrapper
+ machine.succeed("sudo -u alice bash-jailed -c 'cat ~/public' | grep -q publ1c")
+ machine.fail(
+ "sudo -u alice bash-jailed -c 'cat ~/.password-store/secret' | grep -q s3cret"
+ )
+ machine.fail("sudo -u alice bash-jailed -c 'cat ~/my-secrets/secret' | grep -q s3cret")
+
+
+ # Test path acl with firejail executable
+ machine.succeed("sudo -u alice firejail -- bash -c 'cat ~/public' | grep -q publ1c")
+ machine.fail(
+ "sudo -u alice firejail -- bash -c 'cat ~/.password-store/secret' | grep -q s3cret"
+ )
+ machine.fail(
+ "sudo -u alice firejail -- bash -c 'cat ~/my-secrets/secret' | grep -q s3cret"
+ )
+
+ # Disabling profiles
+ machine.succeed(
+ "sudo -u alice bash -c 'firejail --noprofile -- cat ~/.password-store/secret' | grep -q s3cret"
+ )
+
+ # CVE-2020-17367
+ machine.fail(
+ "sudo -u alice firejail --private-tmp id --output=/tmp/vuln1 && cat /tmp/vuln1"
+ )
+
+ # CVE-2020-17368
+ machine.fail(
+ "sudo -u alice firejail --private-tmp --output=/tmp/foo 'bash -c $(id>/tmp/vuln2;echo id)' && cat /tmp/vuln2"
+ )
+ '';
+})
+