move userControl to root options
This commit is contained in:
4 files changed
+261
-69
No files matched your search
@@ -331,6 +331,43 @@ in
|
||||
options.services.proxy-suite = {
|
||||
enable = mkEnableOption "proxy suite (sing-box + zapret + tg-ws-proxy)";
|
||||
|
||||
userControl = {
|
||||
group = mkOption {
|
||||
type = types.strMatching "^[a-z_][a-z0-9_-]*$";
|
||||
default = "proxy-suite";
|
||||
description = ''
|
||||
Local group allowed to use passwordless polkit-backed `proxy-ctl`
|
||||
commands when userControl.global.enable or userControl.perApp.enable
|
||||
is turned on.
|
||||
'';
|
||||
example = "proxy-suite";
|
||||
};
|
||||
|
||||
global.enable =
|
||||
(mkEnableOption "passwordless proxy-ctl control over global proxy-suite units")
|
||||
// {
|
||||
default = true;
|
||||
description = ''
|
||||
Whether members of userControl.group may manage global
|
||||
proxy-suite units without password prompts via commands like
|
||||
`proxy-ctl tun on|off`, `proxy-ctl tproxy on|off`,
|
||||
`proxy-ctl restart`, or `proxy-ctl subscription update`.
|
||||
'';
|
||||
};
|
||||
|
||||
perApp.enable =
|
||||
(mkEnableOption "passwordless proxy-ctl control over per-app routing helpers")
|
||||
// {
|
||||
default = true;
|
||||
description = ''
|
||||
Whether members of userControl.group may start and stop the
|
||||
app-scoped backend units used by `proxy-ctl wrap ...` for
|
||||
route = "tun", route = "tproxy", or route = "zapret" profiles
|
||||
without password prompts.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
singBox = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
@@ -1034,19 +1071,6 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
userControl = {
|
||||
group = mkOption {
|
||||
type = types.strMatching "^[a-z_][a-z0-9_-]*$";
|
||||
default = "proxy-suite";
|
||||
description = ''
|
||||
Local group allowed to start and stop app-routing backend units via
|
||||
polkit. Add desktop users who should be able to run
|
||||
`proxy-ctl wrap ...` for route = "tun", route = "tproxy", or
|
||||
route = "zapret" profiles to this group.
|
||||
'';
|
||||
example = "proxy-suite";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
zapret = {
|
||||
|
||||
@@ -18,9 +18,24 @@ let
|
||||
sb = cfg.singBox;
|
||||
t = cfg.tgWsProxy;
|
||||
ar = cfg.appRouting;
|
||||
uc = cfg.userControl;
|
||||
art = ar.backends.tun;
|
||||
artp = ar.backends.tproxy;
|
||||
arz = ar.backends.zapret;
|
||||
userControlEnabled = uc.global.enable || uc.perApp.enable;
|
||||
userControlPolkitRules =
|
||||
lib.optionalString uc.perApp.enable ''
|
||||
if (unit.indexOf("proxy-suite-app-") === 0) {
|
||||
return polkit.Result.YES;
|
||||
}
|
||||
''
|
||||
+ lib.optionalString uc.global.enable ''
|
||||
if ((unit.indexOf("proxy-suite-") === 0 &&
|
||||
unit.indexOf("proxy-suite-app-") !== 0) ||
|
||||
unit === "zapret-discord-youtube.service") {
|
||||
return polkit.Result.YES;
|
||||
}
|
||||
'';
|
||||
builtinTags = [
|
||||
"proxy"
|
||||
"direct"
|
||||
@@ -911,14 +926,14 @@ in
|
||||
# nftables must be on for TProxy to work.
|
||||
networking.nftables.enable = lib.mkIf (sb.tproxy.enable || art.enable || artp.enable || arz.enable) (lib.mkDefault true);
|
||||
|
||||
users.groups = lib.mkIf cfg.enable {
|
||||
"${ar.userControl.group}" = { };
|
||||
users.groups = lib.mkIf (cfg.enable && userControlEnabled) {
|
||||
"${uc.group}" = { };
|
||||
};
|
||||
|
||||
security.polkit.enable = lib.mkIf cfg.enable true;
|
||||
security.polkit.extraConfig = lib.mkIf cfg.enable (lib.mkAfter ''
|
||||
security.polkit.enable = lib.mkIf (cfg.enable && userControlEnabled) true;
|
||||
security.polkit.extraConfig = lib.mkIf (cfg.enable && userControlEnabled) (lib.mkAfter ''
|
||||
polkit.addRule(function(action, subject) {
|
||||
if (!subject.isInGroup("${ar.userControl.group}")) {
|
||||
if (!subject.isInGroup("${uc.group}")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -927,10 +942,7 @@ in
|
||||
}
|
||||
|
||||
var unit = action.lookup("unit");
|
||||
if (unit.indexOf("proxy-suite-") === 0 ||
|
||||
unit === "zapret-discord-youtube.service") {
|
||||
return polkit.Result.YES;
|
||||
}
|
||||
${userControlPolkitRules}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user