feat: add connectivity fix options + hardening
This commit is contained in:
41 files changed
+626
-111
No files matched your search
@@ -348,8 +348,12 @@ in
|
||||
assert builtins.elem fakeTools overrideFixture.config.environment.systemPackages;
|
||||
assert builtins.elem fakeUserspace overrideFixture.config.environment.systemPackages;
|
||||
assert builtins.elem fakeKernelModule overrideFixture.config.boot.extraModulePackages;
|
||||
assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-\") === 0"
|
||||
# userControl covers the profile's unit by name, never by prefix: a prefix would also
|
||||
# match a transient unit (systemd-run --unit=proxy-suite-x), which runs anything as root.
|
||||
assert pkgs.lib.hasInfix "\"proxy-suite-awg-home.service\""
|
||||
awgOnly.config.security.polkit.extraConfig;
|
||||
assert
|
||||
!(pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-\") === 0" awgOnly.config.security.polkit.extraConfig);
|
||||
true
|
||||
)
|
||||
(
|
||||
|
||||
@@ -99,7 +99,10 @@ in
|
||||
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;
|
||||
# From a pipe: argv is readable by every local user.
|
||||
assert pkgs.lib.hasInfix ''--rawfile password <(printf '%s' "$LOCAL_PROXY_PASSWORD")''
|
||||
localProxyAuthStartScript;
|
||||
assert !(pkgs.lib.hasInfix ''--arg password "$LOCAL_PROXY_PASSWORD"'' localProxyAuthStartScript);
|
||||
assert pkgs.lib.hasInfix ''select(.type == "mixed" and .tag == "mixed-in") | .users''
|
||||
localProxyAuthBackendJqFilter;
|
||||
# The password is in the config: root and the backend's group only.
|
||||
|
||||
@@ -127,10 +127,16 @@ let
|
||||
serverAddress = "vpn.example.com";
|
||||
serverAliases = [
|
||||
"turn.example.com"
|
||||
"domain:example.net"
|
||||
"203.0.113.10"
|
||||
"2001:db8::10"
|
||||
"vpn.example.com"
|
||||
];
|
||||
serverPorts = [
|
||||
993
|
||||
"7882-7885"
|
||||
443
|
||||
];
|
||||
listeners.vless-in = realityListener;
|
||||
};
|
||||
aliasedConfig = mkInboundsConfig aliasedFixture;
|
||||
@@ -834,6 +840,7 @@ let
|
||||
(ruleByTag aliasedConfig "inbound-server-address-direct").domain == [
|
||||
"full:vpn.example.com"
|
||||
"full:turn.example.com"
|
||||
"domain:example.net"
|
||||
];
|
||||
true
|
||||
)
|
||||
@@ -845,7 +852,9 @@ let
|
||||
];
|
||||
true
|
||||
)
|
||||
(ok ((ruleByTag aliasedConfig "inbound-server-address-direct-ip").port == "443"))
|
||||
# serverPorts join the listener's, ranges as they are.
|
||||
(ok ((ruleByTag aliasedConfig "inbound-server-address-direct").port == "443,993,7882-7885"))
|
||||
(ok ((ruleByTag aliasedConfig "inbound-server-address-direct-ip").port == "443,993,7882-7885"))
|
||||
(ok ((ruleByTag aliasedConfig "inbound-server-address-direct-ip").outboundTag == "direct"))
|
||||
(ok (!builtins.elem "inbound-block-ru-domain" (ruleTags unguardedConfig)))
|
||||
|
||||
|
||||
+1
-1
@@ -446,7 +446,7 @@ in
|
||||
printf 'AS12389\n' > "$state/cutoff/egress"
|
||||
printf '24940\n14061\n' > "$state/cutoff/asn.txt"
|
||||
printf '24940\t300.ya.ru\n' > "$state/cutoff/sni.txt"
|
||||
cutoff=$(env ZAPRET_CUTOFF_ENABLED=1 ZAPRET_STATE_DIR="$state" python3 "$proxy_ctl" zapret cutoff)
|
||||
cutoff=$(env ZAPRET_CUTOFF_ENABLED=1 ZAPRET_CUTOFF_DIR="$state/cutoff" python3 "$proxy_ctl" zapret cutoff)
|
||||
printf '%s\n' "$cutoff" | grep -q 'from AS12389$'
|
||||
printf '%s\n' "$cutoff" | grep -qx 'Cutoff: 2 network(s)'
|
||||
printf '%s\n' "$cutoff" | grep -qE '^ AS24940 +300\.ya\.ru$'
|
||||
|
||||
+1
-1
@@ -175,7 +175,7 @@ let
|
||||
);
|
||||
guardRuntime = pkgs.runCommand "proxy-suite-tor-guard-check" { nativeBuildInputs = [ pkgs.jq ]; } ''
|
||||
echo '{"inbounds":[],"outbounds":[],"dns":{"rules":[]},"route":{"rules":[]}}' |
|
||||
jq --argjson obs '[]' --argjson auth_enabled false --arg user "" --arg password "" \
|
||||
jq --slurpfile obs <(echo '[]') --argjson auth_enabled false --arg user "" --arg password "" \
|
||||
--argjson route_enabled true --argjson route_rules "$(cat ${guardRouteRules})" \
|
||||
--arg route_final proxy --arg dns_final remote --argjson clear_dns_rules false \
|
||||
--argjson probe_inbounds '[]' --argjson autoproxy_rule_sets '[]' --argjson autoproxy_rules '[]' \
|
||||
|
||||
@@ -78,6 +78,18 @@ in
|
||||
assert hasInfix "var scopes = [];" (polkitConfig allFixture);
|
||||
assert hasInfix "subject.isInGroup(\"proxy-suite\")" (polkitConfig allFixture);
|
||||
assert hasInfix "\"proxy-suite-zapret2-cutoff.\":\"zapret\"" (polkitConfig allFixture);
|
||||
# Declared units by name: systemd asks polkit the same question, with the same unit
|
||||
# name, for a transient unit, so a prefix match would run any command as root.
|
||||
assert hasInfix "\"proxy-suite-socks.service\"" (polkitConfig allFixture);
|
||||
assert hasInfix "\"proxy-suite-per-app-tun-user@\"" (polkitConfig allFixture);
|
||||
assert !(hasInfix "unit.indexOf(\"proxy-suite-\") === 0 ?" (polkitConfig allFixture));
|
||||
# Only start, stop and the like: not set-property, kill or clean.
|
||||
assert hasInfix "\"reload-or-try-restart\",\"reset-failed\"].indexOf(verb)" (
|
||||
polkitConfig allFixture
|
||||
);
|
||||
assert !(hasInfix "\"set-property\"" (polkitConfig allFixture));
|
||||
# A user's per-app marking is theirs alone.
|
||||
assert hasInfix "if (instance !== uid)" (polkitConfig allFixture);
|
||||
assert groupReadsSecrets allFixture;
|
||||
assert hasInfix "chown proxy-suite-daemon:proxy-suite \"$backend_config\"" (socksStart allFixture);
|
||||
assert
|
||||
@@ -87,6 +99,20 @@ in
|
||||
"proxy-suite"
|
||||
];
|
||||
assert (service allFixture "proxy-suite-autoproxy").StateDirectoryMode == "0771";
|
||||
# Root writes by fixed names in that group-writable directory: nowhere else.
|
||||
assert builtins.all
|
||||
(
|
||||
unit:
|
||||
let
|
||||
c = service allFixture unit;
|
||||
in
|
||||
c.ProtectSystem == "strict" && c.ProtectHome && c.PrivateTmp
|
||||
)
|
||||
[
|
||||
"proxy-suite-autoproxy"
|
||||
"proxy-suite-autoproxy-learn"
|
||||
"proxy-suite-autoproxy-sample"
|
||||
];
|
||||
assert builtins.elem "d /var/lib/proxy-suite/outbounds.d 2770 root proxy-suite -" (
|
||||
allFixture.config.systemd.tmpfiles.rules
|
||||
);
|
||||
|
||||
@@ -54,7 +54,7 @@ let
|
||||
local output="$TMPDIR/$name.json"
|
||||
|
||||
jq \
|
||||
--argjson obs "$OBS" \
|
||||
--slurpfile obs <(printf "%s" "$OBS") \
|
||||
--argjson auth_enabled false \
|
||||
--arg user "" \
|
||||
--arg password "" \
|
||||
|
||||
+25
-1
@@ -74,6 +74,24 @@ in
|
||||
true
|
||||
)
|
||||
|
||||
# Root works in directories the zapret scope's group writes to: nfqws2 and the cutoff
|
||||
# probe write nowhere else, whatever a name there points at. The probe's own directory
|
||||
# is root's alone, apart from requests/.
|
||||
(
|
||||
let
|
||||
gc = zapret2Global.config.systemd.services.${globalService}.serviceConfig;
|
||||
pc = zapret2PerApp.config.systemd.services.${perAppService}.serviceConfig;
|
||||
cc = zapret2Global.config.systemd.services.proxy-suite-zapret2-cutoff.serviceConfig;
|
||||
sandboxed = c: c.ProtectSystem == "strict" && c.ProtectHome && c.PrivateTmp;
|
||||
in
|
||||
assert sandboxed gc && sandboxed pc && sandboxed cc;
|
||||
assert cc.StateDirectory == "proxy-suite/zapret2-cutoff" && cc.StateDirectoryMode == "0755";
|
||||
assert !(cc ? Group);
|
||||
assert builtins.any (lib.hasPrefix "d /var/lib/proxy-suite/zapret2-cutoff/requests ")
|
||||
zapret2Global.config.systemd.tmpfiles.rules;
|
||||
true
|
||||
)
|
||||
|
||||
# Two nfqws2 processes must not share a pidfile or a config.
|
||||
(
|
||||
assert envValue zapret2PerApp globalService "PIDDIR=" == "/run/proxy-suite-zapret";
|
||||
@@ -102,7 +120,7 @@ in
|
||||
assert !(zapretDiscordYoutubeGlobal.config.systemd.services ? proxy-suite-zapret2-cutoff);
|
||||
assert (proxyCtlEnv zapret2Global).ZAPRET_CUTOFF_ENABLED == "1";
|
||||
assert
|
||||
envValue zapret2Z2k globalService "Z2K_TCP16_ASN=" == "/var/lib/proxy-suite/zapret2/cutoff/asn.txt";
|
||||
envValue zapret2Z2k globalService "Z2K_TCP16_ASN=" == "/var/lib/proxy-suite/zapret2-cutoff/asn.txt";
|
||||
assert
|
||||
!(builtins.any (lib.hasPrefix "Z2K_TCP16_ASN=")
|
||||
zapret2Global.config.systemd.services.${globalService}.serviceConfig.Environment
|
||||
@@ -206,6 +224,12 @@ in
|
||||
# zapret2 leaves the probe's own connections alone, in every chain.
|
||||
test "$(grep -c 'ct mark and 0x2000000 != 0 return' "${globalRuntime}/init.d/sysv/custom.d/50-proxy-suite-custom.sh")" = 4
|
||||
|
||||
# ts is checked for digits before arithmetic, which would run what a[$(...)] in it names.
|
||||
grep -qF -- '[[ $last =~ ^[0-9]+$ ]] || last=0' ${cutoffProbe}
|
||||
if grep -qF -- '$((now - $(cat ts' ${cutoffProbe}; then exit 1; fi
|
||||
# The group's probe request comes through requests/, not the directory root works in.
|
||||
grep -qF -- 'if [ -e requests/force ]; then' ${cutoffProbe}
|
||||
|
||||
# Cut-off networks without a name become the proxy's rule-set; named ones stay with zapret2.
|
||||
rules=$(grep -oE '/nix/store/[^ ]+-proxy-suite-zapret2 asn.txt' ${cutoffProbe} | cut -d' ' -f1)
|
||||
printf '# networks\n24940\n14061\n' >asn.txt
|
||||
|
||||
Reference in new issue
Block a user