mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 22:46:14 -05:00
fix(nixos): enable the privileged pkexec wrapper
This commit is contained in:
4 files changed
+28
-7
No files matched your search
@@ -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
|
The module builds the package with your NixOS configuration's `pkgs`, so the
|
||||||
GlobalProtect GUI and the system use the same Nixpkgs dependency versions.
|
GlobalProtect GUI and the system use the same Nixpkgs dependency versions.
|
||||||
|
It also enables Polkit and its setuid `pkexec` wrapper for privileged operations.
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -304,6 +304,7 @@
|
|||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
|
options,
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
@@ -326,6 +327,11 @@
|
|||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
environment.systemPackages = [ cfg.package ];
|
environment.systemPackages = [ cfg.package ];
|
||||||
services.ayatana-indicators.enable = lib.mkDefault true;
|
services.ayatana-indicators.enable = lib.mkDefault true;
|
||||||
|
security.polkit = {
|
||||||
|
enable = true;
|
||||||
|
} // lib.optionalAttrs (options.security.polkit ? enablePkexecWrapper) {
|
||||||
|
enablePkexecWrapper = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
|||||||
+13
-2
@@ -41,7 +41,18 @@ in {
|
|||||||
prebuilt = prebuiltPackage;
|
prebuilt = prebuiltPackage;
|
||||||
module = assert builtins.elem modulePackage hostSystem.config.environment.systemPackages;
|
module = assert builtins.elem modulePackage hostSystem.config.environment.systemPackages;
|
||||||
assert hostSystem.config.services.ayatana-indicators.enable;
|
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;
|
modulePackage;
|
||||||
runtime-source = import ./tests/native-runtime.nix { inherit pkgs; package = sourcePackage; };
|
runtime-source = import ./tests/native-runtime.nix {
|
||||||
runtime-prebuilt = import ./tests/native-runtime.nix { inherit pkgs; package = prebuiltPackage; };
|
inherit pkgs;
|
||||||
|
package = sourcePackage;
|
||||||
|
module = gp.nixosModules.default;
|
||||||
|
};
|
||||||
|
runtime-prebuilt = import ./tests/native-runtime.nix {
|
||||||
|
inherit pkgs;
|
||||||
|
package = prebuiltPackage;
|
||||||
|
module = gp.nixosModules.default;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{ pkgs, package }:
|
{ pkgs, package, module }:
|
||||||
let
|
let
|
||||||
guiProbe = pkgs.writeScript "gpgui-runtime-probe" ''
|
guiProbe = pkgs.writeScript "gpgui-runtime-probe" ''
|
||||||
#!${pkgs.python3}/bin/python3
|
#!${pkgs.python3}/bin/python3
|
||||||
@@ -32,9 +32,10 @@ in
|
|||||||
pkgs.testers.runNixOSTest {
|
pkgs.testers.runNixOSTest {
|
||||||
name = "gp-native-runtime-${package.pname}";
|
name = "gp-native-runtime-${package.pname}";
|
||||||
nodes.machine = {
|
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; };
|
users.users.alice = { isNormalUser = true; uid = 1000; };
|
||||||
security.polkit.enable = true;
|
|
||||||
security.polkit.extraConfig = ''
|
security.polkit.extraConfig = ''
|
||||||
polkit.addRule(function(action, subject) {
|
polkit.addRule(function(action, subject) {
|
||||||
if (subject.user == "alice" && (
|
if (subject.user == "alice" && (
|
||||||
@@ -50,6 +51,7 @@ pkgs.testers.runNixOSTest {
|
|||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import shlex
|
import shlex
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
machine.start()
|
machine.start()
|
||||||
machine.wait_for_unit("polkit.service")
|
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"
|
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")
|
as_alice(command + " > /tmp/gp-client-output 2>&1 & echo $! > /tmp/gp-client-pid")
|
||||||
try:
|
try:
|
||||||
machine.wait_until_succeeds("test -s /tmp/gp-gui-ready", timeout=30)
|
machine.wait_until_succeeds("test -s /tmp/gp-gui-ready", timeout=timedelta(seconds=30))
|
||||||
finally:
|
except Exception:
|
||||||
print(machine.succeed("cat /tmp/gp-client-output"))
|
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("cat /home/alice/.local/share/gpclient/gpclient.log 2>/dev/null || true"))
|
||||||
print(machine.succeed("journalctl -u polkit --no-pager"))
|
print(machine.succeed("journalctl -u polkit --no-pager"))
|
||||||
|
raise
|
||||||
service_pid = machine.succeed("cut -d: -f1 /var/run/gpservice.lock").strip()
|
service_pid = machine.succeed("cut -d: -f1 /var/run/gpservice.lock").strip()
|
||||||
machine.succeed("test $(stat -c %u /proc/" + service_pid + ") = 0")
|
machine.succeed("test $(stat -c %u /proc/" + service_pid + ") = 0")
|
||||||
as_alice("kill -TERM $(cat /tmp/gp-client-pid)")
|
as_alice("kill -TERM $(cat /tmp/gp-client-pid)")
|
||||||
|
|||||||
Reference in new issue
Block a user