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

SSH proxy: allow using a bare hostname without root@ #1048

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions lib/kamal/configuration/docs/ssh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ ssh:

# Proxy host
#
# Specified in the form <host> or <user>@<host>:
proxy: root@proxy-host
# Specified in the form <host> or <user>@<host>
proxy: proxy-host

# Proxy command
#
Expand Down
6 changes: 3 additions & 3 deletions lib/kamal/configuration/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def port
end

def proxy
if (proxy = ssh_config["proxy"])
Net::SSH::Proxy::Jump.new(proxy.include?("@") ? proxy : "root@#{proxy}")
elsif (proxy_command = ssh_config["proxy_command"])
if proxy = ssh_config["proxy"]
Net::SSH::Proxy::Jump.new(proxy)
elsif proxy_command = ssh_config["proxy_command"]
Net::SSH::Proxy::Command.new(proxy_command)
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/commands/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class CommandsAppTest < ActiveSupport::TestCase

test "run over ssh with proxy" do
@config[:ssh] = { "proxy" => "2.2.2.2" }
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")
assert_equal "ssh -J 2.2.2.2 -t root@1.1.1.1 -p 22 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1")
end

test "run over ssh with proxy user" do
Expand All @@ -304,7 +304,7 @@ class CommandsAppTest < ActiveSupport::TestCase

test "run over ssh with custom user with proxy" do
@config[:ssh] = { "user" => "app", "proxy" => "2.2.2.2" }
assert_equal "ssh -J root@2.2.2.2 -t app@1.1.1.1 -p 22 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1")
assert_equal "ssh -J 2.2.2.2 -t app@1.1.1.1 -p 22 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1")
end

test "run over ssh with proxy_command" do
Expand Down
2 changes: 1 addition & 1 deletion test/configuration/ssh_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ConfigurationSshTest < ActiveSupport::TestCase

test "ssh options with proxy host" do
config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "1.2.3.4" }) })
assert_equal "root@1.2.3.4", config.ssh.options[:proxy].jump_proxies
assert_equal "1.2.3.4", config.ssh.options[:proxy].jump_proxies
end

test "ssh options with proxy host and user" do
Expand Down