Skip to content

Commit

Permalink
ssh-ng: Set log-fd for ssh to 4 by default
Browse files Browse the repository at this point in the history
That's expected by `build-remote` and makes sure that errors are
correctly forwarded to the user.

For instance, let's say that the host-key of `example.org` is unknown
and

    nix-build ../nixpkgs -A hello -j0 --builders 'ssh-ng://example.org'

is issued, then you get the following, somewhat cryptic error:

    error: cannot open connection to remote store 'ssh-ng://example.org': error: unexpected end-of-file

The relevant information (`Host key verification failed`) ends up in the
daemon's log, but that's not very obvious considering that the daemon
isn't very chatty normally.

This can be fixed - the same way as its done for legacy-ssh - by passing
fd 4 to the SSH wrapper. Now you'd get the following error:

    error: cannot open connection to remote store 'ssh-ng://example.org': error: unexpected end-of-file: Host key verification failed.

...and now it's clear what's wrong.
  • Loading branch information
Ma27 committed Jan 22, 2023
1 parent 04de0dd commit aa82ade
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/libstore/machines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ ref<Store> Machine::openStore() const
Store::Params storeParams;
if (hasPrefix(storeUri, "ssh://")) {
storeParams["max-connections"] = "1";
storeParams["log-fd"] = "4";
}

if (hasPrefix(storeUri, "ssh://") || hasPrefix(storeUri, "ssh-ng://")) {
storeParams["log-fd"] = "4";
if (sshKey != "")
storeParams["ssh-key"] = sshKey;
if (sshPublicHostKey != "")
Expand Down
5 changes: 4 additions & 1 deletion src/libstore/ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class SSHStore : public virtual SSHStoreConfig, public virtual RemoteStore
{
public:

const Setting<int> logFD{(StoreConfig*) this, -1, "log-fd", "file descriptor to which SSH's stderr is connected"};

SSHStore(const std::string & scheme, const std::string & host, const Params & params)
: StoreConfig(params)
, RemoteStoreConfig(params)
Expand All @@ -38,7 +40,8 @@ class SSHStore : public virtual SSHStoreConfig, public virtual RemoteStore
sshPublicHostKey,
// Use SSH master only if using more than 1 connection.
connections->capacity() > 1,
compress)
compress,
logFD)
{
}

Expand Down

0 comments on commit aa82ade

Please sign in to comment.