From 60e1645226133aedaf5e4267670bf919d6ae50e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?McKayla=20=E3=81=AF=E3=81=AA?= Date: Thu, 27 Aug 2026 21:07:39 -0600 Subject: [PATCH] ssh: apply configuration path to SCP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass the configured SSH configuration path to SCP as well as SSH. Signed-off-by: McKayla はな --- pkg/agent/transport/ssh/transport.go | 15 +++++++++++---- pkg/agent/transport/ssh/transport_test.go | 13 +++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/pkg/agent/transport/ssh/transport.go b/pkg/agent/transport/ssh/transport.go index 4a519c031..48d633bb6 100644 --- a/pkg/agent/transport/ssh/transport.go +++ b/pkg/agent/transport/ssh/transport.go @@ -40,6 +40,15 @@ func init() { } } +// sshConfigArguments computes SSH configuration arguments. +func sshConfigArguments() []string { + if configPath := os.Getenv("MUTAGEN_SSH_CONFIG_PATH"); configPath != "" { + // According to `man ssh`, "none" is also a valid value for `-F`. + return []string{"-F", configPath} + } + return nil +} + // sshTransport implements the agent.Transport interface using SSH. type sshTransport struct { // user is the SSH user under which agents should be invoked. @@ -96,6 +105,7 @@ func (t *sshTransport) Copy(localPath, remoteName string) error { // Set up arguments. var scpArguments []string + scpArguments = append(scpArguments, sshConfigArguments()...) scpArguments = append(scpArguments, ssh.CompressionFlag()) scpArguments = append(scpArguments, ssh.ConnectTimeoutFlag(connectTimeoutSeconds)) scpArguments = append(scpArguments, ssh.ServerAliveFlags(serverAliveIntervalSeconds, serverAliveCountMax)...) @@ -156,10 +166,7 @@ func (t *sshTransport) Command(command string) (*exec.Cmd, error) { // more efficient to compress at that layer, even with the slower Go // implementation. var sshArguments []string - if configPath := os.Getenv("MUTAGEN_SSH_CONFIG_PATH"); configPath != "" { - // According to `man ssh`, "none" is also a valid value for `-F` - sshArguments = append(sshArguments, "-F", configPath) - } + sshArguments = append(sshArguments, sshConfigArguments()...) sshArguments = append(sshArguments, ssh.ConnectTimeoutFlag(connectTimeoutSeconds)) sshArguments = append(sshArguments, ssh.ServerAliveFlags(serverAliveIntervalSeconds, serverAliveCountMax)...) if t.port != 0 { diff --git a/pkg/agent/transport/ssh/transport_test.go b/pkg/agent/transport/ssh/transport_test.go index 3109f8b05..1b085210b 100644 --- a/pkg/agent/transport/ssh/transport_test.go +++ b/pkg/agent/transport/ssh/transport_test.go @@ -105,3 +105,16 @@ func TestCommandOutput(t *testing.T) { t.Error("output not in UTF-8 encoding") } } + +func TestSSHConfigArguments(t *testing.T) { + t.Setenv("MUTAGEN_SSH_CONFIG_PATH", "") + if arguments := sshConfigArguments(); len(arguments) != 0 { + t.Fatal("unexpected SSH configuration arguments:", arguments) + } + + t.Setenv("MUTAGEN_SSH_CONFIG_PATH", "none") + arguments := sshConfigArguments() + if len(arguments) != 2 || arguments[0] != "-F" || arguments[1] != "none" { + t.Fatal("unexpected SSH configuration arguments:", arguments) + } +}