refactor: users single-point
This commit is contained in:
35 files changed
+1009
-381
No files matched your search
@@ -270,6 +270,32 @@ lib.mkMerge [
|
||||
"proxy-suite: proxy.listener.address is ${proxyCfg.listener.address} without listener.auth:"
|
||||
+ " anyone who reaches the port uses your outbounds; set listener.auth, or keep it off the"
|
||||
+ " firewall's allowed ports"
|
||||
)
|
||||
# rules/proxy-inbounds.nix guards the names of this host only where XRay leaves names
|
||||
# unresolved, or where IP aliases catch a name that resolves here first.
|
||||
++
|
||||
lib.optional
|
||||
(
|
||||
proxyInboundsEnabled
|
||||
&& !derived.proxyInboundsResolveInSingBox
|
||||
# Only a listener whose traffic is not direct anyway loses anything by it.
|
||||
&& lib.any (
|
||||
ib:
|
||||
!builtins.elem ib.via [
|
||||
"direct"
|
||||
"block"
|
||||
]
|
||||
) derived.proxyInbounds
|
||||
&& (cfg.inbounds.serverAddress != null || cfg.inbounds.serverAliases != [ ])
|
||||
&& lib.all (a: lib.hasPrefix "domain:" a || builtins.match "[0-9.]+|.*:.*" a == null) (
|
||||
lib.optional (cfg.inbounds.serverAddress != null) cfg.inbounds.serverAddress
|
||||
++ cfg.inbounds.serverAliases
|
||||
)
|
||||
)
|
||||
(
|
||||
"proxy-suite: with a direct listener or the XRay backend, list this host's IPs in"
|
||||
+ " inbounds.serverAliases: without them a client can name this host in its TLS handshake"
|
||||
+ " while connecting to any other address, which XRay then dials direct, from this host"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ let
|
||||
buildOutboundPy
|
||||
proxyInboundsFile
|
||||
proxyInboundsSpecFile
|
||||
proxyInboundsSelfSources
|
||||
builders
|
||||
constants
|
||||
;
|
||||
@@ -33,6 +34,22 @@ let
|
||||
subscriptionsFile = "${runtimeDir}/subscriptions.json";
|
||||
subsCfg = proxyInboundsCfg.subscriptions;
|
||||
xray = "${proxyInboundsCfg.package}/bin/xray";
|
||||
|
||||
# inbounds.routing.serverSource: the users' own addresses toward this host, on a dummy
|
||||
# interface. Reached through lo like any local address; nothing routes out from them.
|
||||
ip = "${pkgs.iproute2}/bin/ip";
|
||||
selfInterface = lib.escapeShellArg proxyInboundsCfg.routing.serverSource.interface;
|
||||
selfInterfaceDown = "${ip} link del ${selfInterface} 2>/dev/null || true";
|
||||
selfInterfaceUp = lib.optionalString (proxyInboundsSelfSources != [ ]) ''
|
||||
${selfInterfaceDown}
|
||||
${ip} link add ${selfInterface} type dummy
|
||||
${ip} link set ${selfInterface} up
|
||||
${lib.concatMapStrings (
|
||||
s:
|
||||
lib.optionalString (s.ipv4 != null) "${ip} addr add ${s.ipv4}/32 dev ${selfInterface}\n"
|
||||
+ lib.optionalString (s.ipv6 != null) "${ip} -6 addr add ${s.ipv6}/128 dev ${selfInterface} nodad\n"
|
||||
) proxyInboundsSelfSources}
|
||||
'';
|
||||
# Only listeners, and for AmneziaWG listeners transparent sockets (IP_TRANSPARENT).
|
||||
runXray = constants.runAsServiceUser pkgs (
|
||||
[ "net_bind_service" ] ++ lib.optional (proxyInboundsAwg != [ ]) "net_admin"
|
||||
@@ -242,6 +259,7 @@ let
|
||||
${writeLinksBlock}
|
||||
${writeSubscriptionsBlock}
|
||||
|
||||
${selfInterfaceUp}
|
||||
exec ${runXray} ${xray} run -c "$RUNTIME_DIR/config.json"
|
||||
'';
|
||||
|
||||
@@ -288,10 +306,16 @@ let
|
||||
chmod ${if userControlAllows "stats" then "640" else "600"} "$tmp"
|
||||
mv -f "$tmp" "$file"
|
||||
'';
|
||||
stopInboundsInterface =
|
||||
if proxyInboundsSelfSources == [ ] then
|
||||
null
|
||||
else
|
||||
pkgs.writeShellScript "proxy-suite-inbounds" selfInterfaceDown;
|
||||
in
|
||||
{
|
||||
inherit
|
||||
startInbounds
|
||||
stopInboundsInterface
|
||||
collectInboundStats
|
||||
linksFile
|
||||
subscriptionsFile
|
||||
|
||||
@@ -168,7 +168,7 @@ let
|
||||
inherit (startScripts) startSocks startTun startPerAppTun;
|
||||
|
||||
proxyInboundsScripts = import ./proxy-inbounds-scripts.nix { ctx = sctx; };
|
||||
inherit (proxyInboundsScripts) startInbounds collectInboundStats;
|
||||
inherit (proxyInboundsScripts) startInbounds stopInboundsInterface collectInboundStats;
|
||||
proxyInboundsLinksFile = proxyInboundsScripts.linksFile;
|
||||
proxyInboundsSubscriptionsFile = proxyInboundsScripts.subscriptionsFile;
|
||||
|
||||
@@ -204,6 +204,7 @@ in
|
||||
startTun
|
||||
startPerAppTun
|
||||
startInbounds
|
||||
stopInboundsInterface
|
||||
collectInboundStats
|
||||
;
|
||||
inherit
|
||||
|
||||
@@ -118,6 +118,8 @@ let
|
||||
++ lib.optional torOnionEnabled "proxy-suite-tor.service";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
execStart = scripts.startInbounds;
|
||||
# inbounds.routing.serverSource's dummy interface.
|
||||
execStopPost = scripts.stopInboundsInterface;
|
||||
runtimeDirectory = serviceNames.inbounds;
|
||||
# The collector's file.
|
||||
stateDirectory = "proxy-suite";
|
||||
|
||||
Reference in new issue
Block a user