Skip to content

Commit

Permalink
Merge pull request #56326 from uvNikita/openssh/fix-socket
Browse files Browse the repository at this point in the history
sshd: fix startWhenNeeded and listenAddresses combination
  • Loading branch information
lheckemann authored Feb 25, 2019
2 parents 7ca0086 + 131e31c commit dd25140
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nixos/modules/services/networking/ssh/sshd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,10 @@ in
sockets.sshd =
{ description = "SSH Socket";
wantedBy = [ "sockets.target" ];
socketConfig.ListenStream = cfg.ports;
socketConfig.ListenStream = if cfg.listenAddresses != [] then
map (l: "${l.addr}:${toString (if l.port != null then l.port else 22)}") cfg.listenAddresses
else
cfg.ports;
socketConfig.Accept = true;
};

Expand Down
23 changes: 23 additions & 0 deletions nixos/tests/openssh.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ in {
];
};

server_localhost_only =
{ ... }:

{
services.openssh = {
enable = true; listenAddresses = [ { addr = "127.0.0.1"; port = 22; } ];
};
};

server_localhost_only_lazy =
{ ... }:

{
services.openssh = {
enable = true; startWhenNeeded = true; listenAddresses = [ { addr = "127.0.0.1"; port = 22; } ];
};
};

client =
{ ... }: { };

Expand Down Expand Up @@ -77,5 +95,10 @@ in {
" server_lazy true");
};
subtest "localhost-only", sub {
$server_localhost_only->succeed("ss -nlt | grep '127.0.0.1:22'");
$server_localhost_only_lazy->succeed("ss -nlt | grep '127.0.0.1:22'");
}
'';
})

0 comments on commit dd25140

Please sign in to comment.