Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run_over_ssh does not respect the ssh keys in deploy.yml #1269

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 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}#{identity_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,13 @@ def ssh_proxy_args
" -o ProxyCommand='#{config.ssh.proxy.command_line_template}'"
end
end

def identity_args
if config.ssh.keys
config.ssh.keys.map { |key| " -i #{key}" }.join
else
""
end
end
end
end
5 changes: 5 additions & 0 deletions test/commands/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ class CommandsAppTest < ActiveSupport::TestCase
assert_equal "ssh -t [email protected] -p 22 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1")
end

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

test "run over ssh with custom user" do
@config[:ssh] = { "user" => "app" }
assert_equal "ssh -t [email protected] -p 22 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1")
Expand Down