Skip to content

Commit e8a41af

Browse files
committed
Actually pass ssh/config through to SSHKit options
This option is documented as available since basecamp#908 in: https://github.com/basecamp/kamal/blob/74a06b0ccda616c86ebe1729d0795f39bcac9f00/lib/kamal/configuration/docs/ssh.yml#L65-L70 However, before this the options don't seem to pass through to SSHKit: https://github.com/basecamp/kamal/blob/74a06b0ccda616c86ebe1729d0795f39bcac9f00/lib/kamal/commander.rb#L167 Since `config` isn't actually returned in `#options`.
1 parent 2465681 commit e8a41af

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

lib/kamal/commands/base.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def initialize(config)
1111
end
1212

1313
def run_over_ssh(*command, host:)
14-
"ssh#{ssh_proxy_args} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'"
14+
"ssh#{ssh_proxy_args}#{ssh_config_args} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'"
1515
end
1616

1717
def container_id_for(container_name:, only_running: false)
@@ -94,5 +94,14 @@ def ssh_proxy_args
9494
" -o ProxyCommand='#{config.ssh.proxy.command_line_template}'"
9595
end
9696
end
97+
98+
def ssh_config_args
99+
case config.ssh.config
100+
when true, nil
101+
""
102+
when false
103+
" -F none"
104+
end
105+
end
97106
end
98107
end

lib/kamal/configuration/ssh.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ def key_data
3838
ssh_config["key_data"]
3939
end
4040

41+
def config
42+
ssh_config["config"]
43+
end
44+
4145
def options
42-
{ user: user, port: port, proxy: proxy, logger: logger, keepalive: true, keepalive_interval: 30, keys_only: keys_only, keys: keys, key_data: key_data }.compact
46+
{ user: user, port: port, proxy: proxy, logger: logger, keepalive: true, keepalive_interval: 30, keys_only: keys_only, keys: keys, key_data: key_data, config: config }.compact
4347
end
4448

4549
def to_h

test/commands/app_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ class CommandsAppTest < ActiveSupport::TestCase
300300
assert_equal "ssh -t root@1.1.1.1 -p 2222 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1")
301301
end
302302

303+
test "run over ssh with no config" do
304+
@config[:ssh] = { "config" => false }
305+
assert_equal "ssh -F none -t root@1.1.1.1 -p 22 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1")
306+
end
307+
303308
test "run over ssh with proxy" do
304309
@config[:ssh] = { "proxy" => "2.2.2.2" }
305310
assert_equal "ssh -J root@2.2.2.2 -t root@1.1.1.1 -p 22 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1")

test/configuration/ssh_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ class ConfigurationSshTest < ActiveSupport::TestCase
3737
config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "app@1.2.3.4" }) })
3838
assert_equal "app@1.2.3.4", config.ssh.options[:proxy].jump_proxies
3939
end
40+
41+
test "ssh options with disabled ssh_config" do
42+
config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "config" => false }) })
43+
assert_equal false, config.ssh.options[:config]
44+
end
4045
end

0 commit comments

Comments
 (0)