fix: hardening and fixes
This commit is contained in:
32 files changed
+619
-256
No files matched your search
@@ -70,6 +70,9 @@ let
|
||||
homeService = awgOnly.config.systemd.services.proxy-suite-awg-home;
|
||||
workService = awgOnly.config.systemd.services.proxy-suite-awg-work;
|
||||
ctl = mkProxyCtlDerived awgOnly;
|
||||
homeWatchdog = awgOnly.config.systemd.services.proxy-suite-awg-home-watchdog;
|
||||
homeWatchdogScript = generated.readDerivation homeWatchdog.serviceConfig.ExecStart;
|
||||
homeStart = generated.readDerivation homeService.serviceConfig.ExecStart;
|
||||
|
||||
sourceFixture = evalProxySuite [
|
||||
{
|
||||
@@ -190,6 +193,12 @@ in
|
||||
assert homeService.serviceConfig.NoNewPrivileges;
|
||||
assert builtins.length homeService.serviceConfig.ExecStartPre == 1;
|
||||
assert !(homeService.serviceConfig ? ExecStopPost);
|
||||
# A silent handshake moves the interface to a new port: at start, and from the watchdog.
|
||||
assert pkgs.lib.hasInfix "set \"$interface\" listen-port 0" homeStart;
|
||||
assert pkgs.lib.hasInfix "--inspect" homeStart;
|
||||
assert homeWatchdog.bindsTo == [ "proxy-suite-awg-home.service" ];
|
||||
assert homeWatchdog.wantedBy == [ "proxy-suite-awg-home.service" ];
|
||||
assert pkgs.lib.hasInfix "rekey + 10" homeWatchdogScript;
|
||||
true
|
||||
)
|
||||
(
|
||||
|
||||
@@ -104,7 +104,11 @@ in
|
||||
assert pkgs.lib.hasInfix ''--arg password "$LOCAL_PROXY_PASSWORD"'' localProxyAuthStartScript;
|
||||
assert pkgs.lib.hasInfix ''select(.type == "mixed" and .tag == "mixed-in") | .users''
|
||||
localProxyAuthBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix ''chmod 600 "$RUNTIME_DIR/config.json"'' localProxyAuthStartScript;
|
||||
# The password is in the config: root and the backend's group only.
|
||||
assert pkgs.lib.hasInfix ''chgrp proxy-suite-daemon "$backend_config"'' localProxyAuthStartScript;
|
||||
assert pkgs.lib.hasInfix ''chmod 640 "$backend_config"'' localProxyAuthStartScript;
|
||||
# The backend itself runs unprivileged.
|
||||
assert pkgs.lib.hasInfix "setpriv --reuid=proxy-suite-daemon --regid=proxy-suite-daemon" localProxyAuthStartScript;
|
||||
true
|
||||
)
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ let
|
||||
server = "ssh.example.com";
|
||||
server_port = 22;
|
||||
user = "root";
|
||||
private_key_path = "/run/secrets/ssh-key";
|
||||
host_key = [ testHostKey ];
|
||||
routing_mark = markOf sshNativeSingBox;
|
||||
};
|
||||
@@ -367,6 +366,9 @@ let
|
||||
)
|
||||
(
|
||||
assert pkgs.lib.hasInfix expectedNativeSingBoxOutbound sshNativeSingBoxStart;
|
||||
# The daemon cannot read the key where it lives: it gets a group-readable copy.
|
||||
assert pkgs.lib.hasInfix "install -m 0640 -g proxy-suite-daemon /run/secrets/ssh-key \"$SSH_IDENTITY\"" sshNativeSingBoxStart;
|
||||
assert pkgs.lib.hasInfix "'.private_key_path = $key'" sshNativeSingBoxStart;
|
||||
true
|
||||
)
|
||||
# The global local-resolve route rule is gone; the native outbound resolves.
|
||||
@@ -441,7 +443,16 @@ let
|
||||
true
|
||||
)
|
||||
(
|
||||
assert pkgs.lib.hasInfix "UserKnownHostsFile=/run/secrets/ssh-known-hosts" standaloneStartScript;
|
||||
assert pkgs.lib.hasInfix ''UserKnownHostsFile="$CREDENTIALS_DIRECTORY/known_hosts"'' standaloneStartScript;
|
||||
true
|
||||
)
|
||||
# Secrets reach the unprivileged user as credentials.
|
||||
(
|
||||
assert
|
||||
standaloneService.serviceConfig.LoadCredential == [
|
||||
"identity:/run/secrets/ssh-key"
|
||||
"known_hosts:/run/secrets/ssh-known-hosts"
|
||||
];
|
||||
true
|
||||
)
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ let
|
||||
tgWithGlobalTunServiceConfig
|
||||
tgWithGlobalTunBypassUp
|
||||
tgWithGlobalTunBypassDown
|
||||
tgWithGlobalTunModule
|
||||
tgWithGlobalTunRules
|
||||
tgWithGlobalTproxyNft
|
||||
invalidTgWsProxyAssertions
|
||||
@@ -81,6 +82,10 @@ in
|
||||
# Global TUN/TProxy bypass mark keeps relay traffic out of transparent capture.
|
||||
(
|
||||
assert !(tgWithGlobalTunServiceConfig ? SocketMark);
|
||||
# The relay runs as the service user; only the bypass scripts are privileged.
|
||||
assert tgWithGlobalTunServiceConfig.User == "proxy-suite-daemon";
|
||||
assert tgWithGlobalTunServiceConfig.ExecStartPre == "+${tgWithGlobalTunModule.bypassUpScript}";
|
||||
assert tgWithGlobalTunServiceConfig.ExecStopPost == "+${tgWithGlobalTunModule.bypassDownScript}";
|
||||
assert pkgs.lib.hasInfix "\"system.slice/proxy-suite-tg-ws-proxy.service\" meta mark set 4" tgWithGlobalTunBypassUp;
|
||||
assert pkgs.lib.hasInfix "delete table inet proxy_suite_tg_ws_proxy" tgWithGlobalTunBypassDown;
|
||||
assert pkgs.lib.hasInfix "rule add pref 8999 fwmark 4 lookup main" tgWithGlobalTunBypassUp;
|
||||
|
||||
@@ -66,8 +66,19 @@ let
|
||||
];
|
||||
tgWithGlobalTunServiceConfig =
|
||||
tgWithGlobalTun.config.systemd.services."proxy-suite-tg-ws-proxy".serviceConfig;
|
||||
tgWithGlobalTunBypassUp = generated.readDerivation tgWithGlobalTunServiceConfig.ExecStartPre;
|
||||
tgWithGlobalTunBypassDown = generated.readDerivation tgWithGlobalTunServiceConfig.ExecStopPost;
|
||||
tgWithGlobalTunModule =
|
||||
let
|
||||
inherit (tgWithGlobalTun) pkgs;
|
||||
cfg = tgWithGlobalTun.config.services.proxy-suite;
|
||||
in
|
||||
import ../../../modules/proxy-suite/tg-ws-proxy.nix {
|
||||
inherit (pkgs) lib;
|
||||
inherit pkgs cfg;
|
||||
packages = import ../../../pkgs/default.nix { inherit pkgs; };
|
||||
derived = import ../../../modules/proxy-suite/derived.nix { inherit (pkgs) lib; inherit cfg; };
|
||||
};
|
||||
tgWithGlobalTunBypassUp = generated.readDerivation tgWithGlobalTunModule.bypassUpScript;
|
||||
tgWithGlobalTunBypassDown = generated.readDerivation tgWithGlobalTunModule.bypassDownScript;
|
||||
tgWithGlobalTunRules = mkRoutingRules tgWithGlobalTun;
|
||||
|
||||
tgWithGlobalTproxy = evalProxySuite [
|
||||
@@ -134,6 +145,7 @@ in
|
||||
tgWithGlobalTunServiceConfig
|
||||
tgWithGlobalTunBypassUp
|
||||
tgWithGlobalTunBypassDown
|
||||
tgWithGlobalTunModule
|
||||
tgWithGlobalTunRules
|
||||
tgWithGlobalTproxyNft
|
||||
invalidTgWsProxyAssertions
|
||||
|
||||
@@ -109,6 +109,18 @@ let
|
||||
asAmneziaWg = true;
|
||||
};
|
||||
}
|
||||
# Both modes at once: two sessions on one WARP key.
|
||||
{
|
||||
enable = true;
|
||||
amneziaWg.enable = true;
|
||||
warp = {
|
||||
enable = true;
|
||||
configFile = profile;
|
||||
asOutbound = true;
|
||||
asAmneziaWg = true;
|
||||
};
|
||||
proxy.enable = true;
|
||||
}
|
||||
# Tag collision with a declared outbound.
|
||||
{
|
||||
enable = true;
|
||||
@@ -203,6 +215,23 @@ in
|
||||
&& !(hasInfix "generate()" autoRegister);
|
||||
true
|
||||
)
|
||||
# Registration runs as the service user; the generator is tried through the proxy last.
|
||||
(
|
||||
assert
|
||||
auto.config.systemd.services."proxy-suite-warp".serviceConfig.User == "proxy-suite-daemon"
|
||||
&& hasInfix "register || register || generate || proxied generate" generatorRegister;
|
||||
true
|
||||
)
|
||||
# sing-box runs as the service user with only net_admin, under a watchdog that can tell a
|
||||
# dead uplink (the marked direct-in listener) from a silent WARP.
|
||||
(
|
||||
assert
|
||||
hasInfix "--reuid=proxy-suite-daemon" singBoxTunnel
|
||||
&& hasInfix "--ambient-caps=-all,+net_admin --bounding-set" singBoxTunnel
|
||||
&& hasInfix ''{type: "socks", tag: "direct-in", listen: "127.0.0.1", listen_port: 18539}'' singBoxTunnel
|
||||
&& hasInfix ''{type: "direct", tag: "direct", routing_mark: ${markOf singBox}}'' singBoxTunnel;
|
||||
true
|
||||
)
|
||||
(
|
||||
assert amneziaWg.config.services.proxy-suite.amneziaWg.profiles.warp.configFile == profile;
|
||||
true
|
||||
|
||||
Reference in new issue
Block a user