feat: warp endpoint; fix: hardening

This commit is contained in:
FUFSoB committed 2026-09-23 11:50:22 +05:00
1 parent 8f65fa9c25
commit 5f29f30790
32 files changed
+266 -381

No files matched your search

+9 -2
View File
@@ -80,6 +80,7 @@ let
allowConfigHooks = profile.allowConfigHooks;
vpnContainer = profile.vpnContainer;
}
// lib.optionalAttrs (profile.endpoint != null) { inherit (profile) endpoint; }
// source profile
)
);
@@ -145,7 +146,9 @@ let
if profile.asOutbound == "interface" then
" --outbound-fwmark ${toString cfg.proxy.tproxy.proxyMark}"
else
lib.optionalString (derived.killSwitchEnabled && profile.asOutbound == null) " --fwmark ${toString awgGlobalFwmark} --resolve-endpoints"
lib.optionalString (
derived.killSwitchEnabled && profile.asOutbound == null
) " --fwmark ${toString awgGlobalFwmark} --resolve-endpoints"
}
'';
@@ -169,7 +172,11 @@ let
configPath = runtimeConfig name profile;
prepare = pkgs.writeShellScript "proxy-suite-awg" ''
set -euo pipefail
${lib.optionalString (derived.killSwitchEnabled && !outbound) "${pkgs.util-linux}/bin/unshare --mount ${ownLookups} "}${prepareCommand profile (lib.escapeShellArg configPath)}
${
lib.optionalString (
derived.killSwitchEnabled && !outbound
) "${pkgs.util-linux}/bin/unshare --mount ${ownLookups} "
}${prepareCommand profile (lib.escapeShellArg configPath)}
'';
proxyBypassUp = pkgs.writeShellScript "proxy-suite-awg" ''
set -euo pipefail
+9
View File
@@ -18,6 +18,15 @@ in
default = null;
inherit description example;
};
# A WireGuard peer's host:port, IPv6 in brackets.
endpoint =
description:
mkOption {
type = types.nullOr (types.strMatching "(\\[[0-9A-Fa-f:.]+]|[^]:[]+):[0-9]+");
default = null;
example = "162.159.192.1:500";
inherit description;
};
bool =
default: description:
mkOption {
+14 -4
View File
@@ -13,11 +13,21 @@ in
options.services.proxy-suite.proxy.dns = {
local = mkOption {
type = t.dnsUpstreamType;
default = cloudflare;
description = "Resolver for direct traffic and the default domain resolver. Goes through the proxy in global TUN mode.";
example = {
# TCP: DPI boxes answer plain UDP queries to well-known resolvers themselves, with
# NXDOMAIN or a stub address for blocked names, so direct traffic (zapret's
# included) dials nothing. Not tls, which pure XRay lacks.
default = cloudflare // {
type = "tcp";
address = "9.9.9.9";
};
description = ''
Resolver for direct traffic and the default domain resolver. Goes through the proxy in
global TUN mode. TCP by default: plain UDP queries to well-known resolvers are often
answered by the ISP's DPI instead, which breaks blocked names routed direct to zapret.
'';
example = {
type = "tls";
address = "1.1.1.1";
port = 853;
};
};
@@ -3,6 +3,7 @@
let
inherit (lib) mkOption types;
inherit (import ../lib.nix { inherit lib; }) endpoint;
optionalString = types.nullOr types.str;
optionalUnsigned = types.nullOr types.ints.unsigned;
rangeValue = types.oneOf [
@@ -206,6 +207,7 @@ let
Either way the tunnel itself reaches the peer over the uplink, past TUN and TProxy.
'';
};
endpoint = endpoint "host:port (IPv6 in brackets) that replaces the first peer's Endpoint when the profile is prepared.";
allowConfigHooks = mkOption {
type = types.bool;
default = false;
+8
View File
@@ -2,6 +2,7 @@
let
inherit (lib) mkEnableOption mkOption types;
inherit (import ./lib.nix { inherit lib; }) endpoint;
in
{
options.services.proxy-suite.warp = {
@@ -35,6 +36,13 @@ in
example = "https://valokda-amnezia.vercel.app/api/warp?mode=awg2";
};
endpoint = endpoint ''
host:port that replaces the profile's Endpoint (IPv6 in brackets), for when the default
engage.cloudflareclient.com:2408 is blocked: another Cloudflare address, another port WARP
answers on (500, 1701, 4500, ...), or a relay. Applied in every mode when the tunnel or
AmneziaWG profile starts; the profile file itself is left as is.
'';
asOutbound = mkOption {
type = types.nullOr (
types.enum [
+1 -2
View File
@@ -948,8 +948,7 @@ let
(proxyEnabled && proxyCfg.listener.port == torCfg.socksPort)
|| (proxyInboundsEnabled && builtins.elem torCfg.socksPort derived.proxyInboundPorts)
|| builtins.elem torCfg.socksPort (
builtins.attrValues constants.xrayDnsBridgePorts
++ [ constants.outboundTestPort ]
builtins.attrValues constants.xrayDnsBridgePorts ++ [ constants.outboundTestPort ]
)
)
)
+3 -1
View File
@@ -103,7 +103,9 @@ let
umask 0077
torrc="$RUNTIME_DIRECTORY/torrc"
${pkgs.coreutils}/bin/mkdir -p -m ${if controlGroup then "0750" else "0700"} "$RUNTIME_DIRECTORY/control"
${pkgs.coreutils}/bin/mkdir -p -m ${
if controlGroup then "0750" else "0700"
} "$RUNTIME_DIRECTORY/control"
{
cat <<'TORRC'
${staticConfig}
+2 -1
View File
@@ -94,6 +94,7 @@ in
services.proxy-suite.amneziaWg.profiles = lib.mkIf (w.asAmneziaWg || viaAmneziaWg) {
warp = {
configFile = w.profilePath;
inherit (w) endpoint;
asOutbound = lib.mkIf viaAmneziaWg w.asOutbound;
};
};
@@ -111,7 +112,7 @@ in
until [ -s "$profile" ]; do sleep 5; done
fi
'';
inherit (w) tunnelPort directPort;
inherit (w) tunnelPort directPort endpoint;
};
})
+13 -3
View File
@@ -86,10 +86,13 @@ let
tag,
tunnelPort,
directPort,
endpoint,
}:
{
convert = ''
endpoint=$(${pkgs.python3}/bin/python3 ${scriptsDir}/warp_outbound.py --tag ${tag}${markArg "--routing-mark"} < "$profile")
endpoint=$(${pkgs.python3}/bin/python3 ${scriptsDir}/warp_outbound.py --tag ${tag}${markArg "--routing-mark"}${
lib.optionalString (endpoint != null) " --endpoint ${lib.escapeShellArg endpoint}"
} < "$profile")
(umask 027 && ${pkgs.jq}/bin/jq -n --argjson ep "$endpoint" '{
log: {level: "warn"},
dns: {servers: [
@@ -130,7 +133,8 @@ let
};
# `profile` is a shell snippet, run as root on a privileged host, that sets $profile to
# the WireGuard .conf. `engine` is "singBox" or "userspace"; only sing-box uses directPort.
# the WireGuard .conf. `engine` is "singBox" or "userspace"; only sing-box uses directPort,
# and `endpoint`, a host:port in place of the profile's Endpoint.
mkTunnel =
{
description,
@@ -139,11 +143,17 @@ let
profile,
tunnelPort,
directPort ? null,
endpoint ? null,
engine ? "singBox",
}:
let
chosen = (if engine == "userspace" then wireproxyEngine else singBoxEngine) {
inherit tag tunnelPort directPort;
inherit
tag
tunnelPort
directPort
endpoint
;
};
tunnelScript = pkgs.writeShellScript "proxy-suite-wg-tunnel" ''
set -euo pipefail
+3 -1
View File
@@ -67,11 +67,13 @@ let
zapret2Cfg.excludeDomains != [ ]
) "--hostlist-exclude-domains=${lib.concatStringsSep "," zapret2Cfg.excludeDomains}";
# lib.trim drops string context: without it the source's list paths are no build input,
# so lazy trees never materialize them and the closure omits them.
renderProfile =
profile:
lib.replaceStrings hostlistMarkers (map (
marker: marker + withSpaces staticListArgs
) hostlistMarkers) (lib.trim profile);
) hostlistMarkers) (lib.addContextFrom profile (lib.trim profile));
z2kGenerated = sources.z2k.mkProfiles {
hostlistSuffix = withSpaces staticListArgs;