Skip to content

Fix SSH argument handling for timeouts and complex options#625

Open
cafkafk wants to merge 1 commit intonix-community:mainfrom
cafkafk:kexec-ssh-args-bug
Open

Fix SSH argument handling for timeouts and complex options#625
cafkafk wants to merge 1 commit intonix-community:mainfrom
cafkafk:kexec-ssh-args-bug

Conversation

@cafkafk
Copy link
Member

@cafkafk cafkafk commented Mar 7, 2026

This PR fixes two related issues with how SSH arguments are propagated, which were causing failures for deployments using complex SSH options (e.g., ProxyCommand with arguments) or relying on ConnectTimeout.

Issues Fixed

1. Fix NIX_SSHOPTS Quoting
sshArgs was being flattened into NIX_SSHOPTS using "${sshArgs[*]}". This naive expansion destroys the quoting of array elements that contain spaces.

Passing --ssh-option "ProxyCommand='wrapper.sh' %h %p" would result in nix splitting the proxy command string, causing SSH to execute the wrapper without arguments (failed IAP tunnels, etc.).

Fix: Changed to NIX_SSHOPTS="$(printf '%q ' "${sshArgs[@]}")" to properly shell-escape the arguments, preserving the structure of complex flags when passed to nix.

2. Fix ConnectTimeout Injection
Internal calls like runSsh -o ConnectTimeout=10 were broken because runSsh appends positional arguments ($@) after the destination.

ssh root@host -o ConnectTimeout=10 tries to execute -o as a remote command on the server. This returns exit code 127 (command not found) instead of actually setting a connection timeout, breaking logic that relies on exit codes (like the post-kexec wait loop).

Fix: Refactored these calls to append -o ConnectTimeout=10 to the sshArgs array (scoped within subshells where appropriate) so they are correctly passed as SSH flags before the destination.

@cafkafk cafkafk force-pushed the kexec-ssh-args-bug branch from d282120 to ac10e25 Compare March 7, 2026 09:49
@cafkafk
Copy link
Member Author

cafkafk commented Mar 7, 2026

Shellcheck here and here were false positives, so I've silence them.

Update `importFacts`, `generateHardwareConfig`, and other functions
to append the `ConnectTimeout` option to the `sshArgs` array instead
of passing it as a direct argument to `runSsh` and `runSshNoTty`. This
ensures more consistent handling of SSH arguments throughout the script
and leverages subshells where necessary to scope the argument changes.
@cafkafk cafkafk force-pushed the kexec-ssh-args-bug branch from ac10e25 to bbb2cc2 Compare March 7, 2026 09:56
@cafkafk
Copy link
Member Author

cafkafk commented Mar 7, 2026

For context: The failing tests seems to be an issue with CI, not this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant