feat: add connectivity fix options + hardening
This commit is contained in:
41 files changed
+626
-111
No files matched your search
@@ -1,6 +1,17 @@
|
||||
# Polkit rule body granting userControl group members passwordless control over the
|
||||
# units of their scopes.
|
||||
{ userControlCfg }:
|
||||
#
|
||||
# Only units this module declares, by their full names: systemd asks the same
|
||||
# manage-units question with the same unit name for a transient unit
|
||||
# (`systemd-run --unit=proxy-suite-x ...`), so a prefix match would run any command as
|
||||
# root. A declared unit has a fragment, and systemd refuses a transient one of its name.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
userControlCfg,
|
||||
# Declared system units, "name.service" or "name.timer"; templates as "name@".
|
||||
unitNames,
|
||||
}:
|
||||
|
||||
let
|
||||
# Units a narrower scope starts; every other proxy-suite unit is "services".
|
||||
@@ -20,11 +31,56 @@ let
|
||||
"proxy-suite-inbound-stats." = "stats";
|
||||
"proxy-suite-wb-" = "whitelistBypass";
|
||||
};
|
||||
templates = lib.filter (lib.hasSuffix "@") unitNames;
|
||||
units = lib.filter (name: !lib.hasSuffix "@" name) unitNames;
|
||||
# What proxy-ctl asks for; not kill, clean, set-property, freeze or thaw.
|
||||
verbs = [
|
||||
"start"
|
||||
"stop"
|
||||
"restart"
|
||||
"try-restart"
|
||||
"reload"
|
||||
"reload-or-restart"
|
||||
"reload-or-try-restart"
|
||||
"reset-failed"
|
||||
];
|
||||
in
|
||||
{
|
||||
userControlPolkitRules = ''
|
||||
var verb = action.lookup("verb");
|
||||
if (typeof unit !== "string" || ${builtins.toJSON verbs}.indexOf(verb) === -1) {
|
||||
return null;
|
||||
}
|
||||
var known = ${builtins.toJSON units}.indexOf(unit) !== -1;
|
||||
var templates = ${builtins.toJSON templates};
|
||||
for (var i = 0; !known && i < templates.length; i++) {
|
||||
var template = templates[i];
|
||||
if (unit.indexOf(template) !== 0) {
|
||||
continue;
|
||||
}
|
||||
var instance = unit.slice(template.length).replace(/\.service$/, "");
|
||||
if (!/^[A-Za-z0-9:_.\\-]+$/.test(instance) || unit !== template + instance + ".service") {
|
||||
continue;
|
||||
}
|
||||
// Per-app marking follows one user's apps: only that user's own instance.
|
||||
if (/-user@$/.test(template)) {
|
||||
try {
|
||||
var uid = polkit.spawn(["${pkgs.coreutils}/bin/id", "-u", "--", subject.user]).trim();
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
if (instance !== uid) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
known = true;
|
||||
}
|
||||
if (!known) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var scopeByUnitPrefix = ${builtins.toJSON scopeByUnitPrefix};
|
||||
var scope = unit.indexOf("proxy-suite-") === 0 ? "services" : null;
|
||||
var scope = "services";
|
||||
for (var prefix in scopeByUnitPrefix) {
|
||||
if (unit.indexOf(prefix) === 0) {
|
||||
scope = scopeByUnitPrefix[prefix];
|
||||
@@ -33,7 +89,7 @@ in
|
||||
}
|
||||
// No scopes listed means all of them.
|
||||
var scopes = ${builtins.toJSON userControlCfg.scopes};
|
||||
if (scope !== null && (scopes.length === 0 || scopes.indexOf(scope) !== -1)) {
|
||||
if (scopes.length === 0 || scopes.indexOf(scope) !== -1) {
|
||||
return polkit.Result.YES;
|
||||
}
|
||||
'';
|
||||
|
||||
Reference in new issue
Block a user