feat(wl): runtime auth

This commit is contained in:
fufsob committed 2026-09-25 04:57:30 +00:00
1 parent f3e9140f62
commit ba5f960b2e
10 files changed
+222 -34

No files matched your search

+41 -15
View File
@@ -9,7 +9,7 @@
let
w = derived.whitelistBypassCfg;
inherit (derived.constants) unprivilegedServiceConfig;
inherit (derived.constants) unprivilegedServiceConfig privileged serviceUser;
inherit (derived.localProxy) auth;
# Every flag that takes the call, joiner and creator alike.
@@ -32,6 +32,18 @@ let
else
null;
# Logins, calls and the links joiners take at runtime (`proxy-ctl wl auth|join|new`); the
# whitelistBypass scope's group writes them too. tmpfiles makes it before any unit has run,
# so a creator or joiner that waits on a file there can be given one.
groupAccess = privileged && derived.userControlAllows "whitelistBypass";
stateDir = "${derived.constants.stateDir}/whitelist-bypass";
stateMode = if groupAccess then "0770" else "0700";
stateGroup = if groupAccess then cfg.userControl.group else serviceUser;
# A runtime file the unit cannot start without, when nothing in the configuration stands in.
waitFor = file: {
unitConfig.ConditionPathExists = "%S/proxy-suite/whitelist-bypass/${file}";
};
# Restart=always must not trip the start limit while the network or the platform is down.
mkUnit = description: serviceConfig: {
inherit description;
@@ -44,22 +56,29 @@ let
// {
Restart = "always";
RestartSec = 5;
StateDirectory = "proxy-suite/whitelist-bypass";
StateDirectoryMode = stateMode;
}
// lib.optionalAttrs groupAccess { Group = stateGroup; }
// serviceConfig;
};
# The link `wl join` gave it wins over linkFile.
mkJoiner =
j:
lib.nameValuePair "proxy-suite-wb-joiner-${j.tag}" (
mkUnit "proxy-suite - whitelist-bypass joiner ${j.tag}" {
ExecStart = pkgs.writeShellScript "proxy-suite-wb-joiner-${j.tag}" ''
set -euo pipefail
link=$(tr -d '[:space:]' < "$CREDENTIALS_DIRECTORY/link")
join="$STATE_DIRECTORY/${j.tag}.join"
${lib.optionalString (j.linkFile != null) ''[ -e "$join" ] || join="$CREDENTIALS_DIRECTORY/link"''}
link=$(tr -d '[:space:]' < "$join")
exec ${w.package}/bin/headless-${j.platform}-joiner \
${joinerLinkFlag.${j.platform}} "$link" --socks-port ${toString j.port}
'';
LoadCredential = [ "link:${j.linkFile}" ];
LoadCredential = lib.optional (j.linkFile != null) "link:${j.linkFile}";
}
// lib.optionalAttrs (j.linkFile == null) (waitFor "${j.tag}.join")
);
mkCreator =
@@ -72,7 +91,9 @@ let
set -euo pipefail
cookies="$STATE_DIRECTORY/${name}.cookies.json"
links="$STATE_DIRECTORY/${name}.link"
[ -e "$cookies" ] || install -m 600 "$CREDENTIALS_DIRECTORY/cookies" "$cookies"
${lib.optionalString (c.cookiesFile != null) ''
[ -e "$cookies" ] || install -m 600 "$CREDENTIALS_DIRECTORY/cookies" "$cookies"
''}
args=(--cookies "$cookies" --write-file "$links" --resources ${c.resources})
${
if c.linkFile != null then
@@ -88,21 +109,26 @@ let
''}
exec ${w.package}/bin/headless-${c.platform}-creator "''${args[@]}"
'';
StateDirectory = "proxy-suite/whitelist-bypass";
StateDirectoryMode = "0700";
LoadCredential = [
"cookies:${c.cookiesFile}"
]
++ lib.optional (c.linkFile != null) "link:${c.linkFile}"
++ lib.optional withProxyAuth "proxy-password:${passwordSource}";
LoadCredential =
lib.optional (c.cookiesFile != null) "cookies:${c.cookiesFile}"
++ lib.optional (c.linkFile != null) "link:${c.linkFile}"
++ lib.optional withProxyAuth "proxy-password:${passwordSource}";
};
in
lib.nameValuePair "proxy-suite-wb-creator-${name}" (
unit // lib.optionalAttrs viaProxy { after = unit.after ++ [ "proxy-suite-socks.service" ]; }
unit
// lib.optionalAttrs viaProxy { after = unit.after ++ [ "proxy-suite-socks.service" ]; }
# Without a login it has nothing to run on until `proxy-ctl wl auth` writes one.
// lib.optionalAttrs (c.cookiesFile == null) (waitFor "${name}.cookies.json")
);
in
{
services.proxy-suite.internal.services = lib.listToAttrs (
map mkJoiner derived.whitelistBypassJoiners ++ lib.mapAttrsToList mkCreator w.creators
);
services.proxy-suite.internal = {
services = lib.listToAttrs (
map mkJoiner derived.whitelistBypassJoiners ++ lib.mapAttrsToList mkCreator w.creators
);
tmpfiles = [
"d ${stateDir} ${stateMode} ${if privileged then "${serviceUser} ${stateGroup}" else "- -"} -"
];
};
}