feat(wip): amnezia-wg 3.1 support

This commit is contained in:
FUFSoB committed 2026-08-30 18:07:43 +05:00
1 parent 539f6a13ee
commit a456534801
29 files changed
+4092 -12

No files matched your search

+6
View File
@@ -33,10 +33,16 @@ let
controlModuleSource = builtins.readFile ../modules/proxy-suite/service/control.nix;
};
moduleSuiteChecks = import ./checks/module-suite.nix { inherit pkgs checkLib; };
amneziaWgRuntime = import ./checks/amnezia-wg-runtime.nix {
inherit pkgs nixpkgs proxySuiteModule;
};
in
moduleSuiteChecks
// {
proxy-suite-tray-build = suitePkgs.proxy-suite-tray;
}
// pkgs.lib.optionalAttrs (system == "x86_64-linux") {
amneziawg-runtime = amneziaWgRuntime;
}
// parserChecks
// repoChecks
+133
View File
@@ -0,0 +1,133 @@
{
pkgs,
nixpkgs,
proxySuiteModule,
}:
let
keys = import "${nixpkgs}/nixos/tests/wireguard/snakeoil-keys.nix";
awgPackages = import ../../pkgs/amneziawg.nix { inherit pkgs; };
obfuscation = {
jc = 5;
jmin = 10;
jmax = 42;
s1 = 60;
s2 = 90;
};
network = address: {
networking.useDHCP = false;
networking.interfaces.eth1.ipv4.addresses = [
{
inherit address;
prefixLength = 24;
}
];
};
client =
address: userspaceOnly:
{
imports = [ proxySuiteModule ];
services.proxy-suite = {
enable = true;
amneziaWg = {
enable = true;
kernelModulePackage =
if userspaceOnly then null else awgPackages.kernelModule pkgs.linuxPackages;
profiles.test = {
interfaceName = "awg-test";
settings = {
addresses = [ "10.23.42.2/32" ];
privateKey = keys.peer1.privateKey;
inherit obfuscation;
peers = [
{
publicKey = keys.peer0.publicKey;
endpoint = "192.168.0.1:23542";
allowedIPs = [ "10.23.42.1/32" ];
persistentKeepalive = 5;
}
];
};
};
profiles.broken = {
interfaceName = "awg-broken";
settings = {
addresses = [ "10.99.42.2/32" ];
privateKey = keys.peer1.privateKey;
inherit obfuscation;
peers = [
{
publicKey = keys.peer0.publicKey;
endpoint = "192.168.0.254:23542";
allowedIPs = [ "10.99.42.1/32" ];
}
];
};
};
};
};
}
// network address;
in
pkgs.testers.runNixOSTest {
name = "proxy-suite-amneziawg-runtime";
nodes = {
server =
{ ... }:
{
imports = [ (network "192.168.0.1") ];
networking.firewall.allowedUDPPorts = [ 23542 ];
networking.wg-quick.interfaces.awg-server = {
type = "amneziawg";
address = [ "10.23.42.1/32" ];
listenPort = 23542;
privateKey = keys.peer0.privateKey;
extraOptions = {
Jc = obfuscation.jc;
Jmin = obfuscation.jmin;
Jmax = obfuscation.jmax;
S1 = obfuscation.s1;
S2 = obfuscation.s2;
};
peers = [
{
publicKey = keys.peer1.publicKey;
allowedIPs = [ "10.23.42.2/32" ];
}
];
};
};
kernel = client "192.168.0.2" false;
userspace = client "192.168.0.3" true;
};
testScript = ''
start_all()
server.wait_for_unit("wg-quick-awg-server.service")
with subtest("packaged kernel module"):
kernel.succeed("systemctl start proxy-suite-awg-test.service")
kernel.succeed("ip -d link show awg-test | grep -q amneziawg")
kernel.succeed("ping -c 5 10.23.42.1")
kernel.succeed("test $(awg show awg-test latest-handshakes | awk '{print $2}') -gt 0")
kernel.succeed("systemctl stop proxy-suite-awg-test.service")
kernel.fail("ip link show awg-test")
with subtest("automatic userspace fallback"):
userspace.fail("modprobe -n amneziawg")
userspace.succeed("systemctl start proxy-suite-awg-test.service")
userspace.succeed("test -r /sys/class/net/awg-test/tun_flags")
userspace.succeed("ping -c 5 10.23.42.1")
userspace.succeed("test $(awg show awg-test latest-handshakes | awk '{print $2}') -gt 0")
userspace.succeed("systemctl stop proxy-suite-awg-test.service")
userspace.fail("ip link show awg-test")
with subtest("failed handshake rolls back userspace routing"):
userspace.fail("systemctl start proxy-suite-awg-broken.service")
userspace.fail("ip link show awg-broken")
userspace.fail("ip route show table all | grep -F awg-broken")
userspace.fail("ip -6 route show table all | grep -F awg-broken")
'';
}
+331
View File
@@ -0,0 +1,331 @@
{
pkgs,
evalProxySuite,
mkBadProxySuiteFixture,
mkFailingAssertions,
mkProxyCtlDerived,
}:
let
generated = import ./read-generated.nix;
defaultPackages = evalProxySuite [
{
system.stateVersion = "26.05";
services.proxy-suite = {
enable = true;
amneziaWg = {
enable = true;
profiles.home.configFile = "/run/secrets/awg.conf";
};
};
}
];
awgOnly = evalProxySuite [
{
system.stateVersion = "26.05";
services.proxy-suite = {
enable = true;
amneziaWg = {
enable = true;
kernelModulePackage = null;
profiles = {
home = {
autostart = true;
settings = {
addresses = [ "10.8.0.2/32" ];
privateKeyFile = "/run/secrets/awg-private";
obfuscation = {
s1 = 12;
s2 = 12;
s3 = 12;
s4 = 12;
h1 = "100-200";
headerProtectionKeyFile = "/run/secrets/awg-header";
rekeyAfterTime = "120-180";
};
peers = [
{
publicKey = "public";
presharedKeyFile = "/run/secrets/awg-psk";
allowedIPs = [
"0.0.0.0/0"
"::/0"
];
endpoint = "vpn.example.com:51820";
persistentKeepalive = "20-30";
advancedSecurity = true;
}
];
};
};
work = {
configFile = "/run/secrets/work-awg.conf";
};
};
};
};
}
];
homeService = awgOnly.config.systemd.services.proxy-suite-awg-home;
workService = awgOnly.config.systemd.services.proxy-suite-awg-work;
ctl = mkProxyCtlDerived awgOnly;
sourceFixture = evalProxySuite [
{
system.stateVersion = "26.05";
services.proxy-suite = {
enable = true;
amneziaWg = {
enable = true;
kernelModulePackage = null;
profiles = {
conf.configFile = "/run/secrets/client.conf";
file.vpnFile = "/run/secrets/client.vpn";
inline.vpn = "vpn://ZW1iZWRkZWQ";
nix.settings = {
addresses = [ "10.0.0.2/32" ];
privateKey = "inline-private";
peers = [
{
publicKey = "public";
allowedIPs = [ "10.0.0.1/32" ];
}
];
};
};
};
};
}
];
fakeTools = pkgs.writeShellScriptBin "awg-quick" "exit 0";
fakeUserspace = pkgs.writeShellScriptBin "amneziawg-go" "exit 0";
fakeKernelModule = pkgs.runCommand "fake-amneziawg-module" { } ''
mkdir -p "$out/lib/modules"
'';
overrideFixture = evalProxySuite [
{
system.stateVersion = "26.05";
services.proxy-suite = {
enable = true;
amneziaWg = {
enable = true;
toolsPackage = fakeTools;
userspacePackage = fakeUserspace;
kernelModulePackage = fakeKernelModule;
profiles.home.configFile = "/run/secrets/client.conf";
};
};
}
];
withGlobalTun = evalProxySuite [
{
system.stateVersion = "26.05";
services.proxy-suite = {
enable = true;
proxy = {
enable = true;
singBox.enable = true;
outbounds = [
{
tag = "primary";
url = "http://proxy.example.com:8080";
}
];
tun.enable = true;
tproxy.enable = true;
};
zapret = {
enable = true;
perApp.enable = true;
};
amneziaWg = {
enable = true;
kernelModulePackage = null;
profiles.home.configFile = "/run/secrets/awg.conf";
};
};
}
];
withGlobalAwgService = withGlobalTun.config.systemd.services.proxy-suite-awg-home;
withGlobalAwgStartPre = withGlobalAwgService.serviceConfig.ExecStartPre;
withGlobalAwgBypassUp = generated.readDerivation (builtins.elemAt withGlobalAwgStartPre 1);
withGlobalAwgBypassDown = generated.readDerivation withGlobalAwgService.serviceConfig.ExecStopPost;
in
{
assertions = [
(
assert !awgOnly.config.services.proxy-suite.proxy.enable;
assert homeService.serviceConfig.RuntimeDirectoryMode == "0700";
assert homeService.serviceConfig.UMask == "0077";
assert builtins.elem "multi-user.target" homeService.wantedBy;
assert builtins.elem "proxy-suite-awg-work.service" homeService.conflicts;
assert builtins.elem "proxy-suite-tun.service" homeService.conflicts;
assert builtins.elem "proxy-suite-tproxy.service" homeService.conflicts;
assert builtins.elem "zapret-discord-youtube.service" homeService.conflicts;
assert builtins.elem "proxy-suite-per-app-zapret.service" homeService.conflicts;
assert workService.wantedBy == [ ];
assert homeService.serviceConfig.NoNewPrivileges;
assert builtins.length homeService.serviceConfig.ExecStartPre == 1;
assert !(homeService.serviceConfig ? ExecStopPost);
true
)
(
assert builtins.elem awgOnly.config.services.proxy-suite.amneziaWg.toolsPackage
awgOnly.config.environment.systemPackages;
assert builtins.elem awgOnly.config.services.proxy-suite.amneziaWg.userspacePackage
awgOnly.config.environment.systemPackages;
assert awgOnly.config.services.proxy-suite.amneziaWg.toolsPackage.version == "3.1.20260812";
assert awgOnly.config.services.proxy-suite.amneziaWg.userspacePackage.version == "3.1.20260828";
assert pkgs.lib.hasInfix "cmd_awg" ctl.script;
assert
ctl.awgProfiles == [
"home"
"work"
];
true
)
(
assert defaultPackages.config.services.proxy-suite.amneziaWg.toolsPackage.version == "3.1.20260812";
assert
defaultPackages.config.services.proxy-suite.amneziaWg.userspacePackage.version == "3.1.20260828";
assert
defaultPackages.config.services.proxy-suite.amneziaWg.kernelModulePackage.version == "3.1.20260812";
true
)
(
assert
sourceFixture.config.services.proxy-suite.amneziaWg.profiles.conf.configFile
== "/run/secrets/client.conf";
assert
sourceFixture.config.services.proxy-suite.amneziaWg.profiles.file.vpnFile
== "/run/secrets/client.vpn";
assert
sourceFixture.config.services.proxy-suite.amneziaWg.profiles.inline.vpn == "vpn://ZW1iZWRkZWQ";
assert
sourceFixture.config.services.proxy-suite.amneziaWg.profiles.nix.settings.privateKey
== "inline-private";
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"
awgOnly.config.security.polkit.extraConfig;
true
)
(
assert builtins.elem "proxy-suite-awg-home.service"
withGlobalTun.config.systemd.services.proxy-suite-tun.conflicts;
assert builtins.elem "proxy-suite-awg-home.service"
withGlobalTun.config.systemd.services.proxy-suite-tproxy.conflicts;
assert builtins.elem "proxy-suite-awg-home.service"
withGlobalTun.config.systemd.services.zapret-discord-youtube.conflicts;
assert builtins.elem "proxy-suite-awg-home.service"
withGlobalTun.config.systemd.services.proxy-suite-per-app-zapret.conflicts;
assert builtins.elem "proxy-suite-socks.service" withGlobalAwgService.after;
assert builtins.elem "proxy-suite-socks.service" withGlobalAwgService.wants;
assert builtins.length withGlobalAwgStartPre == 2;
assert pkgs.lib.hasInfix "rule add" withGlobalAwgBypassUp;
assert pkgs.lib.hasInfix "pref 8998" withGlobalAwgBypassUp;
assert pkgs.lib.hasInfix "fwmark 2 lookup main" withGlobalAwgBypassUp;
assert pkgs.lib.hasInfix "unable to install the AWG proxy-backend bypass rule"
withGlobalAwgBypassUp;
assert pkgs.lib.hasInfix "rule del" withGlobalAwgBypassDown;
assert pkgs.lib.hasInfix "pref 8998" withGlobalAwgBypassDown;
assert pkgs.lib.hasInfix "fwmark 2 lookup main" withGlobalAwgBypassDown;
true
)
]
++ mkFailingAssertions mkBadProxySuiteFixture [
{
enable = true;
amneziaWg.enable = true;
}
{
enable = true;
amneziaWg = {
enable = true;
kernelModulePackage = null;
profiles.home = {
configFile = "/run/a.conf";
vpnFile = "/run/a.vpn";
};
};
}
{
enable = true;
amneziaWg = {
enable = true;
kernelModulePackage = null;
profiles = {
one = {
autostart = true;
configFile = "/run/one.conf";
};
two = {
autostart = true;
configFile = "/run/two.conf";
};
};
};
}
{
enable = true;
amneziaWg = {
enable = true;
kernelModulePackage = null;
profiles = {
one = {
interfaceName = "awg-shared";
configFile = "/run/one.conf";
};
two = {
interfaceName = "awg-shared";
configFile = "/run/two.conf";
};
};
};
}
{
enable = true;
amneziaWg = {
enable = true;
kernelModulePackage = null;
profiles.home.settings = {
addresses = [ "10.8.0.2/32" ];
peers = [
{
publicKey = "public";
allowedIPs = [ "0.0.0.0/0" ];
}
];
};
};
}
{
enable = true;
proxy = {
enable = true;
singBox.enable = true;
outbounds = [
{
tag = "primary";
url = "http://proxy.example.com:8080";
}
];
tun = {
enable = true;
autostart = true;
};
};
amneziaWg = {
enable = true;
kernelModulePackage = null;
profiles.home = {
autostart = true;
configFile = "/run/home.conf";
};
};
}
];
}
+1
View File
@@ -213,6 +213,7 @@ let
profiles = builtins.fromJSON (generated.readDerivation metadata.perAppRoutingProfilesFile);
subscriptionTags = builtins.fromJSON (generated.readDerivation metadata.subscriptionTagsFile);
inherit (metadata) proxychainsConfigFile;
awgProfiles = builtins.fromJSON (generated.readDerivation metadata.amneziaWgProfileNamesFile);
};
in
{
+11
View File
@@ -126,6 +126,16 @@ let
inherit mkBadProxySuiteFixture mkFailingAssertions;
};
amneziaWgChecks = import ./amnezia-wg.nix {
inherit
pkgs
evalProxySuite
mkBadProxySuiteFixture
mkFailingAssertions
mkProxyCtlDerived
;
};
globalProxyModeChecks = import ./global-proxy-modes.nix {
inherit
pkgs
@@ -196,6 +206,7 @@ let
++ tgWsProxyChecks.assertions
++ xrayBackendChecks.assertions
++ outboundValidationChecks.assertions
++ amneziaWgChecks.assertions
++ zapretChecks.assertions
++ globalProxyModeChecks.assertions
++ trayChecks.assertions
+9
View File
@@ -18,4 +18,13 @@
python ${../../scripts/test-fetch-subscription.py}
touch "$out"
'';
amneziawg-config-parser =
pkgs.runCommand "amneziawg-config-parser-check" { nativeBuildInputs = [ pkgs.python3 ]; }
''
export PYTHONDONTWRITEBYTECODE=1
export PYTHONPATH=${../../scripts}:$PYTHONPATH
python ${../../scripts/test-amneziawg-config.py}
touch "$out"
'';
}
+62
View File
@@ -87,6 +87,68 @@
touch "$out"
'';
proxy-ctl-amneziawg =
pkgs.runCommand "proxy-suite-proxy-ctl-amneziawg-check"
{
nativeBuildInputs = [
pkgs.bash
pkgs.coreutils
pkgs.gnugrep
pkgs.jq
];
}
''
proxy_ctl="$TMPDIR/proxy-ctl"
cat ${../../pkgs/proxy-ctl-lib.sh} ${../../pkgs/proxy-ctl.sh} > "$proxy_ctl"
chmod +x "$proxy_ctl"
mkdir -p bin
cat > bin/systemctl <<'SH'
#!${pkgs.bash}/bin/bash
case "$1" in
cat) exit 0 ;;
is-active)
if [ "''${3:-''${2:-}}" = "proxy-suite-awg-home" ] || [ "''${2:-}" = "proxy-suite-awg-home" ]; then
if [ "''${2:-}" != "--quiet" ]; then
echo active
fi
exit 0
fi
if [ "''${2:-}" != "--quiet" ]; then
echo inactive
fi
exit 3
;;
start|stop|restart)
printf '%s %s\n' "$1" "$2" >> "$SYSTEMCTL_LOG"
;;
esac
SH
chmod +x bin/systemctl
printf '%s\n' '["home","work"]' > awg-profiles.json
export PATH="$PWD/bin:$PATH"
export SYSTEMCTL_LOG="$PWD/systemctl.log"
export AWG_PROFILES_FILE="$PWD/awg-profiles.json"
bash "$proxy_ctl" awg list > list-output
grep -q 'home.*active' list-output
grep -q 'work.*inactive' list-output
test "$(bash "$proxy_ctl" awg status)" = home
bash "$proxy_ctl" awg on work
bash "$proxy_ctl" awg off home
bash "$proxy_ctl" awg restart home
grep -q '^start proxy-suite-awg-work$' "$SYSTEMCTL_LOG"
grep -q '^stop proxy-suite-awg-home$' "$SYSTEMCTL_LOG"
grep -q '^restart proxy-suite-awg-home$' "$SYSTEMCTL_LOG"
if bash "$proxy_ctl" awg on missing 2> error-output; then
exit 1
fi
grep -q 'Unknown AmneziaWG profile' error-output
touch "$out"
'';
readme-doc-source = builtins.seq (
assert !(pkgs.lib.hasInfix "environment.systemPackages" readmeDocSource);
assert !(pkgs.lib.hasInfix "packageByPattern" readmeDocSource);