fix: hardening
This commit is contained in:
168 files changed
+9166
-1644
No files matched your search
@@ -27,14 +27,19 @@ rec {
|
||||
};
|
||||
|
||||
# One system user per daemon, each in a group of its own, plus the userControl group.
|
||||
systemUsersAndGroups = cfg: {
|
||||
users.users = lib.genAttrs cfg.internal.systemUsers (name: {
|
||||
isSystemUser = true;
|
||||
group = name;
|
||||
description = "proxy-suite daemons";
|
||||
});
|
||||
users.groups = lib.genAttrs (cfg.internal.systemUsers ++ cfg.internal.groups) (_: { });
|
||||
};
|
||||
systemUsersAndGroups =
|
||||
cfg:
|
||||
let
|
||||
users = lib.unique cfg.internal.systemUsers;
|
||||
in
|
||||
{
|
||||
users.users = lib.genAttrs users (name: {
|
||||
isSystemUser = true;
|
||||
group = name;
|
||||
description = "proxy-suite daemons";
|
||||
});
|
||||
users.groups = lib.genAttrs (users ++ cfg.internal.groups) (_: { });
|
||||
};
|
||||
|
||||
firewallPortForward = internal: {
|
||||
networking.firewall = {
|
||||
@@ -52,11 +57,12 @@ rec {
|
||||
host,
|
||||
internal,
|
||||
hostPath ? null,
|
||||
withSystemd ? true,
|
||||
}:
|
||||
let
|
||||
units = import ./user-units.nix (
|
||||
{
|
||||
inherit lib pkgs;
|
||||
inherit lib pkgs withSystemd;
|
||||
inherit (host) runtimeDir;
|
||||
stateDir = builtins.dirOf host.stateDir;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ let
|
||||
internal
|
||||
;
|
||||
hostPath = "${home}/.nix-profile/bin";
|
||||
withSystemd = false;
|
||||
};
|
||||
|
||||
supervisorDir = "${host.runtimeDir}/proxy-suite-supervisor";
|
||||
@@ -76,6 +77,11 @@ in
|
||||
firewallPackage = null;
|
||||
resolvconfPackage = null;
|
||||
};
|
||||
# A phone's storage is tight: proxy-ctl falls back to less and plain curl.
|
||||
services.proxy-suite.tools = {
|
||||
lnav.enable = lib.mkDefault false;
|
||||
curlImpersonate.enable = lib.mkDefault false;
|
||||
};
|
||||
# An app may not join netlink's route groups: without this sing-box fails to start.
|
||||
services.proxy-suite.proxy.singBox.package = lib.mkDefault (
|
||||
import ../../../pkgs/sing-box-rootless-netlink.nix { inherit (proxySuiteUpstream) sing-box; }
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
@@ -42,6 +43,11 @@ in
|
||||
) ([ firewall ] ++ lib.attrValues firewall.interfaces)
|
||||
);
|
||||
resolvconfPackage = config.networking.resolvconf.package;
|
||||
# ntpd-rs runs as a dynamic user, which has no name until it starts.
|
||||
timeSyncUsers =
|
||||
lib.optional config.services.timesyncd.enable "systemd-timesync"
|
||||
++ lib.optional config.services.chrony.enable "chrony"
|
||||
++ lib.optional (config.services.ntp.enable || config.services.openntpd.enable) "ntp";
|
||||
};
|
||||
# NixOS's place for helper functions; set even while disabled, so a config can
|
||||
# refer to it unconditionally.
|
||||
@@ -57,8 +63,40 @@ in
|
||||
|
||||
security.polkit.enable = lib.mkIf cfg.internal.polkit.enable true;
|
||||
security.polkit.extraConfig = forwardWith lib.mkAfter internal.polkit.rules;
|
||||
# polkitd reads actions from the system profile's share/polkit-1/actions.
|
||||
environment.systemPackages = lib.mkIf (cfg.internal.polkit.actions != { }) [
|
||||
(pkgs.linkFarm "proxy-suite-polkit-actions" (
|
||||
lib.mapAttrsToList (name: path: {
|
||||
name = "share/polkit-1/actions/${name}";
|
||||
inherit path;
|
||||
}) cfg.internal.polkit.actions
|
||||
))
|
||||
];
|
||||
|
||||
networking.nftables.enable = lib.mkIf cfg.internal.nftables (lib.mkDefault true);
|
||||
# proxy-suite's tables that are up, put back in the firewall's own load, whose flush would
|
||||
# otherwise drop them (constants.persistedNftDir). An empty glob is no error.
|
||||
networking.nftables.ruleset = lib.mkIf config.networking.nftables.enable (
|
||||
lib.mkAfter ''
|
||||
include "${cfg.host.runtimeDir}/proxy-suite-nft/*.nft"
|
||||
''
|
||||
);
|
||||
# A persisted table that no longer loads (a user it names is gone, its store path
|
||||
# collected) would fail the whole load: dropped until its unit writes it again.
|
||||
systemd.services.nftables.serviceConfig = lib.mkIf config.networking.nftables.enable (
|
||||
let
|
||||
prune = pkgs.writeShellScript "proxy-suite-nft-prune" ''
|
||||
for f in ${cfg.host.runtimeDir}/proxy-suite-nft/*.nft; do
|
||||
[ -e "$f" ] || continue
|
||||
${pkgs.nftables}/bin/nft -c -f "$f" > /dev/null 2>&1 || ${pkgs.coreutils}/bin/rm -f -- "$f"
|
||||
done
|
||||
'';
|
||||
in
|
||||
{
|
||||
ExecStart = lib.mkBefore [ prune ];
|
||||
ExecReload = lib.mkBefore [ prune ];
|
||||
}
|
||||
);
|
||||
networking.nftables.tables = lib.mapAttrs (_: content: {
|
||||
family = "inet";
|
||||
inherit content;
|
||||
@@ -73,6 +111,13 @@ in
|
||||
trustedInterfaces = forward internal.firewall.trustedInterfaces;
|
||||
};
|
||||
|
||||
# networkd drops foreign ip rules and unreachable routes (TProxy's and AmneziaWG's IPv6
|
||||
# refusal) in every table whenever it reconfigures a link.
|
||||
systemd.network.config.networkConfig = lib.mkIf config.systemd.network.enable {
|
||||
ManageForeignRoutingPolicyRules = lib.mkDefault false;
|
||||
ManageForeignRoutes = lib.mkDefault false;
|
||||
};
|
||||
|
||||
boot.extraModulePackages = forward internal.kernelModulePackages;
|
||||
boot.kernel.sysctl = lib.mapAttrs (_: lib.mkDefault) cfg.internal.sysctl;
|
||||
|
||||
@@ -88,6 +133,20 @@ in
|
||||
|| config.networking.nftables.enable;
|
||||
message = "proxy-suite: proxy.tproxy.lanInterfaces needs the nftables firewall (networking.nftables.enable); the iptables one drops the gateway clients' diverted traffic";
|
||||
}
|
||||
# The kill switch lets that user's traffic past, all of it: a login user's browser
|
||||
# and apps too, whenever no tunnel is up.
|
||||
(
|
||||
let
|
||||
user = cfg.sshProxy.serviceUser;
|
||||
declared = config.users.users.${user} or null;
|
||||
in
|
||||
{
|
||||
assertion =
|
||||
!(cfg.sshProxy.enable && user != null && user != "proxy-suite-daemon" && declared != null)
|
||||
|| !declared.isNormalUser;
|
||||
message = "proxy-suite: sshProxy.serviceUser = \"${toString user}\" is a login user, whose traffic would all get past the kill switch; use a system user of its own (isSystemUser = true), or the default";
|
||||
}
|
||||
)
|
||||
];
|
||||
}
|
||||
]
|
||||
|
||||
@@ -97,6 +97,11 @@ in
|
||||
(lib.mkIf cfg.internal.polkit.enable {
|
||||
"polkit-1/rules.d/50-proxy-suite.rules".text = cfg.internal.polkit.rules;
|
||||
})
|
||||
# Read from /etc by polkit 126 and later. An older one never finds the action, and
|
||||
# its pkexec asks for the password every time instead.
|
||||
(lib.mapAttrs' (
|
||||
name: path: lib.nameValuePair "polkit-1/actions/${name}" { source = path; }
|
||||
) cfg.internal.polkit.actions)
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
runtimeDir,
|
||||
stateDir,
|
||||
hostPath ? null,
|
||||
# Off under proxy-suitectl: the scripts call it by path, and nothing needs systemd's tools.
|
||||
withSystemd ? true,
|
||||
}:
|
||||
|
||||
let
|
||||
@@ -71,13 +73,15 @@ let
|
||||
iniSection = section: lib.mapAttrs (_: iniValue) (lib.filterAttrs (_: v: v != null) section);
|
||||
|
||||
# As NixOS's service `path` default.
|
||||
defaultPath = with pkgs; [
|
||||
coreutils
|
||||
findutils
|
||||
gnugrep
|
||||
gnused
|
||||
systemd
|
||||
];
|
||||
defaultPath =
|
||||
with pkgs;
|
||||
[
|
||||
coreutils
|
||||
findutils
|
||||
gnugrep
|
||||
gnused
|
||||
]
|
||||
++ lib.optional withSystemd systemd;
|
||||
|
||||
# As NixOS: "@" is not allowed in a store path name.
|
||||
jobScript =
|
||||
|
||||
Reference in new issue
Block a user