diff --git a/README.md b/README.md index bda451e..9b93970 100644 --- a/README.md +++ b/README.md @@ -257,6 +257,7 @@ Add the flake input and NixOS module to your `flake.nix`: The module builds the package with your NixOS configuration's `pkgs`, so the GlobalProtect GUI and the system use the same Nixpkgs dependency versions. +It also enables Polkit and its setuid `pkexec` wrapper for privileged operations. ```nix { diff --git a/flake.nix b/flake.nix index fabc7b1..130c1e8 100644 --- a/flake.nix +++ b/flake.nix @@ -304,6 +304,7 @@ { config, lib, + options, pkgs, ... }: @@ -326,6 +327,11 @@ config = lib.mkIf cfg.enable { environment.systemPackages = [ cfg.package ]; services.ayatana-indicators.enable = lib.mkDefault true; + security.polkit = { + enable = true; + } // lib.optionalAttrs (options.security.polkit ? enablePkexecWrapper) { + enablePkexecWrapper = true; + }; }; }; in diff --git a/nix/ci.nix b/nix/ci.nix index 756e15b..c89b351 100644 --- a/nix/ci.nix +++ b/nix/ci.nix @@ -41,7 +41,18 @@ in { prebuilt = prebuiltPackage; module = assert builtins.elem modulePackage hostSystem.config.environment.systemPackages; assert hostSystem.config.services.ayatana-indicators.enable; + assert hostSystem.config.security.polkit.enable; + assert hostSystem.config.security.wrappers.pkexec.enable; + assert hostSystem.config.security.wrappers.pkexec.setuid; modulePackage; - runtime-source = import ./tests/native-runtime.nix { inherit pkgs; package = sourcePackage; }; - runtime-prebuilt = import ./tests/native-runtime.nix { inherit pkgs; package = prebuiltPackage; }; + runtime-source = import ./tests/native-runtime.nix { + inherit pkgs; + package = sourcePackage; + module = gp.nixosModules.default; + }; + runtime-prebuilt = import ./tests/native-runtime.nix { + inherit pkgs; + package = prebuiltPackage; + module = gp.nixosModules.default; + }; } diff --git a/nix/tests/native-runtime.nix b/nix/tests/native-runtime.nix index 2e1e8c1..d83a550 100644 --- a/nix/tests/native-runtime.nix +++ b/nix/tests/native-runtime.nix @@ -1,4 +1,4 @@ -{ pkgs, package }: +{ pkgs, package, module }: let guiProbe = pkgs.writeScript "gpgui-runtime-probe" '' #!${pkgs.python3}/bin/python3 @@ -32,9 +32,10 @@ in pkgs.testers.runNixOSTest { name = "gp-native-runtime-${package.pname}"; nodes.machine = { - environment.systemPackages = [ package hostCollector ]; + imports = [ module ]; + programs.globalprotect-openconnect = { enable = true; inherit package; }; + environment.systemPackages = [ hostCollector ]; users.users.alice = { isNormalUser = true; uid = 1000; }; - security.polkit.enable = true; security.polkit.extraConfig = '' polkit.addRule(function(action, subject) { if (subject.user == "alice" && ( @@ -50,6 +51,7 @@ pkgs.testers.runNixOSTest { import base64 import json import shlex + from datetime import timedelta machine.start() machine.wait_for_unit("polkit.service") @@ -62,11 +64,12 @@ pkgs.testers.runNixOSTest { command = "GP_GUI_BINARY=${guiProbe} " + package + "/bin/gpclient --lock-file /tmp/gp-client.lock launch-gui" as_alice(command + " > /tmp/gp-client-output 2>&1 & echo $! > /tmp/gp-client-pid") try: - machine.wait_until_succeeds("test -s /tmp/gp-gui-ready", timeout=30) - finally: + machine.wait_until_succeeds("test -s /tmp/gp-gui-ready", timeout=timedelta(seconds=30)) + except Exception: print(machine.succeed("cat /tmp/gp-client-output")) print(machine.succeed("cat /home/alice/.local/share/gpclient/gpclient.log 2>/dev/null || true")) print(machine.succeed("journalctl -u polkit --no-pager")) + raise service_pid = machine.succeed("cut -d: -f1 /var/run/gpservice.lock").strip() machine.succeed("test $(stat -c %u /proc/" + service_pid + ") = 0") as_alice("kill -TERM $(cat /tmp/gp-client-pid)")