feat(wl): runtime auth
This commit is contained in:
10 files changed
+222
-34
No files matched your search
@@ -24,6 +24,7 @@ in
|
||||
"autoProxy"
|
||||
"zapret"
|
||||
"stats"
|
||||
"whitelistBypass"
|
||||
]
|
||||
);
|
||||
default = [ ];
|
||||
@@ -37,6 +38,7 @@ in
|
||||
- "autoProxy": read what autoProxy learned, and `proxy auto learn|forget|relearn|clear`.
|
||||
- "zapret": edit zapret2's learned hosts, and `zapret cutoff probe`.
|
||||
- "stats": `inbounds stats`.
|
||||
- "whitelistBypass": the whitelist-bypass creators and joiners: `wl on|off|toggle|restart`, their calls (`wl link`), and their logins and links (`wl auth|join|new`).
|
||||
'';
|
||||
example = [
|
||||
"services"
|
||||
|
||||
@@ -17,10 +17,13 @@ let
|
||||
};
|
||||
|
||||
linkFile = mkOption {
|
||||
type = types.str;
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to the call link the creator printed (or wrote to its state directory):
|
||||
a WB Stream room id, a Telemost link, a DION event slug or a Bitrix conference link.
|
||||
`proxy-ctl wl join <name> <link>` sets one at runtime, which wins over this. Null
|
||||
leaves the joiner off until then.
|
||||
'';
|
||||
example = "/run/secrets/whitelist-bypass-link";
|
||||
};
|
||||
@@ -45,12 +48,14 @@ let
|
||||
};
|
||||
|
||||
cookiesFile = mkOption {
|
||||
type = types.str;
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to the platform's cookies, as the upstream desktop Creator exports them.
|
||||
Copied into the state directory on first start only: DION and Bitrix rotate their
|
||||
refresh token into that copy, and a stale one would kill the session. Delete
|
||||
`<stateDir>/whitelist-bypass/<name>.cookies.json` to take a new export.
|
||||
refresh token into that copy, and a stale one would kill the session.
|
||||
`proxy-ctl wl auth <name>` replaces that copy at runtime, with a new export or, for
|
||||
DION and Bitrix, an email and password. Null leaves the creator off until then.
|
||||
'';
|
||||
example = "/run/secrets/whitelist-bypass-cookies-wbstream.json";
|
||||
};
|
||||
@@ -61,7 +66,8 @@ let
|
||||
description = ''
|
||||
Runtime path to the call to rejoin. Null rejoins the last call written to
|
||||
`<stateDir>/whitelist-bypass/<name>.link`, and creates one on first start: the link
|
||||
stays the same across restarts, so the joiner needs it only once.
|
||||
stays the same across restarts, so the joiner needs it only once. `proxy-ctl wl new
|
||||
<name>` drops it for a new call, when the platform has closed the old one.
|
||||
'';
|
||||
example = "/run/secrets/whitelist-bypass-link";
|
||||
};
|
||||
|
||||
@@ -80,6 +80,8 @@ in
|
||||
inherit name;
|
||||
inherit (c) platform;
|
||||
role = "creator";
|
||||
# Set in the configuration: `wl new` cannot drop it.
|
||||
fixedLink = c.linkFile != null;
|
||||
}) cfg.whitelistBypass.creators
|
||||
++ lib.mapAttrsToList (name: j: {
|
||||
inherit name;
|
||||
|
||||
@@ -14,6 +14,7 @@ let
|
||||
"proxy-suite-autoproxy-learn." = "autoProxy";
|
||||
"proxy-suite-zapret2-cutoff." = "zapret";
|
||||
"proxy-suite-inbound-stats." = "stats";
|
||||
"proxy-suite-wb-" = "whitelistBypass";
|
||||
};
|
||||
in
|
||||
{
|
||||
|
||||
@@ -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 "- -"} -"
|
||||
];
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user