fix: hardening

This commit is contained in:
FUFSoB committed 2026-10-05 22:44:09 +05:00
1 parent 017a947a18
commit a435942b4f
168 files changed
+9166 -1644

No files matched your search

+23 -3
View File
@@ -10,10 +10,30 @@ let
s = cfg.sshProxy;
inherit (derived.constants) serviceUser unprivilegedServiceConfig;
destination = if s.server.user == null then s.server.host else "${s.server.user}@${s.server.host}";
# ssh reads "::1:1091" as a bad forwarding spec: an IPv6 address goes in brackets.
listenHost =
if lib.hasInfix ":" s.listener.address then "[${s.listener.address}]" else s.listener.address;
extraArgs = lib.concatMapStrings (arg: " args+=(${lib.escapeShellArg arg})\n") s.extraArgs;
# The server's keys: a known-hosts file, the one sing-box reads, or its keys as one.
knownHostsSource =
if s.knownHostsFile != null then
s.knownHostsFile
else if s.hostKeyFile != null then
s.hostKeyFile
else if s.hostKey != [ ] then
pkgs.writeText "proxy-suite-ssh-known-hosts" (
lib.concatMapStrings (
key:
"${
if s.server.port == 22 then s.server.host else "[${s.server.host}]:${toString s.server.port}"
} ${key}\n"
) s.hostKey
)
else
null;
# The service user's home is /var/empty: accepted host keys are kept in the state dir.
knownHosts =
if s.knownHostsFile != null then
if knownHostsSource != null then
''"$CREDENTIALS_DIRECTORY/known_hosts"''
else if s.serviceUser == serviceUser then
''"$STATE_DIRECTORY/known_hosts"''
@@ -30,7 +50,7 @@ let
-o ServerAliveCountMax=3
-o ConnectTimeout=10
-o StrictHostKeyChecking=${lib.escapeShellArg s.strictHostKeyChecking}
-D ${lib.escapeShellArg "${s.listener.address}:${toString s.listener.port}"}
-D ${lib.escapeShellArg "${listenHost}:${toString s.listener.port}"}
)
${lib.optionalString (s.server.port != 22) "args+=(-p ${toString s.server.port})"}
${lib.optionalString (s.identityFile != null) ''args+=(-i "$CREDENTIALS_DIRECTORY/identity")''}
@@ -55,7 +75,7 @@ in
# Copies the service user can read, whoever owns the originals.
LoadCredential =
lib.optional (s.identityFile != null) "identity:${s.identityFile}"
++ lib.optional (s.knownHostsFile != null) "known_hosts:${s.knownHostsFile}";
++ lib.optional (knownHostsSource != null) "known_hosts:${knownHostsSource}";
StateDirectory = "proxy-suite/ssh";
StateDirectoryMode = "0700";
# `ssh -N` exits 0 when the server closes the connection cleanly, which