Skip to content

Commit

Permalink
Actually pass ssh/config through to SSHKit options
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Burgestrand committed Oct 28, 2024
1 parent 2465681 commit e8a41af
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/kamal/commands/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(config)
end

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

def container_id_for(container_name:, only_running: false)
Expand Down Expand Up @@ -94,5 +94,14 @@ def ssh_proxy_args
" -o ProxyCommand='#{config.ssh.proxy.command_line_template}'"
end
end

def ssh_config_args
case config.ssh.config
when true, nil
""
when false
" -F none"
end
end
end
end
6 changes: 5 additions & 1 deletion lib/kamal/configuration/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ def key_data
ssh_config["key_data"]
end

def config
ssh_config["config"]
end

def options
{ user: user, port: port, proxy: proxy, logger: logger, keepalive: true, keepalive_interval: 30, keys_only: keys_only, keys: keys, key_data: key_data }.compact
{ 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
end

def to_h
Expand Down
5 changes: 5 additions & 0 deletions test/commands/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ class CommandsAppTest < ActiveSupport::TestCase
assert_equal "ssh -t [email protected] -p 2222 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1")
end

test "run over ssh with no config" do
@config[:ssh] = { "config" => false }
assert_equal "ssh -F none -t [email protected] -p 22 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1")
end

test "run over ssh with proxy" do
@config[:ssh] = { "proxy" => "2.2.2.2" }
assert_equal "ssh -J [email protected] -t [email protected] -p 22 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1")
Expand Down
5 changes: 5 additions & 0 deletions test/configuration/ssh_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ class ConfigurationSshTest < ActiveSupport::TestCase
config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "[email protected]" }) })
assert_equal "[email protected]", config.ssh.options[:proxy].jump_proxies
end

test "ssh options with disabled ssh_config" do
config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "config" => false }) })
assert_equal false, config.ssh.options[:config]
end
end

0 comments on commit e8a41af

Please sign in to comment.