fix: truly fixing xray tun
This commit is contained in:
6 files changed
+392
-49
No files matched your search
+147
-17
@@ -276,6 +276,64 @@ let
|
||||
xrayPerAppTunCleanupScript = builtins.readFile (
|
||||
xrayFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig.ExecStopPost
|
||||
);
|
||||
xrayStartBackendJqFilterFile = shellValueByPrefix xrayStartScript "BACKEND_JQ_FILTER=";
|
||||
xrayTunBackendJqFilterFile = shellValueByPrefix xrayTunStartScript "BACKEND_JQ_FILTER=";
|
||||
xrayPerAppTunBackendJqFilterFile = shellValueByPrefix xrayPerAppTunStartScript "BACKEND_JQ_FILTER=";
|
||||
xrayBackendJqFilter = builtins.readFile xrayTunBackendJqFilterFile;
|
||||
xrayDnsLocalClient = xrayFixture.config.services.proxy-suite.proxy.dns.local.address;
|
||||
xrayDnsRemoteClient = xrayFixture.config.services.proxy-suite.proxy.dns.remote.address;
|
||||
xrayTunConfigJson = pkgs.writeText "proxy-suite-xray-tun-check.json" (builtins.toJSON xrayTunConfig);
|
||||
xrayPerAppTunConfigJson =
|
||||
pkgs.writeText "proxy-suite-xray-per-app-tun-check.json" (builtins.toJSON xrayPerAppTunConfig);
|
||||
xrayJqFilterRuntimeCheck = pkgs.runCommand "proxy-suite-xray-jq-filter-runtime-check" { nativeBuildInputs = [ pkgs.jq ]; } ''
|
||||
OBS='[{"protocol":"freedom","tag":"proxy-suite-ob-primary"}]'
|
||||
|
||||
check_runtime() {
|
||||
local name="$1"
|
||||
local input="$2"
|
||||
local output="$TMPDIR/$name.json"
|
||||
|
||||
jq \
|
||||
--argjson obs "$OBS" \
|
||||
--argjson auth_enabled false \
|
||||
--arg user "" \
|
||||
--arg password "" \
|
||||
--argjson route_enabled true \
|
||||
--argjson route_rules '[]' \
|
||||
--arg route_final "proxy" \
|
||||
--arg dns_final "remote" \
|
||||
--argjson clear_dns_rules false \
|
||||
--arg xray_loglevel "" \
|
||||
--arg xray_bind_interface "eth0" \
|
||||
--arg xray_single_proxy_tag "proxy-suite-ob-primary" \
|
||||
--argjson xray_tun_dns_runtime true \
|
||||
--arg xray_dns_local_client ${pkgs.lib.escapeShellArg xrayDnsLocalClient} \
|
||||
--arg xray_dns_remote_client ${pkgs.lib.escapeShellArg xrayDnsRemoteClient} \
|
||||
-f ${pkgs.lib.escapeShellArg xrayTunBackendJqFilterFile} \
|
||||
"$input" > "$output"
|
||||
|
||||
jq -e \
|
||||
--arg remote ${pkgs.lib.escapeShellArg xrayDnsRemoteClient} \
|
||||
--arg local ${pkgs.lib.escapeShellArg xrayDnsLocalClient} \
|
||||
'
|
||||
type == "object"
|
||||
and (.dns.servers | length) >= 3
|
||||
and .dns.servers[0].tag == "fakedns"
|
||||
and ([.routing.rules[] | select((.ruleTag? // "") == "dns-hijack")] | length) == 1
|
||||
and ([.routing.rules[] | select((.ruleTag? // "") == "dns-upstream-direct")] | length) == 1
|
||||
and ([.outbounds[] | select(.tag == "proxy-suite-ob-primary" and (.streamSettings.sockopt.interface? // "") == "eth0")] | length) == 1
|
||||
and ([.outbounds[] | select(.tag == "dns-out" and ((.streamSettings.sockopt.interface? // "") == ""))] | length) == 1
|
||||
and ([.inbounds[] | select(.tag == "tun-in") | .settings.dns] | length) == 1
|
||||
and ([.inbounds[] | select(.tag == "tun-in") | .settings.dns][0] == [$remote, $local])
|
||||
and ((.routing | has("balancers")) | not)
|
||||
and ((has("observatory")) | not)
|
||||
' "$output" >/dev/null
|
||||
}
|
||||
|
||||
check_runtime global ${pkgs.lib.escapeShellArg xrayTunConfigJson}
|
||||
check_runtime per-app ${pkgs.lib.escapeShellArg xrayPerAppTunConfigJson}
|
||||
touch "$out"
|
||||
'';
|
||||
xraySubscriptionFixture = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
@@ -399,6 +457,8 @@ let
|
||||
routeModeStartScript = builtins.readFile (
|
||||
routeModeFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
routeModeBackendJqFilterFile = shellValueByPrefix routeModeStartScript "BACKEND_JQ_FILTER=";
|
||||
routeModeBackendJqFilter = builtins.readFile routeModeBackendJqFilterFile;
|
||||
routeModeRules = mkRouteModeRules routeModeFixture;
|
||||
|
||||
tgSecretFile = evalProxySuite [
|
||||
@@ -1090,6 +1150,8 @@ let
|
||||
localProxyAuthStartScript = builtins.readFile (
|
||||
localProxyAuthFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
localProxyAuthBackendJqFilterFile = shellValueByPrefix localProxyAuthStartScript "BACKEND_JQ_FILTER=";
|
||||
localProxyAuthBackendJqFilter = builtins.readFile localProxyAuthBackendJqFilterFile;
|
||||
|
||||
localProxyAuthPasswordFileFixture = evalProxySuite [
|
||||
baseModule
|
||||
@@ -1600,9 +1662,11 @@ let
|
||||
# -- proxy.auth: authenticated mixed inbound is injected at runtime --
|
||||
(
|
||||
assert pkgs.lib.hasInfix ''LOCAL_PROXY_PASSWORD="$(cat "'' localProxyAuthStartScript;
|
||||
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" localProxyAuthStartScript;
|
||||
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' localProxyAuthStartScript;
|
||||
assert pkgs.lib.hasInfix ''--arg user local-user'' localProxyAuthStartScript;
|
||||
assert pkgs.lib.hasInfix ''--arg password "$LOCAL_PROXY_PASSWORD"'' localProxyAuthStartScript;
|
||||
assert pkgs.lib.hasInfix ''select(.type == "mixed" and .tag == "mixed-in") | .users'' localProxyAuthStartScript;
|
||||
assert pkgs.lib.hasInfix ''select(.type == "mixed" and .tag == "mixed-in") | .users'' localProxyAuthBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix ''chmod 600 "$RUNTIME_DIR/config.json"'' localProxyAuthStartScript;
|
||||
true
|
||||
)
|
||||
@@ -1685,6 +1749,9 @@ let
|
||||
balancer = builtins.head xrayTproxyConfig.routing.balancers;
|
||||
in
|
||||
assert xrayFixture.config.services.proxy-suite.proxy.xray.enable;
|
||||
assert builtins.any (
|
||||
warning: pkgs.lib.hasInfix "XRay backend is still in test mode" warning
|
||||
) xrayFixture.config.warnings;
|
||||
assert xrayFixture.config.systemd.services ? "proxy-suite-socks";
|
||||
assert xrayFixture.config.systemd.services ? "proxy-suite-tproxy";
|
||||
assert xrayFixture.config.systemd.services ? "proxy-suite-tun";
|
||||
@@ -1717,44 +1784,104 @@ let
|
||||
tunDirectOutbound = builtins.head (
|
||||
builtins.filter (outbound: outbound.tag == "direct") xrayTunConfig.outbounds
|
||||
);
|
||||
perAppTunDirectOutbound = builtins.head (
|
||||
builtins.filter (outbound: outbound.tag == "direct") xrayPerAppTunConfig.outbounds
|
||||
);
|
||||
tunDnsOutbound = builtins.head (
|
||||
builtins.filter (outbound: outbound.tag == "dns-out") xrayTunConfig.outbounds
|
||||
);
|
||||
tunHasFinalRuleTag = builtins.any (rule: (rule ? ruleTag) && rule.ruleTag == "final-default") xrayTunConfig.routing.rules;
|
||||
tunHasDirectGeositeRule = builtins.any (rule: (rule ? ruleTag) && rule.ruleTag == "direct-geosite") xrayTunConfig.routing.rules;
|
||||
tunHasDnsHijackRule = builtins.any (rule: (rule ? ruleTag) && rule.ruleTag == "dns-hijack") xrayTunConfig.routing.rules;
|
||||
tunHasDnsUpstreamRule = builtins.any (rule: (rule ? ruleTag) && rule.ruleTag == "dns-upstream-direct") xrayTunConfig.routing.rules;
|
||||
in
|
||||
assert tunInbound.protocol == "tun";
|
||||
assert tunInbound.settings.name == "singtun0";
|
||||
assert tunInbound.settings.gateway == [ "172.19.0.1/30" ];
|
||||
assert tunInbound.settings.gateway == [ "172.19.0.1/30" "fd66:19::1/64" ];
|
||||
assert builtins.length tunInbound.settings.dns == 2;
|
||||
assert tunInbound.settings.autoOutboundsInterface == "auto";
|
||||
assert !(tunInbound.sniffing ? routeOnly);
|
||||
assert xrayTunConfig.routing.domainStrategy == "AsIs";
|
||||
assert tunInbound.sniffing.destOverride == [ "fakedns" ];
|
||||
assert tunInbound.sniffing.metadataOnly == true;
|
||||
assert xrayTunConfig.routing.domainStrategy == "IPIfNonMatch";
|
||||
assert tunHasFinalRuleTag;
|
||||
assert tunHasDirectGeositeRule;
|
||||
assert tunHasDnsHijackRule;
|
||||
assert tunHasDnsUpstreamRule;
|
||||
assert xrayTunConfig.dns.queryStrategy == "UseIP";
|
||||
assert xrayTunConfig.dns.tag == "dns-in";
|
||||
assert (builtins.head xrayTunConfig.dns.servers).address == "fakedns";
|
||||
assert (builtins.head xrayTunConfig.dns.servers).tag == "fakedns";
|
||||
assert (builtins.elemAt xrayTunConfig.dns.servers 1).tag == "remote";
|
||||
assert (builtins.elemAt xrayTunConfig.dns.servers 2).tag == "local";
|
||||
assert builtins.length xrayTunConfig.fakedns == 2;
|
||||
assert tunDnsOutbound.protocol == "dns";
|
||||
assert tunDnsOutbound.settings.rules == [ { action = "direct"; qType = "2-27,29-65535"; } ];
|
||||
assert tunDirectOutbound.streamSettings.sockopt.mark == 2;
|
||||
assert xrayStartBackendJqFilterFile == xrayTunBackendJqFilterFile;
|
||||
assert xrayTunBackendJqFilterFile == xrayPerAppTunBackendJqFilterFile;
|
||||
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" xrayStartScript;
|
||||
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' xrayStartScript;
|
||||
assert pkgs.lib.hasInfix "xray-loglevel" xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix "XRAY_SINGLE_PROXY_TAG=" xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix "ip -4 route get 1.1.1.1" xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix ".streamSettings.sockopt.interface = $interface" xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix "del(.routing.balancers)" xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix "del(.observatory)" xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix "xray_rewrite_proxy_rule" xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix "xray_tun_dns_runtime" xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix "xray_preserved_rules" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "dns-upstream-direct" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "xray_tun_dns_addresses" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "dns-hijack" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix ".streamSettings.sockopt.interface = $interface" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "del(.routing.balancers)" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "del(.observatory)" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "xray_rewrite_proxy_rule" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix ".protocol == \"dns\"" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix ''tun_route_prefix="$(cidr_network "$tun_cidr")"'' xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix "fd66:19::1/64" xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''uplink_addr="$('' xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''addr replace "$tun_cidr" dev singtun0'' xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''-6 addr replace "$tun6_cidr" dev singtun0'' xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''route replace "$tun_route_prefix" dev singtun0 src "$tun_addr" table 2022'' xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''route replace default dev singtun0 src "$uplink_addr" table 2022'' xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''-6 route replace "$tun6_route_prefix" dev singtun0 table 2022'' xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''-6 route replace default dev singtun0 table 2022'' xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix "rule add pref 8996 fwmark 17 table 102" xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix "rule add pref 8997 fwmark 16 table 101" xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix "rule add pref 9000 not fwmark 2 table 2022" xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix "-6 rule add pref 8997 fwmark 16 table 101" xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix "-6 rule add pref 9000 not fwmark 2 table 2022" xrayTunUpScript;
|
||||
assert perAppTunInbound.settings.name == "psperapptun0";
|
||||
assert perAppTunInbound.settings.gateway == [ "172.20.0.1/30" ];
|
||||
assert !(perAppTunInbound.sniffing ? routeOnly);
|
||||
assert xrayPerAppTunConfig.routing.domainStrategy == "AsIs";
|
||||
assert perAppTunInbound.settings.gateway == [ "172.20.0.1/30" "fd66:20::1/64" ];
|
||||
assert builtins.length perAppTunInbound.settings.dns == 2;
|
||||
assert perAppTunInbound.sniffing.destOverride == [ "fakedns" ];
|
||||
assert perAppTunInbound.sniffing.metadataOnly == true;
|
||||
assert xrayPerAppTunConfig.routing.domainStrategy == "IPIfNonMatch";
|
||||
assert (builtins.head xrayPerAppTunConfig.dns.servers).address == "fakedns";
|
||||
assert xrayPerAppTunConfig.dns.tag == "dns-in";
|
||||
assert builtins.length xrayPerAppTunConfig.fakedns == 2;
|
||||
assert perAppTunDirectOutbound.streamSettings.sockopt.mark == 2;
|
||||
assert pkgs.lib.hasInfix "XRAY_SINGLE_PROXY_TAG=" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix "ip -4 route get 1.1.1.1" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix ".streamSettings.sockopt.interface = $interface" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix "del(.routing.balancers)" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix "del(.observatory)" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix "--routing-mark 2" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix "xray_tun_dns_runtime" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix ".streamSettings.sockopt.interface = $interface" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "del(.routing.balancers)" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "del(.observatory)" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix ''tun_route_prefix="$(cidr_network "$tun_cidr")"'' xrayPerAppTunUpScript;
|
||||
assert pkgs.lib.hasInfix "fd66:20::1/64" xrayPerAppTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''uplink_addr="$('' xrayPerAppTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''addr replace "$tun_cidr" dev psperapptun0'' xrayPerAppTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''-6 addr replace "$tun6_cidr" dev psperapptun0'' xrayPerAppTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''route replace "$tun_route_prefix" dev psperapptun0 src "$tun_addr" table 101'' xrayPerAppTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''route flush table 101'' xrayPerAppTunCleanupScript;
|
||||
assert pkgs.lib.hasInfix ''route replace default dev psperapptun0 src "$uplink_addr" table 101'' xrayPerAppTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''-6 route replace "$tun6_route_prefix" dev psperapptun0 table 101'' xrayPerAppTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''-6 route replace default dev psperapptun0 table 101'' xrayPerAppTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''-6 rule add fwmark 16 table 101'' xrayPerAppTunUpScript;
|
||||
assert pkgs.lib.hasInfix ''-4 route flush table 101'' xrayPerAppTunCleanupScript;
|
||||
assert pkgs.lib.hasInfix ''-6 route flush table 101'' xrayPerAppTunCleanupScript;
|
||||
assert pkgs.lib.hasInfix "resolvectl flush-caches" xrayPerAppTunCleanupScript;
|
||||
true
|
||||
)
|
||||
(
|
||||
@@ -2235,10 +2362,12 @@ let
|
||||
# -- runtime route mode: socks start script includes all override branches and uses volatile state --
|
||||
(
|
||||
assert pkgs.lib.hasInfix ''ROUTE_MODE_STATE_FILE="/run/proxy-suite/route-mode"'' routeModeStartScript;
|
||||
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" routeModeStartScript;
|
||||
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' routeModeStartScript;
|
||||
assert pkgs.lib.hasInfix ''all-proxy)'' routeModeStartScript;
|
||||
assert pkgs.lib.hasInfix ''all-bypass)'' routeModeStartScript;
|
||||
assert pkgs.lib.hasInfix ''.route.rules = $route_rules'' routeModeStartScript;
|
||||
assert pkgs.lib.hasInfix ''.dns.rules = []'' routeModeStartScript;
|
||||
assert pkgs.lib.hasInfix ''.route.rules = $route_rules'' routeModeBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix ''.dns.rules = []'' routeModeBackendJqFilter;
|
||||
true
|
||||
)
|
||||
|
||||
@@ -2722,6 +2851,7 @@ in
|
||||
{
|
||||
proxy-suite-module = builtins.seq validated (pkgs.writeText "proxy-suite-module-check" "ok");
|
||||
proxy-suite-tray-build = suitePkgs.proxy-suite-tray;
|
||||
xray-jq-filter-runtime = xrayJqFilterRuntimeCheck;
|
||||
|
||||
zapret-hostlist-rules = pkgs.runCommand "proxy-suite-zapret-hostlist-rules-check" { } ''
|
||||
grep -F -- '--hostlist="${zapretSyncExtraListsBase}/hostlists/list-twitter.txt"' "${zapretSyncExtraListsBase}/config"
|
||||
|
||||
Reference in new issue
Block a user