feat: warp endpoint; fix: hardening
This commit is contained in:
32 files changed
+266
-381
No files matched your search
@@ -1,342 +0,0 @@
|
||||
{
|
||||
pkgs,
|
||||
checkLib,
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (checkLib)
|
||||
ok
|
||||
mkRouting
|
||||
evalProxySuite
|
||||
mkRoutingRules
|
||||
mkRouteModeRules
|
||||
mkTProxyConfig
|
||||
mkTunConfig
|
||||
mkPerAppTunConfig
|
||||
mkInboundsConfig
|
||||
mkInboundsSpec
|
||||
mkTProxyNftRules
|
||||
mkNftRules
|
||||
mkPerAppZapretNftRules
|
||||
mkPerAppUserRules
|
||||
hasDirectDomain
|
||||
hasDirectIP
|
||||
hasRuleSet
|
||||
dnsHasRuleSet
|
||||
dnsServerByTag
|
||||
mkZapretBaseFor
|
||||
mkZapretBase
|
||||
packagePathMatches
|
||||
shellValueByPrefix
|
||||
baseModule
|
||||
mkBadFixture
|
||||
mkBadFixtureRaw
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
rejects
|
||||
rejectsProxySuite
|
||||
mkProxyCtlDerived
|
||||
;
|
||||
|
||||
minimal = evalProxySuite [ baseModule ];
|
||||
checkConstants =
|
||||
(import ../../modules/proxy-suite/derived.nix {
|
||||
lib = pkgs.lib;
|
||||
cfg = minimal.config.services.proxy-suite;
|
||||
}).constants;
|
||||
_minimalProxyCtl = mkProxyCtlDerived minimal;
|
||||
minimalProxyCtlWrapper = _minimalProxyCtl.wrapper;
|
||||
minimalProxyCtlScript = _minimalProxyCtl.script;
|
||||
minimalSocksService = minimal.config.systemd.services."proxy-suite-socks";
|
||||
|
||||
coreProxyChecks = import ./core-proxy.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
minimal
|
||||
mkRoutingRules
|
||||
mkTProxyConfig
|
||||
hasRuleSet
|
||||
dnsHasRuleSet
|
||||
dnsServerByTag
|
||||
;
|
||||
};
|
||||
inherit (coreProxyChecks) ruDefaultConfig;
|
||||
|
||||
routeModeChecks = import ./route-mode.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkRouteModeRules
|
||||
shellValueByPrefix
|
||||
minimalProxyCtlWrapper
|
||||
minimalProxyCtlScript
|
||||
;
|
||||
};
|
||||
|
||||
subscriptionChecks = import ./subscriptions.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkBadFixtureRaw
|
||||
mkFailingAssertions
|
||||
mkProxyCtlDerived
|
||||
minimal
|
||||
;
|
||||
};
|
||||
|
||||
guiChecks = import ./gui.nix {
|
||||
inherit
|
||||
evalProxySuite
|
||||
baseModule
|
||||
packagePathMatches
|
||||
;
|
||||
};
|
||||
|
||||
localProxyAuthChecks = import ./local-proxy-auth.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkProxyCtlDerived
|
||||
shellValueByPrefix
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
ruDefaultConfig
|
||||
;
|
||||
};
|
||||
|
||||
sshProxyChecks = import ./ssh-proxy.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
mkRoutingRules
|
||||
;
|
||||
};
|
||||
|
||||
warpChecks = import ./warp.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
;
|
||||
};
|
||||
|
||||
torChecks = import ./tor.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
mkRouting
|
||||
mkTunConfig
|
||||
mkTProxyConfig
|
||||
mkInboundsSpec
|
||||
mkInboundsConfig
|
||||
mkProxyCtlDerived
|
||||
;
|
||||
};
|
||||
|
||||
proxyInboundsChecks = import ./proxy-inbounds.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkInboundsConfig
|
||||
mkInboundsSpec
|
||||
;
|
||||
};
|
||||
|
||||
perAppRoutingChecks = import ./per-app-routing.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkProxyCtlDerived
|
||||
mkPerAppUserRules
|
||||
mkPerAppZapretNftRules
|
||||
mkPerAppTunConfig
|
||||
dnsServerByTag
|
||||
mkZapretBase
|
||||
mkZapretBaseFor
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
rejects
|
||||
minimalProxyCtlScript
|
||||
;
|
||||
};
|
||||
|
||||
outboundValidationChecks = import ./outbound-validation.nix {
|
||||
inherit mkBadProxySuiteFixture mkFailingAssertions;
|
||||
};
|
||||
chainingDnsChecks = import ./chaining-dns.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkTunConfig
|
||||
mkTProxyConfig
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
;
|
||||
};
|
||||
|
||||
amneziaWgChecks = import ./amnezia-wg.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
rejectsProxySuite
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
mkProxyCtlDerived
|
||||
;
|
||||
};
|
||||
|
||||
amneziaWgOutboundChecks = import ./amnezia-wg-outbound.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
mkProxyCtlDerived
|
||||
mkTProxyConfig
|
||||
dnsServerByTag
|
||||
;
|
||||
};
|
||||
|
||||
globalProxyModeChecks = import ./global-proxy-modes.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
mkTunConfig
|
||||
mkTProxyConfig
|
||||
mkTProxyNftRules
|
||||
mkNftRules
|
||||
dnsServerByTag
|
||||
checkConstants
|
||||
;
|
||||
};
|
||||
|
||||
zapretChecks = import ./zapret.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkRoutingRules
|
||||
mkZapretBase
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
hasDirectDomain
|
||||
hasDirectIP
|
||||
;
|
||||
};
|
||||
|
||||
zapret2Checks = import ./zapret2.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkProxyCtlDerived
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
;
|
||||
};
|
||||
|
||||
tgWsProxyChecks = import ./tg-ws-proxy.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkRoutingRules
|
||||
mkTProxyNftRules
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
hasDirectIP
|
||||
minimal
|
||||
minimalSocksService
|
||||
;
|
||||
zapretSyncService = zapretChecks.syncService;
|
||||
};
|
||||
|
||||
serverModuleChecks = import ./server-module.nix {
|
||||
inherit checkLib pkgs mkInboundsSpec;
|
||||
inherit (checkLib) system nixpkgs proxySuiteModule;
|
||||
};
|
||||
|
||||
xrayBackendChecks = import ./xray-backends.nix {
|
||||
inherit checkLib;
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkTProxyConfig
|
||||
mkTunConfig
|
||||
mkPerAppTunConfig
|
||||
shellValueByPrefix
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
dnsServerByTag
|
||||
checkConstants
|
||||
;
|
||||
};
|
||||
|
||||
validated = builtins.all (x: x) (
|
||||
[
|
||||
(ok (minimal.config.services.proxy-suite.proxy.listener.address == "127.0.0.1"))
|
||||
]
|
||||
++ coreProxyChecks.assertions
|
||||
++ localProxyAuthChecks.assertions
|
||||
++ sshProxyChecks.assertions
|
||||
++ warpChecks.assertions
|
||||
++ torChecks.assertions
|
||||
++ proxyInboundsChecks.assertions
|
||||
++ tgWsProxyChecks.assertions
|
||||
++ xrayBackendChecks.assertions
|
||||
++ outboundValidationChecks.assertions
|
||||
++ chainingDnsChecks.assertions
|
||||
++ amneziaWgChecks.assertions
|
||||
++ amneziaWgOutboundChecks.assertions
|
||||
++ zapretChecks.assertions
|
||||
++ zapret2Checks.assertions
|
||||
++ globalProxyModeChecks.assertions
|
||||
++ guiChecks.assertions
|
||||
++ subscriptionChecks.assertions
|
||||
++ routeModeChecks.assertions
|
||||
++ perAppRoutingChecks.assertions
|
||||
++ serverModuleChecks.assertions
|
||||
);
|
||||
in
|
||||
{
|
||||
_groups = { inherit coreProxyChecks localProxyAuthChecks sshProxyChecks warpChecks torChecks proxyInboundsChecks tgWsProxyChecks xrayBackendChecks outboundValidationChecks chainingDnsChecks amneziaWgChecks amneziaWgOutboundChecks zapretChecks zapret2Checks globalProxyModeChecks guiChecks subscriptionChecks routeModeChecks perAppRoutingChecks serverModuleChecks ; minimalOk = { assertions = [ (ok (minimal.config.services.proxy-suite.proxy.listener.address == "127.0.0.1")) ]; }; };
|
||||
proxy-suite-module = builtins.seq validated (pkgs.writeText "proxy-suite-module-check" "ok");
|
||||
amneziawg-secret-manifest = amneziaWgChecks.manifest;
|
||||
xray-jq-filter-runtime = xrayBackendChecks.runtime;
|
||||
tor-guard-runtime = torChecks.runtime;
|
||||
per-app-zapret-runtime = perAppRoutingChecks.runtime;
|
||||
zapret-hostlist-rules = zapretChecks.rules;
|
||||
zapret2-config = zapret2Checks.runtime;
|
||||
proxy-suite-gui-build = _minimalProxyCtl.proxyCtl.gui;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ in
|
||||
localDns = dnsServerByTag ruDefaultConfig "local";
|
||||
remoteDns = dnsServerByTag ruDefaultConfig "remote";
|
||||
in
|
||||
assert localDns.type == "udp";
|
||||
assert localDns.type == "tcp";
|
||||
assert localDns.server == "1.1.1.1";
|
||||
assert localDns.server_port == 53;
|
||||
assert !(localDns ? detour);
|
||||
|
||||
@@ -189,10 +189,10 @@ in
|
||||
perAppRoutingZapretWithoutGlobalFixture.config.systemd.services ? "proxy-suite-per-app-zapret";
|
||||
assert
|
||||
perAppRoutingZapretWithoutGlobalFixture.config.systemd.services
|
||||
? "proxy-suite-per-app-zapret-user@";
|
||||
? "proxy-suite-per-app-zapret-user@";
|
||||
assert
|
||||
perAppRoutingZapretWithoutGlobalFixture.config.systemd.user.services
|
||||
? "proxy-suite-per-app-zapret-anchor";
|
||||
? "proxy-suite-per-app-zapret-anchor";
|
||||
assert !(perAppRoutingZapretWithoutGlobalFixture.config.systemd.services ? "proxy-suite-zapret");
|
||||
assert builtins.length perAppRoutingZapretWithoutGlobalProfiles == 2;
|
||||
assert builtins.any (
|
||||
|
||||
@@ -591,7 +591,12 @@ let
|
||||
(ok ((ruleByTag exitConfig "inbound-final").outboundTag == "direct"))
|
||||
|
||||
# Safety rules come first.
|
||||
(ok (lib.take 2 (ruleTags relayConfig) == [ "inbound-stats-api" "inbound-block-private" ]))
|
||||
(ok (
|
||||
lib.take 2 (ruleTags relayConfig) == [
|
||||
"inbound-stats-api"
|
||||
"inbound-block-private"
|
||||
]
|
||||
))
|
||||
(ok ((ruleByTag relayConfig "inbound-block-private").outboundTag == "block"))
|
||||
(ok ((ruleByTag relayConfig "inbound-block-ru-domain").domain == [ "geosite:category-ru" ]))
|
||||
(ok ((ruleByTag relayConfig "inbound-block-ru-ip").ip == [ "geoip:ru" ]))
|
||||
|
||||
@@ -57,6 +57,37 @@ in
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
# The tree as `nix fmt` leaves it.
|
||||
nix-format =
|
||||
pkgs.runCommand "proxy-suite-nix-format-check" { nativeBuildInputs = [ pkgs.nixfmt ]; }
|
||||
''
|
||||
cd ${
|
||||
pkgs.lib.fileset.toSource {
|
||||
root = ../..;
|
||||
fileset = pkgs.lib.fileset.fileFilter (file: file.hasExt "nix") ../..;
|
||||
}
|
||||
}
|
||||
find . -name '*.nix' -print0 | xargs -0 nixfmt --check
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
# Pyflakes and bugbear over every script and front end, as ruff.toml configures them.
|
||||
python-lint =
|
||||
pkgs.runCommand "proxy-suite-python-lint-check" { nativeBuildInputs = [ pkgs.ruff ]; }
|
||||
''
|
||||
cd ${
|
||||
pkgs.lib.fileset.toSource {
|
||||
root = ../..;
|
||||
fileset = pkgs.lib.fileset.unions [
|
||||
../../ruff.toml
|
||||
(pkgs.lib.fileset.fileFilter (file: file.hasExt "py") ../..)
|
||||
];
|
||||
}
|
||||
}
|
||||
ruff check --no-cache .
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
proxy-ctl-subscription-list =
|
||||
pkgs.runCommand "proxy-suite-proxy-ctl-subscription-list-check"
|
||||
{
|
||||
|
||||
+41
-1
@@ -67,6 +67,10 @@ let
|
||||
fixture:
|
||||
generated.readDerivation fixture.config.systemd.services."proxy-suite-warp".serviceConfig.ExecStart;
|
||||
autoRegister = registerOf auto;
|
||||
endpointed = mkFixture "sing-box" {
|
||||
asOutbound = "singBox";
|
||||
endpoint = "[2606:4700:d0::a29f:c001]:500";
|
||||
};
|
||||
generatorRegister = registerOf generator;
|
||||
|
||||
amneziaWg = mkProxySuite {
|
||||
@@ -79,7 +83,29 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
amneziaWgEndpoint = mkProxySuite {
|
||||
enable = true;
|
||||
amneziaWg.enable = true;
|
||||
warp = {
|
||||
enable = true;
|
||||
configFile = profile;
|
||||
asAmneziaWg = true;
|
||||
endpoint = "162.159.192.1:500";
|
||||
};
|
||||
};
|
||||
|
||||
invalidAssertions = mkFailingAssertions mkBadProxySuiteFixture [
|
||||
# An IPv6 endpoint without brackets.
|
||||
{
|
||||
enable = true;
|
||||
warp = {
|
||||
enable = true;
|
||||
configFile = profile;
|
||||
asOutbound = "singBox";
|
||||
endpoint = "2606:4700:d0::a29f:c001:500";
|
||||
};
|
||||
proxy.enable = true;
|
||||
}
|
||||
# Enabled but used for nothing.
|
||||
{
|
||||
enable = true;
|
||||
@@ -182,7 +208,7 @@ in
|
||||
# The resolver comes from proxy.dns.local; sing-box's "local" server fails behind resolved.
|
||||
(
|
||||
assert
|
||||
hasInfix ''{"server":"1.1.1.1","server_port":53,"tag":"local","type":"udp"}'' singBoxTunnel
|
||||
hasInfix ''{"server":"1.1.1.1","server_port":53,"tag":"local","type":"tcp"}'' singBoxTunnel
|
||||
&& !(hasInfix ''type: "local"'' singBoxTunnel);
|
||||
true
|
||||
)
|
||||
@@ -242,6 +268,20 @@ in
|
||||
assert !(amneziaWg.config.systemd.services ? "proxy-suite-warp-tunnel");
|
||||
true
|
||||
)
|
||||
# endpoint replaces the profile's Endpoint at conversion; the sing-box tunnel gets it quoted.
|
||||
(
|
||||
assert
|
||||
hasInfix "--endpoint '[2606:4700:d0::a29f:c001]:500' < \"$profile\"" (tunnelOf endpointed)
|
||||
&& !(hasInfix "--endpoint" singBoxTunnel);
|
||||
true
|
||||
)
|
||||
(
|
||||
assert
|
||||
amneziaWgEndpoint.config.services.proxy-suite.amneziaWg.profiles.warp.endpoint
|
||||
== "162.159.192.1:500"
|
||||
&& amneziaWg.config.services.proxy-suite.amneziaWg.profiles.warp.endpoint == null;
|
||||
true
|
||||
)
|
||||
]
|
||||
++ invalidAssertions;
|
||||
}
|
||||
+10
-2
@@ -102,8 +102,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
|
||||
@@ -242,6 +241,15 @@ in
|
||||
test "$(grep -c 'mark and 0x10000000 != 0 return' "$hook")" = 4
|
||||
grep -q 'nft insert rule inet $ZAPRET_NFT_TABLE prenat mark and 0x10000000 != 0 return' "$hook"
|
||||
|
||||
# --- store paths ------------------------------------------------------
|
||||
# Every path a config names is a build input. One that lost its string context
|
||||
# is missing from the closure, and from this sandbox under lazy trees.
|
||||
for config in ${globalRuntime}/config ${perAppRuntime}/config ${z2kRuntime}/config; do
|
||||
for path in $(grep -oE '/nix/store/[a-z0-9]{32}-[^ :"/]+' "$config" | sort -u); do
|
||||
test -e "$path" || { echo "$config names $path, which is not in the sandbox" >&2; exit 1; }
|
||||
done
|
||||
done
|
||||
|
||||
# --- the command line nfqws2 receives ---
|
||||
# Expand <HOSTLIST> with zapret2's list.sh and let nfqws2 validate the result,
|
||||
# Lua included; the strategy state layer gets a writable directory.
|
||||
|
||||
Reference in new issue
Block a user